import AudioVideoControllerState from '../audiovideocontroller/AudioVideoControllerState' ; import DefaultBrowserBehavior from '../browserbehavior/DefaultBrowserBehavior' ; import DefaultSDP from '../sdp/DefaultSDP' ; import BaseTask from './BaseTask' ; export default class SetLocalDescriptionTask extends BaseTask { protected taskName = 'SetLocalDescriptionTask' ; private cancelPromise : undefined | ( ( error : Error ) => void ) ; constructor ( private context ) { super ( context . logger ) ; } cancel ( ) { if ( this . cancelPromise ) { const error = new Error ( `canceling ${ this . name ( ) }` ) ; this . cancelPromise ( error ) ; delete this . cancelPromise ; } } async run ( ) { const peer = this . context . peer ; const sdpOfferInit = this . context . sdpOfferInit ; let sdp = sdpOfferInit . sdp ; if ( new DefaultBrowserBehavior ( ) . requiresDisablingH264Encoding ( ) ) { sdp = new DefaultSDP ( sdp ) . removeH264SupportFromSendSection ( ) . sdp ; } if ( this . context . audioProfile ) { sdp = new DefaultSDP ( sdp ) . withAudioMaxAverageBitrate ( this . context . audioProfile . audioBitrateBps ) . sdp ; if ( this . context . audioProfile . isStereo ( ) ) { sdp = new DefaultSDP ( sdp ) . withStereoAudio ( ) . sdp ; } } this . logger . debug ( ( ) => { return `local description is >>>${ sdp }<<<` ; } ) ; const sdpOffer = { type : 'offer' , sdp : sdp , toJSON : null , } ; await new Promise < void > ( async ( resolve , reject ) => { this . cancelPromise = ( error ) => { reject ( error ) ; } ; try { await peer . setLocalDescription ( sdpOffer ) ; resolve ( ) ; } catch ( error ) { reject ( error ) ; } finally { delete this . cancelPromise ; } } ) ; this . context . logger . info ( 'set local description' ) ; } }