src/js/bg/plugins/calls/call/sip.js
/**
    * Handle an incoming `invite` call from.
    */
Handle an incoming `invite` call from.
Handle an incoming ` invite ` call from .
_incoming() {
        this.state.displayName = this.session.remoteIdentity.displayName
        let rpid = this.session.transaction.request.getHeader('Remote-Party-Id')
        if (rpid) {
            rpid = this._parseRpid(rpid)
            Object.assign(this.state, rpid)
        } else {
            this.state.number = this.session.remoteIdentity.uri.user
        }
        this.state.stats.callId = this.session.request.call_id
        this.app.logger.debug(`${this}incoming call ${this.state.stats.callId} started`)
        super._incoming()
        this.session.on('accepted', (request) => {
            this.app.telemetry.event('call[sip]', 'incoming', 'accepted')
            this._start({message: this.translations.accepted.incoming})
        })
        this.session.on('bye', (e) => {
            this.busyTone.play()
            if (e.getHeader('X-Asterisk-Hangupcausecode') === '58') {
                this.app.notify({
                    icon: 'warning',
                    message: this.app.$t('your VoIP account misses AVPF and encryption support.'),
                    type: 'warning',
                })
            }
            this.setState({status: 'bye'})
            this._stop({message: this.translations[this.state.status]})
        })
        this.session.on('failed', (response, cause) => {
            this.app.logger.info(`${this}incoming call failed caused by: ${cause}`)
            if (response) {
                if (typeof response === 'string') response = SIP.Parser.parseMessage(response, this.module.ua)
                let reason = response.getHeader('Reason')
                if (reason) reason = this._parseHeader(reason).get('text')
                if (reason === 'Call completed elsewhere') {
                    this.app.logger.info(`${this}call completed elsewhere: ${this.state.stats.callId}`)
                    this.app.telemetry.event('call[sip]', 'incoming', 'answered_elsewhere')
                    this.setState({status: 'answered_elsewhere'})
                } else {
                    this.setState({status: 'request_terminated'})
                    this.app.emit('bg:calls:call_rejected', {call: this.state}, true)
                    this.app.telemetry.event('call[sip]', 'incoming', 'rejected')
                }
            } else {
                this.setState({status: 'request_terminated'})
            }
            this._stop({message: this.translations[this.state.status]})
        })
        this.session.on('reinvite', (session, request) => {
            let _rpid = request.getHeader('Remote-Party-Id')
            if (_rpid) {
                _rpid = this._parseRpid(_rpid)
                this.setState(_rpid)
            }
        })
    }
_incoming ( ) { this . state . displayName = this . session . remoteIdentity . displayName let rpid = this . session . transaction . request . getHeader ( 'Remote-Party-Id' ) if ( rpid ) { rpid = this . _parseRpid ( rpid ) Object . assign ( this . state , rpid ) } else { this . state . number = this . session . remoteIdentity . uri . user } this . state . stats . callId = this . session . request . call_id this . app . logger . debug ( ` ${ this } ${ this . state . stats . callId } ` ) super . _incoming ( ) this . session . on ( 'accepted' , ( request ) => { this . app . telemetry . event ( 'call[sip]' , 'incoming' , 'accepted' ) this . _start ( { message : this . translations . accepted . incoming } ) } ) this . session . on ( 'bye' , ( e ) => { this . busyTone . play ( ) if ( e . getHeader ( 'X-Asterisk-Hangupcausecode' ) === '58' ) { this . app . notify ( { icon : 'warning' , message : this . app . $t ( 'your VoIP account misses AVPF and encryption support.' ) , type : 'warning' , } ) } this . setState ( { status : 'bye' } ) this . _stop ( { message : this . translations [ this . state . status ] } ) } ) this . session . on ( 'failed' , ( response , cause ) => { this . app . logger . info ( ` ${ this } ${ cause } ` ) if ( response ) { if ( typeof response === 'string' ) response = SIP . Parser . parseMessage ( response , this . module . ua ) let reason = response . getHeader ( 'Reason' ) if ( reason ) reason = this . _parseHeader ( reason ) . get ( 'text' ) if ( reason === 'Call completed elsewhere' ) { this . app . logger . info ( ` ${ this } ${ this . state . stats . callId } ` ) this . app . telemetry . event ( 'call[sip]' , 'incoming' , 'answered_elsewhere' ) this . setState ( { status : 'answered_elsewhere' } ) } else { this . setState ( { status : 'request_terminated' } ) this . app . emit ( 'bg:calls:call_rejected' , { call : this . state } , true ) this . app . telemetry . event ( 'call[sip]' , 'incoming' , 'rejected' ) } } else { this . setState ( { status : 'request_terminated' } ) } this . _stop ( { message : this . translations [ this . state . status ] } ) } ) this . session . on ( 'reinvite' , ( session , request ) => { let _rpid = request . getHeader ( 'Remote-Party-Id' ) if ( _rpid ) { _rpid = this . _parseRpid ( _rpid ) this . setState ( _rpid ) } } ) }
Handle an incoming `invite` call from.
Handle an incoming ` invite ` call from .
// (!) Set the state before calling super. // Try to get the caller info first from the RPID. // Setup some event handlers for the different stages of a call. /**
        * The `failed` event is triggered when a call is being rejected,
        * but also when an incoming calls keeps ringing for a certain amount
        * of time (60 seconds), and fails due to a timeout. In that case,
        * no `rejected` event is triggered and we need to kill the
        * call ASAP, so a new INVITE for the same call will be accepted by the
        * call module's invite handler.
        * See: https://sipjs.com/api/0.11.0/session/#failed
        * And: https://sipjs.com/api/0.11.0/causes/
        */ // `Call completed elsewhere` is not considered to be // a missed call and will not end up in the activity log. // Check for the RPID. Update the display name and number to the // transferred caller, if there is one.