onsip / SIP.js

A simple, intuitive, and powerful JavaScript signaling library
https://sipjs.com
MIT License
1.88k stars 700 forks source link

session.onrefer #997

Closed ilygin closed 2 years ago

ilygin commented 2 years ago

These are typically directed to the google group. Hi. I have the following issue: 3 agents: Alice, Bob, Carol

Alice call to Bob. Bob do attended transfer on Carol.

I init session between Alice and Bob. Hold this session Init session berween Bob and Carol first sesstion refer(second session)

I'd like to get info, when Carol stop talking with Bob and start session with Alice

`scope.userAgent.delegate = { onConnect: () => { console.log(scope.isConnected()) scope.events.onConnect.trigger(); },

            onInvite: (invitation) => {
                console.log(`Received INVITE`);
                //Chcek that invitation is not existed
                if(scope.sessions.has(invitation.id)) {
                    console.warn(`[${this.id}] Session already in progress, rejecting INVITE...`);
                    invitation
                        .reject()
                        .then(() => {
                        console.log(`[${this.id}] Rejected INVITE`);
                    })
                        .catch((error) => {
                        console.error(`[${this.id}] Failed to reject INVITE`);
                        console.error(error.toString());
                    });
                    return;
                }
                if (invitation.request.getHeader("XConsultCall")) {
                    console.log("XConsultCall header:");
                    console.log(params.request.getHeader("XConsultCall"));
                    invitation.direction = params.request.getHeader("XDirection");
                } else {
                    invitation.direction = telephonyCore.callDirection.Inbound;
                }

                scope.initSession(invitation);

            },
        };`

answer(callId) { var scope = this; var session = scope.sessions[callId]; scope.sessions[callId].accept(); }

    `        attendedTransfer(callId, number) {
        var scope = this;
        var session = scope.sessions[callId];
        if (!session) {
            return;
        }
        var inviteOptions = {};
        var consultCallId =  scope.generateGuid();

        inviteOptions.requestDelegate = {
            onAccept: (response) => {
                console.log("Positive response = " + response);
                var telephonyCall = new TelephonyCall(scope.sessions[consultCallId]);
                scope.events.onBridgeCall.trigger(telephonyCall.toObject());     
            },
            onReject: (response) => {
                if(response.message.statusCode>=400 &&response.message.statusCode<700 ) {
                    if(!(response.message.statusCode==487&&e.method.toUpperCase() == 'INVITE')){
                        scope.audioSettings.busyRingtone.play();

                    }
                }
                console.log("Negative response = " + response);
            }
        },
        inviteOptions.sessionDescriptionHandlerOptions =
        {
            constraints:{
                audio: true,
                video: false
            }
        }
        try {
            const target = SIP.UserAgent.makeURI("sip:"+number+"@" + scope.config.domain);           
            const consultCallSession = new SIP.Inviter(scope.userAgent, target, {});
            consultCallSession.invite(inviteOptions);
            consultCallSession.direction = telephonyCore.callDirection.Outbound;
            scope.initSession(consultCallSession, consultCallId);

        } catch (e) {
            throw (e);
        }
    };
    bridgeTransfer(callId, consultCallId) {
        var scope = this;

        var callSession = scope.sessions[callId];
        if (!callSession) {
            return;
        }

        var consultSession = scope.sessions[consultCallId];
        if (!consultSession) {
            return;
        }
         consultSession.refer(callSession);
    };`
john-e-riordan commented 2 years ago

This is not the forum for support - please try google group. Thanks.