The trouble is that I cannot find a place to register a callback for the SUBSCRIBE where I have access to the Call-ID.
If I do this:
var subscription = this.ua.subscribe(contact, event, options);
saveCallID(subscription.dialog.id.call_id);
...then the browser complains, rightly so, that subscription.dialog is null, since it is apparently created asynchronously.
However, if I do this:
var subscription = this.ua.subscribe(contact, event, options);
subscription.on('accepted', function(response, cause) {
console.log("RECEIVED accepted for SUBSCRIBE");
console.log(response);
})
subscription.on('notify', notifyCallback);
...the callback for the accepted event is never called, even though the callback for the notify event gets called later. I expected that since SIP.Subscription mixes the behavior for SIP.ClientContext, then it should fire all of the events defined for SIP.ClientContext, including the accepted event.
So, how can I get the Call-ID value for the SUBSCRIBE as soon as possible?
Contact: <sip:kftfdvdg@1o8mtor6hl25.invalid;transport=ws>
Apparently UA.stop() is NOT synchronous. As evidence, I present the following trace. This trace was obtained after installing a beforeunload handler like this: $(window).on('beforeunload', function () { ua.stop(); });
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.ua | user requested closure..." sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.ua | closing registerContext" sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.ua | emitting event newTransaction" sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.transaction.nict | adding event stateChanged" sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.transaction.nict | emitting event stateChanged" sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.transport | sending WebSocket message:
REGISTER sip:pbx.villacis.com SIP/2.0
Via: SIP/2.0/WSS 3u2gggnosgp0.invalid;branch=z9hG4bK1212055
Max-Forwards: 70
To: <sip:avil...@pbx.villacis.com>
From: "Alex Villacís" <sip:avil...@pbx.villacis.com>;tag=7jtj4snakb
Call-ID: 9qvgdl2frckdgco4kiampf
CSeq: 83 REGISTER
Authorization: Digest algorithm=MD5, username="avillacis", realm="pbx.villacis.com", nonce="U+zjC1Ps4d+r4O/PBviZyc32z5Y6r0LF", uri="sip:pbx.villacis.com", response="ea5edbb9f4d090fadba00557dcd3ac53"
Contact: <sip:77g5cfiv@3u2gggnosgp0.invalid;transport=ws>;reg-id=1;+sip.instance="<urn:uuid:1fb7dd94-481a-45b3-ace2-55aeb938651f>";expires=0
Supported: path,gruu,outbound
User-Agent: SIP.js/0.6.2
Content-Length: 0
" sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.ua | unsubscribing from subscription 4ik6f0e97mk4tis2rp2c4u2mjdhu24a6a1c5f60faecf035a1ae5b6e96e979a-e17f" sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.ua | emitting event newTransaction" sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.transaction.nict | adding event stateChanged" sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.transaction.nict | emitting event stateChanged" sip-0.6.2.js:2655
"Thu Aug 14 2014 11:21:13 GMT-0500 (ECT) | sip.transport | sending WebSocket message:
SUBSCRIBE sip:avil...@pbx.villacis.com SIP/2.0
Via: SIP/2.0/WSS 3u2gggnosgp0.invalid;branch=z9hG4bK9026714
Max-Forwards: 70
To: <sip:avil...@pbx.villacis.com>
From: "Alex Villacís" <sip:avil...@pbx.villacis.com>;tag=iqtae2p0rv
Call-ID: 4ik6fb8n4rd5uimh2ps3
CSeq: 1016 SUBSCRIBE
Event: presence.winfo
Expires: 0
Contact: <sip:77g5cfiv@3u2gggnosgp0.invalid;transport=ws>