ringcentral-softphone 1.3.2 → 1.3.4
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 +274 -0
- package/dist/{esm/call-session → call-session}/index.d.ts +6 -4
- package/dist/call-session/index.js +248 -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/{esm/call-session → call-session}/streamer.d.ts +2 -2
- package/dist/call-session/streamer.js +83 -0
- package/dist/codec.cjs +85 -0
- package/dist/codec.js +66 -0
- package/dist/dtmf.cjs +66 -0
- package/dist/dtmf.d.ts +7 -0
- package/dist/dtmf.js +47 -0
- package/dist/index.cjs +260 -0
- package/dist/{cjs/index.d.ts → index.d.ts} +3 -3
- package/dist/index.js +242 -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 -76
- package/dist/cjs/codec.js +0 -65
- package/dist/cjs/dtmf.d.ts +0 -8
- 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 -71
- 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/{cjs/codec.d.ts → codec.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/dist/codec.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var codec_exports = {};
|
|
19
|
+
__export(codec_exports, {
|
|
20
|
+
default: () => codec_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(codec_exports);
|
|
23
|
+
var import_node_buffer = require("node:buffer");
|
|
24
|
+
var import_opus = require("@evan/opus");
|
|
25
|
+
class Codec {
|
|
26
|
+
id;
|
|
27
|
+
name;
|
|
28
|
+
packetSize;
|
|
29
|
+
timestampInterval;
|
|
30
|
+
createEncoder;
|
|
31
|
+
createDecoder;
|
|
32
|
+
constructor(name) {
|
|
33
|
+
this.name = name;
|
|
34
|
+
switch (name) {
|
|
35
|
+
case "OPUS/16000": {
|
|
36
|
+
this.createEncoder = () => {
|
|
37
|
+
const encoder = new import_opus.Encoder({ channels: 1, sample_rate: 16e3 });
|
|
38
|
+
return { encode: (pcm) => import_node_buffer.Buffer.from(encoder.encode(pcm)) };
|
|
39
|
+
};
|
|
40
|
+
this.createDecoder = () => {
|
|
41
|
+
const decoder = new import_opus.Decoder({ channels: 1, sample_rate: 16e3 });
|
|
42
|
+
return {
|
|
43
|
+
decode: (opus) => import_node_buffer.Buffer.from(decoder.decode(opus))
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
this.id = 109;
|
|
47
|
+
this.packetSize = 640;
|
|
48
|
+
this.timestampInterval = 320;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "OPUS/48000/2": {
|
|
52
|
+
this.createEncoder = () => {
|
|
53
|
+
const encoder = new import_opus.Encoder({ channels: 2, sample_rate: 48e3 });
|
|
54
|
+
return { encode: (pcm) => import_node_buffer.Buffer.from(encoder.encode(pcm)) };
|
|
55
|
+
};
|
|
56
|
+
this.createDecoder = () => {
|
|
57
|
+
const decoder = new import_opus.Decoder({ channels: 2, sample_rate: 48e3 });
|
|
58
|
+
return {
|
|
59
|
+
decode: (opus) => import_node_buffer.Buffer.from(decoder.decode(opus))
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
this.id = 111;
|
|
63
|
+
this.packetSize = 3840;
|
|
64
|
+
this.timestampInterval = 960;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case "PCMU/8000": {
|
|
68
|
+
this.createEncoder = () => {
|
|
69
|
+
return { encode: (pcm) => pcm };
|
|
70
|
+
};
|
|
71
|
+
this.createDecoder = () => {
|
|
72
|
+
return { decode: (audio) => audio };
|
|
73
|
+
};
|
|
74
|
+
this.id = 0;
|
|
75
|
+
this.packetSize = 160;
|
|
76
|
+
this.timestampInterval = 160;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
default: {
|
|
80
|
+
throw new Error(`unsupported codec: ${name}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
var codec_default = Codec;
|
package/dist/codec.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { Decoder, Encoder } from "@evan/opus";
|
|
3
|
+
class Codec {
|
|
4
|
+
id;
|
|
5
|
+
name;
|
|
6
|
+
packetSize;
|
|
7
|
+
timestampInterval;
|
|
8
|
+
createEncoder;
|
|
9
|
+
createDecoder;
|
|
10
|
+
constructor(name) {
|
|
11
|
+
this.name = name;
|
|
12
|
+
switch (name) {
|
|
13
|
+
case "OPUS/16000": {
|
|
14
|
+
this.createEncoder = () => {
|
|
15
|
+
const encoder = new Encoder({ channels: 1, sample_rate: 16e3 });
|
|
16
|
+
return { encode: (pcm) => Buffer.from(encoder.encode(pcm)) };
|
|
17
|
+
};
|
|
18
|
+
this.createDecoder = () => {
|
|
19
|
+
const decoder = new Decoder({ channels: 1, sample_rate: 16e3 });
|
|
20
|
+
return {
|
|
21
|
+
decode: (opus) => Buffer.from(decoder.decode(opus))
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
this.id = 109;
|
|
25
|
+
this.packetSize = 640;
|
|
26
|
+
this.timestampInterval = 320;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case "OPUS/48000/2": {
|
|
30
|
+
this.createEncoder = () => {
|
|
31
|
+
const encoder = new Encoder({ channels: 2, sample_rate: 48e3 });
|
|
32
|
+
return { encode: (pcm) => Buffer.from(encoder.encode(pcm)) };
|
|
33
|
+
};
|
|
34
|
+
this.createDecoder = () => {
|
|
35
|
+
const decoder = new Decoder({ channels: 2, sample_rate: 48e3 });
|
|
36
|
+
return {
|
|
37
|
+
decode: (opus) => Buffer.from(decoder.decode(opus))
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
this.id = 111;
|
|
41
|
+
this.packetSize = 3840;
|
|
42
|
+
this.timestampInterval = 960;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case "PCMU/8000": {
|
|
46
|
+
this.createEncoder = () => {
|
|
47
|
+
return { encode: (pcm) => pcm };
|
|
48
|
+
};
|
|
49
|
+
this.createDecoder = () => {
|
|
50
|
+
return { decode: (audio) => audio };
|
|
51
|
+
};
|
|
52
|
+
this.id = 0;
|
|
53
|
+
this.packetSize = 160;
|
|
54
|
+
this.timestampInterval = 160;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
default: {
|
|
58
|
+
throw new Error(`unsupported codec: ${name}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
var codec_default = Codec;
|
|
64
|
+
export {
|
|
65
|
+
codec_default as default
|
|
66
|
+
};
|
package/dist/dtmf.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var dtmf_exports = {};
|
|
19
|
+
__export(dtmf_exports, {
|
|
20
|
+
default: () => dtmf_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(dtmf_exports);
|
|
23
|
+
var import_node_buffer = require("node:buffer");
|
|
24
|
+
const phoneChars = [
|
|
25
|
+
"0",
|
|
26
|
+
"1",
|
|
27
|
+
"2",
|
|
28
|
+
"3",
|
|
29
|
+
"4",
|
|
30
|
+
"5",
|
|
31
|
+
"6",
|
|
32
|
+
"7",
|
|
33
|
+
"8",
|
|
34
|
+
"9",
|
|
35
|
+
"*",
|
|
36
|
+
"#"
|
|
37
|
+
];
|
|
38
|
+
const payloads = [
|
|
39
|
+
393216,
|
|
40
|
+
393376,
|
|
41
|
+
393536,
|
|
42
|
+
8782624,
|
|
43
|
+
8782624,
|
|
44
|
+
8782624
|
|
45
|
+
];
|
|
46
|
+
const DTMF = {
|
|
47
|
+
phoneChars,
|
|
48
|
+
charToPayloads(char) {
|
|
49
|
+
const index = phoneChars.indexOf(char[0]);
|
|
50
|
+
if (index === -1) {
|
|
51
|
+
throw new Error("invalid phone char");
|
|
52
|
+
}
|
|
53
|
+
return payloads.map((payload) => {
|
|
54
|
+
const temp = payload + index * 16777216;
|
|
55
|
+
const buffer = import_node_buffer.Buffer.alloc(4);
|
|
56
|
+
buffer.writeIntBE(temp, 0, 4);
|
|
57
|
+
return buffer;
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
payloadToChar(payload) {
|
|
61
|
+
const intBE = payload.readIntBE(0, 4);
|
|
62
|
+
const index = (intBE - 393216) / 16777216;
|
|
63
|
+
return phoneChars[index];
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var dtmf_default = DTMF;
|
package/dist/dtmf.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
declare const DTMF: {
|
|
3
|
+
phoneChars: readonly ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "#"];
|
|
4
|
+
charToPayloads(char: string): Buffer<ArrayBuffer>[];
|
|
5
|
+
payloadToChar(payload: Buffer): "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "*" | "#";
|
|
6
|
+
};
|
|
7
|
+
export default DTMF;
|
package/dist/dtmf.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
const phoneChars = [
|
|
3
|
+
"0",
|
|
4
|
+
"1",
|
|
5
|
+
"2",
|
|
6
|
+
"3",
|
|
7
|
+
"4",
|
|
8
|
+
"5",
|
|
9
|
+
"6",
|
|
10
|
+
"7",
|
|
11
|
+
"8",
|
|
12
|
+
"9",
|
|
13
|
+
"*",
|
|
14
|
+
"#"
|
|
15
|
+
];
|
|
16
|
+
const payloads = [
|
|
17
|
+
393216,
|
|
18
|
+
393376,
|
|
19
|
+
393536,
|
|
20
|
+
8782624,
|
|
21
|
+
8782624,
|
|
22
|
+
8782624
|
|
23
|
+
];
|
|
24
|
+
const DTMF = {
|
|
25
|
+
phoneChars,
|
|
26
|
+
charToPayloads(char) {
|
|
27
|
+
const index = phoneChars.indexOf(char[0]);
|
|
28
|
+
if (index === -1) {
|
|
29
|
+
throw new Error("invalid phone char");
|
|
30
|
+
}
|
|
31
|
+
return payloads.map((payload) => {
|
|
32
|
+
const temp = payload + index * 16777216;
|
|
33
|
+
const buffer = Buffer.alloc(4);
|
|
34
|
+
buffer.writeIntBE(temp, 0, 4);
|
|
35
|
+
return buffer;
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
payloadToChar(payload) {
|
|
39
|
+
const intBE = payload.readIntBE(0, 4);
|
|
40
|
+
const index = (intBE - 393216) / 16777216;
|
|
41
|
+
return phoneChars[index];
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var dtmf_default = DTMF;
|
|
45
|
+
export {
|
|
46
|
+
dtmf_default as default
|
|
47
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
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 index_exports = {};
|
|
29
|
+
__export(index_exports, {
|
|
30
|
+
default: () => index_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
var import_node_events = __toESM(require("node:events"), 1);
|
|
34
|
+
var import_node_tls = __toESM(require("node:tls"), 1);
|
|
35
|
+
var import_wait_for_async = __toESM(require("wait-for-async"), 1);
|
|
36
|
+
var import_inbound = __toESM(require("./call-session/inbound.js"), 1);
|
|
37
|
+
var import_outbound = __toESM(require("./call-session/outbound.js"), 1);
|
|
38
|
+
var import_codec = __toESM(require("./codec.js"), 1);
|
|
39
|
+
var import_sip_message = require("./sip-message/index.js");
|
|
40
|
+
var import_utils = require("./utils.js");
|
|
41
|
+
class Softphone extends import_node_events.default {
|
|
42
|
+
sipInfo;
|
|
43
|
+
client;
|
|
44
|
+
codec;
|
|
45
|
+
fakeDomain = `${(0, import_utils.uuid)()}.invalid`;
|
|
46
|
+
fakeEmail = `${(0, import_utils.uuid)()}@${this.fakeDomain}`;
|
|
47
|
+
intervalHandle;
|
|
48
|
+
connected = false;
|
|
49
|
+
constructor(sipInfo) {
|
|
50
|
+
super();
|
|
51
|
+
if (sipInfo.codec === void 0) {
|
|
52
|
+
sipInfo.codec = "OPUS/16000";
|
|
53
|
+
}
|
|
54
|
+
this.codec = new import_codec.default(sipInfo.codec);
|
|
55
|
+
this.sipInfo = sipInfo;
|
|
56
|
+
if (this.sipInfo.domain === void 0) {
|
|
57
|
+
this.sipInfo.domain = "sip.ringcentral.com";
|
|
58
|
+
}
|
|
59
|
+
if (this.sipInfo.outboundProxy === void 0) {
|
|
60
|
+
this.sipInfo.outboundProxy = "sip10.ringcentral.com:5096";
|
|
61
|
+
}
|
|
62
|
+
const tokens = this.sipInfo.outboundProxy.split(":");
|
|
63
|
+
this.client = import_node_tls.default.connect(
|
|
64
|
+
{
|
|
65
|
+
host: tokens[0],
|
|
66
|
+
port: parseInt(tokens[1], 10),
|
|
67
|
+
rejectUnauthorized: !this.sipInfo.ignoreTlsCertErrors
|
|
68
|
+
},
|
|
69
|
+
() => {
|
|
70
|
+
this.connected = true;
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
let cache = "";
|
|
74
|
+
this.client.on("data", (data) => {
|
|
75
|
+
cache += data.toString("utf-8");
|
|
76
|
+
if (!cache.endsWith("\r\n")) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const tempMessages = cache.split("\r\nContent-Length: 0\r\n\r\n").filter((message) => message.trim() !== "");
|
|
80
|
+
cache = "";
|
|
81
|
+
for (let i = 0; i < tempMessages.length; i++) {
|
|
82
|
+
if (!tempMessages[i].includes("Content-Length: ")) {
|
|
83
|
+
tempMessages[i] = `${tempMessages[i]}\r
|
|
84
|
+
Content-Length: 0`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const message of tempMessages) {
|
|
88
|
+
this.emit("message", import_sip_message.InboundMessage.fromString(message));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
instanceId = (0, import_utils.uuid)();
|
|
93
|
+
registerCallId = (0, import_utils.uuid)();
|
|
94
|
+
async register() {
|
|
95
|
+
if (!this.connected) {
|
|
96
|
+
await (0, import_wait_for_async.default)({
|
|
97
|
+
interval: 100,
|
|
98
|
+
times: 100,
|
|
99
|
+
condition: () => this.connected
|
|
100
|
+
});
|
|
101
|
+
if (!this.connected) {
|
|
102
|
+
throw new Error("Failed to register: connect to TLS timeout");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const sipRegister = async () => {
|
|
106
|
+
const fromTag = (0, import_utils.uuid)();
|
|
107
|
+
const requestMessage = new import_sip_message.RequestMessage(
|
|
108
|
+
`REGISTER sip:${this.sipInfo.domain} SIP/2.0`,
|
|
109
|
+
{
|
|
110
|
+
Via: `SIP/2.0/TLS ${this.client.localAddress}:${this.client.localPort};rport;branch=${(0, import_utils.branch)()};alias`,
|
|
111
|
+
"Max-Forwards": "70",
|
|
112
|
+
From: `<sip:${this.sipInfo.username}@${this.sipInfo.domain}>;tag=${fromTag}`,
|
|
113
|
+
To: `<sip:${this.sipInfo.username}@${this.sipInfo.domain}>`,
|
|
114
|
+
"Call-ID": this.registerCallId,
|
|
115
|
+
Contact: `<sip:${this.sipInfo.username}@${this.client.localAddress}:${this.client.localPort};transport=TLS;ob>;reg-id=1;+sip.instance="<urn:uuid:${this.instanceId}>"`,
|
|
116
|
+
Expires: 3600,
|
|
117
|
+
Allow: "PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS"
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
const inboundMessage = await this.send(requestMessage, true);
|
|
121
|
+
if (inboundMessage.subject.startsWith("SIP/2.0 200 ")) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const wwwAuth = inboundMessage.getHeader("Www-Authenticate");
|
|
125
|
+
const nonce = wwwAuth.match(/, nonce="(.+?)"/)[1];
|
|
126
|
+
const newMessage = requestMessage.fork();
|
|
127
|
+
newMessage.headers.Authorization = (0, import_utils.generateAuthorization)(
|
|
128
|
+
this.sipInfo,
|
|
129
|
+
nonce,
|
|
130
|
+
"REGISTER"
|
|
131
|
+
);
|
|
132
|
+
const message = await this.send(newMessage, true);
|
|
133
|
+
if (!message.subject.startsWith("SIP/2.0 200 ")) {
|
|
134
|
+
throw new Error(`Failed to register: ${message.subject}`);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
await sipRegister();
|
|
138
|
+
this.intervalHandle = setInterval(
|
|
139
|
+
() => {
|
|
140
|
+
sipRegister().catch((error) => {
|
|
141
|
+
this.emit("registrationError", error);
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
30 * 1e3
|
|
145
|
+
// refresh registration every 30 seconds
|
|
146
|
+
);
|
|
147
|
+
this.on("message", (inboundMessage) => {
|
|
148
|
+
if (!inboundMessage.subject.startsWith("INVITE sip:")) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const outboundMessage = new import_sip_message.OutboundMessage("SIP/2.0 100 Trying", {
|
|
152
|
+
Via: inboundMessage.headers.Via,
|
|
153
|
+
"Call-ID": inboundMessage.getHeader("Call-ID"),
|
|
154
|
+
From: inboundMessage.headers.From,
|
|
155
|
+
To: inboundMessage.headers.To,
|
|
156
|
+
CSeq: inboundMessage.headers.CSeq,
|
|
157
|
+
"Content-Length": "0"
|
|
158
|
+
});
|
|
159
|
+
this.send(outboundMessage);
|
|
160
|
+
this.emit("invite", inboundMessage);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
enableDebugMode() {
|
|
164
|
+
this.on(
|
|
165
|
+
"message",
|
|
166
|
+
(message) => console.log(`Receiving...(${/* @__PURE__ */ new Date()})
|
|
167
|
+
${message.toString()}`)
|
|
168
|
+
);
|
|
169
|
+
const tlsWrite = this.client.write.bind(this.client);
|
|
170
|
+
this.client.write = (message) => {
|
|
171
|
+
console.log(`Sending...(${/* @__PURE__ */ new Date()})
|
|
172
|
+
${message}`);
|
|
173
|
+
return tlsWrite(message);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
revoke() {
|
|
177
|
+
clearInterval(this.intervalHandle);
|
|
178
|
+
this.removeAllListeners();
|
|
179
|
+
this.client.removeAllListeners();
|
|
180
|
+
this.client.destroy();
|
|
181
|
+
}
|
|
182
|
+
send(message, waitForReply = false) {
|
|
183
|
+
this.client.write(message.toString());
|
|
184
|
+
if (!waitForReply) {
|
|
185
|
+
return new Promise((resolve) => {
|
|
186
|
+
resolve(void 0);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return new Promise((resolve) => {
|
|
190
|
+
const messageListerner = (inboundMessage) => {
|
|
191
|
+
if (inboundMessage.headers.CSeq.trim().split(/\s+/)[0] !== message.headers.CSeq.trim().split(/\s+/)[0]) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (inboundMessage.subject.startsWith("SIP/2.0 100 ")) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.off("message", messageListerner);
|
|
198
|
+
resolve(inboundMessage);
|
|
199
|
+
};
|
|
200
|
+
this.on("message", messageListerner);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
async answer(inviteMessage) {
|
|
204
|
+
const inboundCallSession = new import_inbound.default(this, inviteMessage);
|
|
205
|
+
await inboundCallSession.answer();
|
|
206
|
+
return inboundCallSession;
|
|
207
|
+
}
|
|
208
|
+
// decline an inbound call
|
|
209
|
+
async decline(inviteMessage) {
|
|
210
|
+
const newMessage = new import_sip_message.ResponseMessage(inviteMessage, 603);
|
|
211
|
+
await this.send(newMessage);
|
|
212
|
+
}
|
|
213
|
+
async call(callee) {
|
|
214
|
+
const offerSDP = `
|
|
215
|
+
v=0
|
|
216
|
+
o=- ${Date.now()} 0 IN IP4 ${this.client.localAddress}
|
|
217
|
+
s=rc-softphone-ts
|
|
218
|
+
c=IN IP4 ${this.client.localAddress}
|
|
219
|
+
t=0 0
|
|
220
|
+
m=audio ${(0, import_utils.randomInt)()} RTP/SAVP ${this.codec.id} 101
|
|
221
|
+
a=rtpmap:${this.codec.id} ${this.codec.name}
|
|
222
|
+
a=rtpmap:101 telephone-event/8000
|
|
223
|
+
a=fmtp:101 0-15
|
|
224
|
+
a=sendrecv
|
|
225
|
+
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:${import_utils.localKey}
|
|
226
|
+
`.trim();
|
|
227
|
+
const inviteMessage = new import_sip_message.RequestMessage(
|
|
228
|
+
`INVITE sip:${callee}@${this.sipInfo.domain} SIP/2.0`,
|
|
229
|
+
{
|
|
230
|
+
Via: `SIP/2.0/TLS ${this.client.localAddress}:${this.client.localPort};rport;branch=${(0, import_utils.branch)()};alias`,
|
|
231
|
+
"Max-Forwards": 70,
|
|
232
|
+
From: `<sip:${this.sipInfo.username}@${this.sipInfo.domain}>;tag=${(0, import_utils.uuid)()}`,
|
|
233
|
+
To: `<sip:${callee}@sip.ringcentral.com>`,
|
|
234
|
+
Contact: ` <sip:${this.sipInfo.username}@${this.client.localAddress}:${this.client.localPort};transport=TLS;ob>`,
|
|
235
|
+
"Call-ID": (0, import_utils.uuid)(),
|
|
236
|
+
Route: `<sip:${this.sipInfo.outboundProxy};transport=tls;lr>`,
|
|
237
|
+
Allow: `PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS`,
|
|
238
|
+
Supported: `replaces, 100rel, timer, norefersub`,
|
|
239
|
+
"Session-Expires": 1800,
|
|
240
|
+
"Min-SE": 90,
|
|
241
|
+
"Content-Type": "application/sdp"
|
|
242
|
+
},
|
|
243
|
+
offerSDP
|
|
244
|
+
);
|
|
245
|
+
const inboundMessage = await this.send(inviteMessage, true);
|
|
246
|
+
const proxyAuthenticate = inboundMessage.getHeader("Proxy-Authenticate");
|
|
247
|
+
const nonce = proxyAuthenticate.match(/, nonce="(.+?)"/)[1];
|
|
248
|
+
const newMessage = inviteMessage.fork();
|
|
249
|
+
newMessage.headers["Proxy-Authorization"] = (0, import_utils.generateAuthorization)(
|
|
250
|
+
this.sipInfo,
|
|
251
|
+
nonce,
|
|
252
|
+
"INVITE"
|
|
253
|
+
);
|
|
254
|
+
const progressMessage = await this.send(newMessage, true);
|
|
255
|
+
const outboundCallSession = new import_outbound.default(this, progressMessage);
|
|
256
|
+
outboundCallSession.sdp = offerSDP;
|
|
257
|
+
return outboundCallSession;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
var index_default = Softphone;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import EventEmitter from "node:events";
|
|
2
|
-
import { TLSSocket } from "node:tls";
|
|
2
|
+
import { type TLSSocket } from "node:tls";
|
|
3
3
|
import InboundCallSession from "./call-session/inbound.js";
|
|
4
4
|
import OutboundCallSession from "./call-session/outbound.js";
|
|
5
|
-
import { InboundMessage, OutboundMessage } from "./sip-message/index.js";
|
|
6
|
-
import { SoftPhoneOptions } from "./types.js";
|
|
7
5
|
import Codec from "./codec.js";
|
|
6
|
+
import { InboundMessage, OutboundMessage } from "./sip-message/index.js";
|
|
7
|
+
import type { SoftPhoneOptions } from "./types.js";
|
|
8
8
|
declare class Softphone extends EventEmitter {
|
|
9
9
|
sipInfo: SoftPhoneOptions;
|
|
10
10
|
client: TLSSocket;
|