ringcentral-softphone 1.3.1 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/call-session/inbound.cjs +93 -0
- package/dist/call-session/inbound.js +64 -0
- package/dist/call-session/index.cjs +270 -0
- package/dist/{esm/call-session → call-session}/index.d.ts +3 -3
- package/dist/call-session/index.js +244 -0
- package/dist/call-session/outbound.cjs +100 -0
- package/dist/call-session/outbound.js +71 -0
- package/dist/call-session/streamer.cjs +112 -0
- package/dist/call-session/streamer.js +83 -0
- package/dist/codec.cjs +85 -0
- package/dist/codec.js +66 -0
- package/dist/dtmf.cjs +65 -0
- package/dist/dtmf.js +46 -0
- package/dist/index.cjs +258 -0
- package/dist/{cjs/index.d.ts → index.d.ts} +3 -3
- package/dist/index.js +240 -0
- package/dist/sip-message/inbound/index.cjs +51 -0
- package/dist/sip-message/inbound/index.js +22 -0
- package/dist/sip-message/index.cjs +49 -0
- package/dist/sip-message/index.js +12 -0
- package/dist/sip-message/outbound/index.cjs +41 -0
- package/dist/sip-message/outbound/index.js +12 -0
- package/dist/sip-message/outbound/request.cjs +62 -0
- package/dist/sip-message/outbound/request.js +33 -0
- package/dist/sip-message/outbound/response.cjs +55 -0
- package/dist/sip-message/outbound/response.js +26 -0
- package/dist/sip-message/response-codes.cjs +102 -0
- package/dist/sip-message/response-codes.js +83 -0
- package/dist/sip-message/sip-message.cjs +53 -0
- package/dist/sip-message/sip-message.js +34 -0
- package/dist/types.cjs +15 -0
- package/dist/types.js +0 -0
- package/dist/utils.cjs +80 -0
- package/dist/{cjs/utils.d.ts → utils.d.ts} +2 -2
- package/dist/utils.js +41 -0
- package/package.json +19 -13
- package/dist/cjs/call-session/inbound.js +0 -57
- package/dist/cjs/call-session/index.d.ts +0 -44
- package/dist/cjs/call-session/index.js +0 -239
- package/dist/cjs/call-session/outbound.js +0 -66
- package/dist/cjs/call-session/streamer.d.ts +0 -17
- package/dist/cjs/call-session/streamer.js +0 -75
- package/dist/cjs/codec.js +0 -65
- package/dist/cjs/dtmf.js +0 -45
- package/dist/cjs/index.js +0 -209
- package/dist/cjs/sip-message/inbound/index.js +0 -22
- package/dist/cjs/sip-message/index.d.ts +0 -5
- package/dist/cjs/sip-message/index.js +0 -16
- package/dist/cjs/sip-message/outbound/index.js +0 -14
- package/dist/cjs/sip-message/outbound/request.js +0 -28
- package/dist/cjs/sip-message/outbound/response.js +0 -25
- package/dist/cjs/sip-message/response-codes.js +0 -83
- package/dist/cjs/sip-message/sip-message.js +0 -34
- package/dist/cjs/types.js +0 -2
- package/dist/cjs/utils.js +0 -40
- package/dist/esm/call-session/inbound.d.ts +0 -8
- package/dist/esm/call-session/inbound.js +0 -52
- package/dist/esm/call-session/index.js +0 -234
- package/dist/esm/call-session/outbound.d.ts +0 -11
- package/dist/esm/call-session/outbound.js +0 -61
- package/dist/esm/call-session/streamer.js +0 -70
- package/dist/esm/codec.d.ts +0 -15
- package/dist/esm/codec.js +0 -63
- package/dist/esm/dtmf.d.ts +0 -8
- package/dist/esm/dtmf.js +0 -43
- package/dist/esm/index.d.ts +0 -28
- package/dist/esm/index.js +0 -204
- package/dist/esm/sip-message/inbound/index.d.ts +0 -5
- package/dist/esm/sip-message/inbound/index.js +0 -17
- package/dist/esm/sip-message/index.js +0 -5
- package/dist/esm/sip-message/outbound/index.d.ts +0 -5
- package/dist/esm/sip-message/outbound/index.js +0 -9
- package/dist/esm/sip-message/outbound/request.d.ts +0 -7
- package/dist/esm/sip-message/outbound/request.js +0 -23
- package/dist/esm/sip-message/outbound/response.d.ts +0 -6
- package/dist/esm/sip-message/outbound/response.js +0 -20
- package/dist/esm/sip-message/response-codes.d.ts +0 -4
- package/dist/esm/sip-message/response-codes.js +0 -81
- package/dist/esm/sip-message/sip-message.d.ts +0 -11
- package/dist/esm/sip-message/sip-message.js +0 -32
- package/dist/esm/types.d.ts +0 -9
- package/dist/esm/types.js +0 -1
- package/dist/esm/utils.d.ts +0 -8
- package/dist/esm/utils.js +0 -28
- package/dist/{cjs/call-session → call-session}/inbound.d.ts +2 -2
- package/dist/{cjs/call-session → call-session}/outbound.d.ts +2 -2
- package/dist/{esm/call-session → call-session}/streamer.d.ts +1 -1
- package/dist/{cjs/codec.d.ts → codec.d.ts} +0 -0
- package/dist/{cjs/dtmf.d.ts → dtmf.d.ts} +0 -0
- package/dist/{cjs/sip-message → sip-message}/inbound/index.d.ts +0 -0
- package/dist/{esm/sip-message → sip-message}/index.d.ts +2 -2
- package/dist/{cjs/sip-message → sip-message}/outbound/index.d.ts +0 -0
- package/dist/{cjs/sip-message → sip-message}/outbound/request.d.ts +0 -0
- package/dist/{cjs/sip-message → sip-message}/outbound/response.d.ts +1 -1
- /package/dist/{cjs/sip-message → sip-message}/response-codes.d.ts +0 -0
- /package/dist/{cjs/sip-message → sip-message}/sip-message.d.ts +0 -0
- /package/dist/{cjs/types.d.ts → types.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var inbound_exports = {};
|
|
29
|
+
__export(inbound_exports, {
|
|
30
|
+
default: () => inbound_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(inbound_exports);
|
|
33
|
+
var import_sip_message = require("../sip-message/index.js");
|
|
34
|
+
var import_utils = require("../utils.js");
|
|
35
|
+
var import_index = __toESM(require("./index.js"), 1);
|
|
36
|
+
class InboundCallSession extends import_index.default {
|
|
37
|
+
constructor(softphone, inviteMessage) {
|
|
38
|
+
super(softphone, inviteMessage);
|
|
39
|
+
this.localPeer = inviteMessage.headers.To;
|
|
40
|
+
this.remotePeer = inviteMessage.headers.From;
|
|
41
|
+
if (inviteMessage.body.length > 0) {
|
|
42
|
+
this.remoteKey = inviteMessage.body.match(
|
|
43
|
+
/AES_CM_128_HMAC_SHA1_80 inline:([\w+/]+)/
|
|
44
|
+
)[1];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async answer() {
|
|
48
|
+
const answerSDP = `
|
|
49
|
+
v=0
|
|
50
|
+
o=- ${Date.now()} 0 IN IP4 ${this.softphone.client.localAddress}
|
|
51
|
+
s=rc-softphone-ts
|
|
52
|
+
c=IN IP4 ${this.softphone.client.localAddress}
|
|
53
|
+
t=0 0
|
|
54
|
+
m=audio ${(0, import_utils.randomInt)()} RTP/SAVP ${this.softphone.codec.id} 101
|
|
55
|
+
a=rtpmap:${this.softphone.codec.id} ${this.softphone.codec.name}
|
|
56
|
+
a=rtpmap:101 telephone-event/8000
|
|
57
|
+
a=fmtp:101 0-15
|
|
58
|
+
a=sendrecv
|
|
59
|
+
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:${import_utils.localKey}
|
|
60
|
+
`.trim();
|
|
61
|
+
this.sdp = answerSDP;
|
|
62
|
+
const newMessage = new import_sip_message.OutboundMessage(
|
|
63
|
+
"SIP/2.0 200 OK",
|
|
64
|
+
{
|
|
65
|
+
Via: this.sipMessage.headers.Via,
|
|
66
|
+
"Call-ID": this.sipMessage.getHeader("Call-ID"),
|
|
67
|
+
From: this.sipMessage.headers.From,
|
|
68
|
+
To: this.sipMessage.headers.To,
|
|
69
|
+
CSeq: this.sipMessage.headers.CSeq,
|
|
70
|
+
Contact: `<sip:${this.softphone.sipInfo.username}@${this.softphone.client.localAddress}:${this.softphone.client.localPort};transport=TLS;ob>`,
|
|
71
|
+
Allow: "PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS",
|
|
72
|
+
Supported: "replaces, 100rel, timer, norefersub",
|
|
73
|
+
"Session-Expires": "14400;refresher=uac",
|
|
74
|
+
Require: "timer",
|
|
75
|
+
"Content-Type": "application/sdp"
|
|
76
|
+
},
|
|
77
|
+
answerSDP
|
|
78
|
+
);
|
|
79
|
+
const ackMessage = await this.softphone.send(newMessage, true);
|
|
80
|
+
if (ackMessage.body.length > 0) {
|
|
81
|
+
this.remoteIP = ackMessage.body.match(/c=IN IP4 ([\d.]+)/)[1];
|
|
82
|
+
this.remotePort = parseInt(
|
|
83
|
+
ackMessage.body.match(/m=audio (\d+) /)[1],
|
|
84
|
+
10
|
|
85
|
+
);
|
|
86
|
+
this.remoteKey = ackMessage.body.match(
|
|
87
|
+
/AES_CM_128_HMAC_SHA1_80 inline:([\w+/]+)/
|
|
88
|
+
)[1];
|
|
89
|
+
}
|
|
90
|
+
this.startLocalServices();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
var inbound_default = InboundCallSession;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OutboundMessage } from "../sip-message/index.js";
|
|
2
|
+
import { localKey, randomInt } from "../utils.js";
|
|
3
|
+
import CallSession from "./index.js";
|
|
4
|
+
class InboundCallSession extends CallSession {
|
|
5
|
+
constructor(softphone, inviteMessage) {
|
|
6
|
+
super(softphone, inviteMessage);
|
|
7
|
+
this.localPeer = inviteMessage.headers.To;
|
|
8
|
+
this.remotePeer = inviteMessage.headers.From;
|
|
9
|
+
if (inviteMessage.body.length > 0) {
|
|
10
|
+
this.remoteKey = inviteMessage.body.match(
|
|
11
|
+
/AES_CM_128_HMAC_SHA1_80 inline:([\w+/]+)/
|
|
12
|
+
)[1];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async answer() {
|
|
16
|
+
const answerSDP = `
|
|
17
|
+
v=0
|
|
18
|
+
o=- ${Date.now()} 0 IN IP4 ${this.softphone.client.localAddress}
|
|
19
|
+
s=rc-softphone-ts
|
|
20
|
+
c=IN IP4 ${this.softphone.client.localAddress}
|
|
21
|
+
t=0 0
|
|
22
|
+
m=audio ${randomInt()} RTP/SAVP ${this.softphone.codec.id} 101
|
|
23
|
+
a=rtpmap:${this.softphone.codec.id} ${this.softphone.codec.name}
|
|
24
|
+
a=rtpmap:101 telephone-event/8000
|
|
25
|
+
a=fmtp:101 0-15
|
|
26
|
+
a=sendrecv
|
|
27
|
+
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:${localKey}
|
|
28
|
+
`.trim();
|
|
29
|
+
this.sdp = answerSDP;
|
|
30
|
+
const newMessage = new OutboundMessage(
|
|
31
|
+
"SIP/2.0 200 OK",
|
|
32
|
+
{
|
|
33
|
+
Via: this.sipMessage.headers.Via,
|
|
34
|
+
"Call-ID": this.sipMessage.getHeader("Call-ID"),
|
|
35
|
+
From: this.sipMessage.headers.From,
|
|
36
|
+
To: this.sipMessage.headers.To,
|
|
37
|
+
CSeq: this.sipMessage.headers.CSeq,
|
|
38
|
+
Contact: `<sip:${this.softphone.sipInfo.username}@${this.softphone.client.localAddress}:${this.softphone.client.localPort};transport=TLS;ob>`,
|
|
39
|
+
Allow: "PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS",
|
|
40
|
+
Supported: "replaces, 100rel, timer, norefersub",
|
|
41
|
+
"Session-Expires": "14400;refresher=uac",
|
|
42
|
+
Require: "timer",
|
|
43
|
+
"Content-Type": "application/sdp"
|
|
44
|
+
},
|
|
45
|
+
answerSDP
|
|
46
|
+
);
|
|
47
|
+
const ackMessage = await this.softphone.send(newMessage, true);
|
|
48
|
+
if (ackMessage.body.length > 0) {
|
|
49
|
+
this.remoteIP = ackMessage.body.match(/c=IN IP4 ([\d.]+)/)[1];
|
|
50
|
+
this.remotePort = parseInt(
|
|
51
|
+
ackMessage.body.match(/m=audio (\d+) /)[1],
|
|
52
|
+
10
|
|
53
|
+
);
|
|
54
|
+
this.remoteKey = ackMessage.body.match(
|
|
55
|
+
/AES_CM_128_HMAC_SHA1_80 inline:([\w+/]+)/
|
|
56
|
+
)[1];
|
|
57
|
+
}
|
|
58
|
+
this.startLocalServices();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
var inbound_default = InboundCallSession;
|
|
62
|
+
export {
|
|
63
|
+
inbound_default as default
|
|
64
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var call_session_exports = {};
|
|
29
|
+
__export(call_session_exports, {
|
|
30
|
+
default: () => call_session_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(call_session_exports);
|
|
33
|
+
var import_node_buffer = require("node:buffer");
|
|
34
|
+
var import_node_dgram = __toESM(require("node:dgram"), 1);
|
|
35
|
+
var import_node_events = __toESM(require("node:events"), 1);
|
|
36
|
+
var import_wait_for_async = __toESM(require("wait-for-async"), 1);
|
|
37
|
+
var import_werift_rtp = require("werift-rtp");
|
|
38
|
+
var import_dtmf = __toESM(require("../dtmf.js"), 1);
|
|
39
|
+
var import_sip_message = require("../sip-message/index.js");
|
|
40
|
+
var import_utils = require("../utils.js");
|
|
41
|
+
var import_streamer = __toESM(require("./streamer.js"), 1);
|
|
42
|
+
class CallSession extends import_node_events.default {
|
|
43
|
+
softphone;
|
|
44
|
+
sipMessage;
|
|
45
|
+
socket;
|
|
46
|
+
localPeer;
|
|
47
|
+
remotePeer;
|
|
48
|
+
remoteIP;
|
|
49
|
+
remotePort;
|
|
50
|
+
disposed = false;
|
|
51
|
+
srtpSession;
|
|
52
|
+
encoder;
|
|
53
|
+
decoder;
|
|
54
|
+
sdp;
|
|
55
|
+
// for audio streaming
|
|
56
|
+
ssrc = (0, import_utils.randomInt)();
|
|
57
|
+
sequenceNumber = (0, import_utils.randomInt)();
|
|
58
|
+
timestamp = (0, import_utils.randomInt)();
|
|
59
|
+
constructor(softphone, sipMessage) {
|
|
60
|
+
super();
|
|
61
|
+
this.softphone = softphone;
|
|
62
|
+
this.encoder = softphone.codec.createEncoder();
|
|
63
|
+
this.decoder = softphone.codec.createDecoder();
|
|
64
|
+
this.sipMessage = sipMessage;
|
|
65
|
+
if (this.sipMessage.body.length > 0) {
|
|
66
|
+
this.remoteIP = this.sipMessage.body.match(/c=IN IP4 ([\d.]+)/)[1];
|
|
67
|
+
this.remotePort = parseInt(
|
|
68
|
+
this.sipMessage.body.match(/m=audio (\d+) /)[1],
|
|
69
|
+
10
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
set remoteKey(key) {
|
|
74
|
+
const localKeyBuffer = import_node_buffer.Buffer.from(import_utils.localKey, "base64");
|
|
75
|
+
const remoteKeyBuffer = import_node_buffer.Buffer.from(key, "base64");
|
|
76
|
+
this.srtpSession = new import_werift_rtp.SrtpSession({
|
|
77
|
+
profile: 1,
|
|
78
|
+
keys: {
|
|
79
|
+
localMasterKey: localKeyBuffer.subarray(0, 16),
|
|
80
|
+
localMasterSalt: localKeyBuffer.subarray(16, 30),
|
|
81
|
+
remoteMasterKey: remoteKeyBuffer.subarray(0, 16),
|
|
82
|
+
remoteMasterSalt: remoteKeyBuffer.subarray(16, 30)
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
get callId() {
|
|
87
|
+
return this.sipMessage.getHeader("Call-ID");
|
|
88
|
+
}
|
|
89
|
+
send(data) {
|
|
90
|
+
this.socket.send(data, this.remotePort, this.remoteIP);
|
|
91
|
+
}
|
|
92
|
+
async hangup() {
|
|
93
|
+
const requestMessage = new import_sip_message.RequestMessage(
|
|
94
|
+
`BYE sip:${this.softphone.sipInfo.domain} SIP/2.0`,
|
|
95
|
+
{
|
|
96
|
+
"Call-ID": this.callId,
|
|
97
|
+
From: this.localPeer,
|
|
98
|
+
To: this.remotePeer,
|
|
99
|
+
Via: `SIP/2.0/TLS ${this.softphone.fakeDomain};branch=${(0, import_utils.branch)()}`
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
await this.softphone.send(requestMessage);
|
|
103
|
+
}
|
|
104
|
+
sendDTMF(char) {
|
|
105
|
+
const payloads = import_dtmf.default.charToPayloads(char);
|
|
106
|
+
const timestamp = this.timestamp;
|
|
107
|
+
let first = true;
|
|
108
|
+
for (const payload of payloads) {
|
|
109
|
+
const rtpHeader = new import_werift_rtp.RtpHeader({
|
|
110
|
+
version: 2,
|
|
111
|
+
padding: false,
|
|
112
|
+
paddingSize: 0,
|
|
113
|
+
extension: false,
|
|
114
|
+
marker: first,
|
|
115
|
+
payloadOffset: 12,
|
|
116
|
+
payloadType: 101,
|
|
117
|
+
sequenceNumber: this.sequenceNumber,
|
|
118
|
+
timestamp,
|
|
119
|
+
ssrc: this.ssrc,
|
|
120
|
+
csrcLength: 0,
|
|
121
|
+
csrc: [],
|
|
122
|
+
extensionProfile: 48862,
|
|
123
|
+
extensionLength: void 0,
|
|
124
|
+
extensions: []
|
|
125
|
+
});
|
|
126
|
+
const rtpPacket = new import_werift_rtp.RtpPacket(rtpHeader, payload);
|
|
127
|
+
this.send(this.srtpSession.encrypt(rtpPacket.payload, rtpPacket.header));
|
|
128
|
+
this.sequenceNumber = (this.sequenceNumber + 1) % 65536;
|
|
129
|
+
first = false;
|
|
130
|
+
}
|
|
131
|
+
this.timestamp += 800;
|
|
132
|
+
}
|
|
133
|
+
async sendDTMFs(s, delay = 500) {
|
|
134
|
+
for (const c of s) {
|
|
135
|
+
this.sendDTMF(c);
|
|
136
|
+
await (0, import_wait_for_async.default)({ interval: delay });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// buffer is the content of a audio file, it is supposed to be uncompressed PCM data
|
|
140
|
+
// The audio should be playable by command: play -t raw -b 16 -r 16000 -e signed-integer test.wav
|
|
141
|
+
streamAudio(input) {
|
|
142
|
+
const streamer = new import_streamer.default(this, input);
|
|
143
|
+
streamer.start();
|
|
144
|
+
return streamer;
|
|
145
|
+
}
|
|
146
|
+
// send a single rtp packet
|
|
147
|
+
sendPacket(rtpPacket) {
|
|
148
|
+
if (this.disposed) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
this.send(this.srtpSession.encrypt(rtpPacket.payload, rtpPacket.header));
|
|
152
|
+
}
|
|
153
|
+
startLocalServices() {
|
|
154
|
+
this.socket = import_node_dgram.default.createSocket("udp4");
|
|
155
|
+
this.socket.on("message", (message) => {
|
|
156
|
+
const rtpPacket = import_werift_rtp.RtpPacket.deSerialize(
|
|
157
|
+
this.srtpSession.decrypt(message)
|
|
158
|
+
);
|
|
159
|
+
this.emit("rtpPacket", rtpPacket);
|
|
160
|
+
if (rtpPacket.header.payloadType === 101) {
|
|
161
|
+
this.emit("dtmfPacket", rtpPacket);
|
|
162
|
+
const char = import_dtmf.default.payloadToChar(rtpPacket.payload);
|
|
163
|
+
if (char) {
|
|
164
|
+
this.emit("dtmf", char);
|
|
165
|
+
}
|
|
166
|
+
} else if (rtpPacket.header.payloadType === this.softphone.codec.id) {
|
|
167
|
+
if (rtpPacket.payload.length === 4 && rtpPacket.payload[0] >= 0 && rtpPacket.payload[0] < 12 && rtpPacket.payload[1] === 138 && rtpPacket.payload[2] === 3 && rtpPacket.payload[3] === 192) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
rtpPacket.payload = this.decoder.decode(rtpPacket.payload);
|
|
172
|
+
this.emit("audioPacket", rtpPacket);
|
|
173
|
+
} catch {
|
|
174
|
+
console.error("Audio packet decode failed", rtpPacket);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
this.socket.bind();
|
|
179
|
+
this.send("hello");
|
|
180
|
+
const byeHandler = (inboundMessage) => {
|
|
181
|
+
if (inboundMessage.getHeader("Call-ID") !== this.callId) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (inboundMessage.headers.CSeq.endsWith(" BYE")) {
|
|
185
|
+
this.softphone.off("message", byeHandler);
|
|
186
|
+
this.dispose();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
this.softphone.on("message", byeHandler);
|
|
190
|
+
}
|
|
191
|
+
dispose() {
|
|
192
|
+
this.disposed = true;
|
|
193
|
+
this.emit("disposed");
|
|
194
|
+
this.removeAllListeners();
|
|
195
|
+
this.socket?.removeAllListeners();
|
|
196
|
+
this.socket?.close();
|
|
197
|
+
}
|
|
198
|
+
async transfer(transferTo) {
|
|
199
|
+
const requestMessage = new import_sip_message.RequestMessage(
|
|
200
|
+
`REFER sip:${this.softphone.sipInfo.username}@${this.softphone.sipInfo.outboundProxy};transport=tls SIP/2.0`,
|
|
201
|
+
{
|
|
202
|
+
Via: `SIP/2.0/TLS ${this.softphone.client.localAddress}:${this.softphone.client.localPort};rport;branch=${(0, import_utils.branch)()};alias`,
|
|
203
|
+
"Max-Forwards": 70,
|
|
204
|
+
From: this.localPeer,
|
|
205
|
+
To: this.remotePeer,
|
|
206
|
+
Contact: `<sip:${this.softphone.sipInfo.username}@${this.softphone.client.localAddress}:${this.softphone.client.localPort};transport=TLS;ob>`,
|
|
207
|
+
"Call-ID": this.callId,
|
|
208
|
+
Event: "refer",
|
|
209
|
+
Expires: 600,
|
|
210
|
+
Supported: "replaces, 100rel, timer, norefersub",
|
|
211
|
+
Accept: "message/sipfrag;version=2.0",
|
|
212
|
+
"Allow-Events": "presence, message-summary, refer",
|
|
213
|
+
"Refer-To": `sip:${transferTo}@${this.softphone.sipInfo.domain}`,
|
|
214
|
+
"Referred-By": `<sip:${this.softphone.sipInfo.username}@${this.softphone.sipInfo.domain}>`
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
await this.softphone.send(requestMessage);
|
|
218
|
+
return new Promise((resolve) => {
|
|
219
|
+
const notifyHandler = (inboundMessage) => {
|
|
220
|
+
if (!inboundMessage.subject.startsWith("NOTIFY ")) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const responseMessage = new import_sip_message.ResponseMessage(inboundMessage, 200);
|
|
224
|
+
this.softphone.send(responseMessage);
|
|
225
|
+
if (inboundMessage.body.trim() === "SIP/2.0 200 OK") {
|
|
226
|
+
this.softphone.off("message", notifyHandler);
|
|
227
|
+
resolve();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
this.softphone.on("message", notifyHandler);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async toggleReceive(toReceive) {
|
|
234
|
+
let newSDP = this.sdp;
|
|
235
|
+
if (!toReceive) {
|
|
236
|
+
newSDP = newSDP.replace(/a=sendrecv/, "a=sendonly");
|
|
237
|
+
}
|
|
238
|
+
const requestMessage = new import_sip_message.RequestMessage(
|
|
239
|
+
`INVITE ${(0, import_utils.extractAddress)(this.remotePeer)} SIP/2.0`,
|
|
240
|
+
{
|
|
241
|
+
"Call-Id": this.callId,
|
|
242
|
+
From: this.localPeer,
|
|
243
|
+
To: this.remotePeer,
|
|
244
|
+
Via: `SIP/2.0/TLS ${this.softphone.client.localAddress}:${this.softphone.client.localPort};rport;branch=${(0, import_utils.branch)()};alias`,
|
|
245
|
+
"Content-Type": "application/sdp",
|
|
246
|
+
Contact: ` <sip:${this.softphone.sipInfo.username}@${this.softphone.client.localAddress}:${this.softphone.client.localPort};transport=TLS;ob>`
|
|
247
|
+
},
|
|
248
|
+
newSDP
|
|
249
|
+
);
|
|
250
|
+
const replyMessage = await this.softphone.send(requestMessage, true);
|
|
251
|
+
const ackMessage = new import_sip_message.RequestMessage(
|
|
252
|
+
`ACK ${(0, import_utils.extractAddress)(this.remotePeer)} SIP/2.0`,
|
|
253
|
+
{
|
|
254
|
+
"Call-Id": this.callId,
|
|
255
|
+
From: this.localPeer,
|
|
256
|
+
To: this.remotePeer,
|
|
257
|
+
Via: replyMessage.headers.Via,
|
|
258
|
+
CSeq: replyMessage.headers.CSeq.replace(" INVITE", " ACK")
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
await this.softphone.send(ackMessage);
|
|
262
|
+
}
|
|
263
|
+
async hold() {
|
|
264
|
+
return this.toggleReceive(false);
|
|
265
|
+
}
|
|
266
|
+
async unhold() {
|
|
267
|
+
return this.toggleReceive(true);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
var call_session_default = CallSession;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
1
2
|
import dgram from "node:dgram";
|
|
2
3
|
import EventEmitter from "node:events";
|
|
3
|
-
import { Buffer } from "node:buffer";
|
|
4
4
|
import { RtpPacket, SrtpSession } from "werift-rtp";
|
|
5
|
-
import { type InboundMessage } from "../sip-message/index.js";
|
|
6
5
|
import type Softphone from "../index.js";
|
|
6
|
+
import { type InboundMessage } from "../sip-message/index.js";
|
|
7
7
|
import Streamer from "./streamer.js";
|
|
8
8
|
declare abstract class CallSession extends EventEmitter {
|
|
9
9
|
softphone: Softphone;
|
|
@@ -27,7 +27,7 @@ declare abstract class CallSession extends EventEmitter {
|
|
|
27
27
|
timestamp: number;
|
|
28
28
|
constructor(softphone: Softphone, sipMessage: InboundMessage);
|
|
29
29
|
set remoteKey(key: string);
|
|
30
|
-
get callId(): string;
|
|
30
|
+
get callId(): string | undefined;
|
|
31
31
|
send(data: string | Buffer): void;
|
|
32
32
|
hangup(): Promise<void>;
|
|
33
33
|
sendDTMF(char: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "*" | "#"): void;
|