ringcentral-softphone 1.3.3 → 1.3.5

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