import logger from '../util/logger' ; import BaseCall from './BaseCall' ; import { IVertoCallOptions } from './interfaces' ; import { getDisplayMedia , setMediaElementSinkId } from '../util/webrtc' ; examples category export class Call extends BaseCall { public screenShare : Call ; private _statsInterval : any = null ; hangup ( params = { } , execute = true ) { if ( this . screenShare instanceof Call ) { this . screenShare . hangup ( params , execute ) ; } super . hangup ( params , execute ) ; } async startScreenShare ( opts ? ) { const displayStream = await getDisplayMedia ( { video : true } ) ; displayStream . getTracks ( ) . forEach ( ( t ) => { t . addEventListener ( 'ended' , ( ) => { if ( this . screenShare ) { this . screenShare . hangup ( ) ; } } ) ; } ) ; const { remoteCallerName , remoteCallerNumber , callerName , callerNumber , } = this . options ; const options = { screenShare : true , localStream : displayStream , destinationNumber : `${ this . extension }-screen` , remoteCallerName , remoteCallerNumber : `${ remoteCallerNumber }-screen` , callerName : `${ callerName } (Screen)` , callerNumber : `${ callerNumber } (Screen)` , ... opts , } ; this . screenShare = new Call ( this . session , options ) ; this . screenShare . invite ( ) ; return this . screenShare ; } stopScreenShare ( ) { if ( this . screenShare instanceof Call ) { this . screenShare . hangup ( ) ; } } examples param deviceId returns async setAudioOutDevice ( deviceId ) { this . options . speakerId = deviceId ; const { remoteElement , speakerId } = this . options ; if ( remoteElement && speakerId ) { return setMediaElementSinkId ( remoteElement , speakerId ) ; } return false ; } protected _finalize ( ) { this . _stats ( false ) ; super . _finalize ( ) ; } private _stats ( what = true ) { if ( what === false ) { return clearInterval ( this . _statsInterval ) ; } logger . setLevel ( 2 ) ; this . _statsInterval = window . setInterval ( async ( ) => { const stats = await this . peer . instance . getStats ( null ) ; let statsOutput = '' ; const invalidReport = [ 'certificate' , 'codec' , 'peer-connection' , 'stream' , 'local-candidate' , 'remote-candidate' , ] ; const invalidStat = [ 'id' , 'type' , 'timestamp' ] ; stats . forEach ( ( report ) => { if ( invalidReport . includes ( report . type ) ) { return ; } statsOutput += `\n${ report . type }\n` ; Object . keys ( report ) . forEach ( ( statName ) => { if ( ! invalidStat . includes ( statName ) ) { statsOutput += `\t${ statName }: ${ report [ statName ] }\n` ; } } ) ; } ) ; logger . info ( statsOutput ) ; } , 2000 ) ; } } export default Call ;