-
Notifications
You must be signed in to change notification settings - Fork 793
Expand file tree
/
Copy pathReferNotifier.js
More file actions
66 lines (56 loc) · 1.39 KB
/
ReferNotifier.js
File metadata and controls
66 lines (56 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const Logger = require('../Logger');
const JsSIP_C = require('../Constants');
const logger = new Logger('RTCSession:ReferNotifier');
const C = {
event_type : 'refer',
body_type : 'message/sipfrag;version=2.0',
expires : 300
};
module.exports = class ReferNotifier
{
constructor(session, id, expires)
{
this._session = session;
this._id = id;
this._expires = expires || C.expires;
this._active = true;
// The creation of a Notifier results in an immediate NOTIFY.
this.notify(100);
}
notify(code, reason)
{
logger.debug('notify()');
if (this._active === false)
{
return;
}
reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
let state;
if (code >= 200)
{
state = 'terminated;reason=noresource';
}
else
{
state = `active;expires=${this._expires}`;
}
try
{
this._session.sendRequest(JsSIP_C.NOTIFY, {
extraHeaders : [
`Event: ${C.event_type};id=${this._id}`,
`Subscription-State: ${state}`,
`Content-Type: ${C.body_type}`
],
body : `SIP/2.0 ${code} ${reason}`,
eventHandlers : {
// If a negative response is received, subscription is canceled.
onErrorResponse() { this._active = false; }
}
});
}
catch (e) {
logger.debug('sendRequest exception ignored', e);
}
}
};