ringcentral-softphone 1.3.4 → 1.3.6

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 (118) hide show
  1. package/dist/call-session/inbound.cjs +41 -83
  2. package/dist/call-session/inbound.d.cts +2 -0
  3. package/dist/call-session/inbound.d.mts +2 -0
  4. package/dist/call-session/inbound.mjs +51 -0
  5. package/dist/call-session/index.cjs +212 -273
  6. package/dist/call-session/index.d.cts +2 -0
  7. package/dist/call-session/index.d.mts +2 -0
  8. package/dist/call-session/index.mjs +209 -0
  9. package/dist/call-session/outbound.cjs +56 -99
  10. package/dist/call-session/outbound.d.cts +2 -0
  11. package/dist/call-session/outbound.d.mts +2 -0
  12. package/dist/call-session/outbound.mjs +57 -0
  13. package/dist/call-session/streamer.cjs +66 -111
  14. package/dist/call-session/streamer.d.cts +2 -0
  15. package/dist/call-session/streamer.d.mts +2 -0
  16. package/dist/call-session/streamer.mjs +65 -0
  17. package/dist/chunk-CKQMccvm.cjs +28 -0
  18. package/dist/codec-Bh7v8J-S.d.mts +18 -0
  19. package/dist/codec-C-VrtVkq.d.cts +18 -0
  20. package/dist/codec.cjs +68 -84
  21. package/dist/codec.d.cts +2 -0
  22. package/dist/codec.d.mts +2 -0
  23. package/dist/codec.mjs +68 -0
  24. package/dist/dtmf-B13Fz2VR.d.mts +10 -0
  25. package/dist/dtmf-DcQ-5vSG.d.cts +10 -0
  26. package/dist/dtmf.cjs +37 -60
  27. package/dist/dtmf.d.cts +2 -0
  28. package/dist/dtmf.d.mts +2 -0
  29. package/dist/dtmf.mjs +42 -0
  30. package/dist/inbound--wGoGqLS.d.mts +103 -0
  31. package/dist/inbound-DquvTSj1.d.cts +103 -0
  32. package/dist/index--UjWgLK-.d.mts +8 -0
  33. package/dist/index-BhN2W8AV.d.mts +8 -0
  34. package/dist/index-CEgs-Dz2.d.cts +1 -0
  35. package/dist/index-Cf2Cev52.d.cts +8 -0
  36. package/dist/index-XMDop59x.d.cts +8 -0
  37. package/dist/index-q_LXL61M.d.mts +1 -0
  38. package/dist/index.cjs +166 -250
  39. package/dist/index.d.cts +2 -0
  40. package/dist/index.d.mts +2 -0
  41. package/dist/index.mjs +172 -0
  42. package/dist/request-B_auLSJn.d.cts +10 -0
  43. package/dist/request-pBe7_mYv.d.mts +10 -0
  44. package/dist/response-LRRpY8lX.d.mts +9 -0
  45. package/dist/response-ReKvb5x9.d.cts +9 -0
  46. package/dist/sip-message/inbound/index.cjs +16 -50
  47. package/dist/sip-message/inbound/index.d.cts +2 -0
  48. package/dist/sip-message/inbound/index.d.mts +2 -0
  49. package/dist/sip-message/inbound/index.mjs +17 -0
  50. package/dist/sip-message/index.cjs +11 -49
  51. package/dist/sip-message/index.d.cts +6 -0
  52. package/dist/sip-message/index.d.mts +6 -0
  53. package/dist/sip-message/index.mjs +6 -0
  54. package/dist/sip-message/outbound/index.cjs +10 -40
  55. package/dist/sip-message/outbound/index.d.cts +2 -0
  56. package/dist/sip-message/outbound/index.d.mts +2 -0
  57. package/dist/sip-message/outbound/index.mjs +11 -0
  58. package/dist/sip-message/outbound/request.cjs +20 -61
  59. package/dist/sip-message/outbound/request.d.cts +2 -0
  60. package/dist/sip-message/outbound/request.d.mts +2 -0
  61. package/dist/sip-message/outbound/request.mjs +21 -0
  62. package/dist/sip-message/outbound/response.cjs +25 -54
  63. package/dist/sip-message/outbound/response.d.cts +2 -0
  64. package/dist/sip-message/outbound/response.d.mts +2 -0
  65. package/dist/sip-message/outbound/response.mjs +26 -0
  66. package/dist/sip-message/response-codes.cjs +80 -100
  67. package/dist/sip-message/response-codes.d.cts +5 -0
  68. package/dist/sip-message/response-codes.d.mts +6 -0
  69. package/dist/sip-message/response-codes.mjs +82 -0
  70. package/dist/sip-message/sip-message.cjs +25 -52
  71. package/dist/sip-message/sip-message.d.cts +2 -0
  72. package/dist/sip-message/sip-message.d.mts +2 -0
  73. package/dist/sip-message/sip-message.mjs +26 -0
  74. package/dist/sip-message-B2D5MPBI.d.cts +13 -0
  75. package/dist/sip-message-PaPho4qU.d.mts +13 -0
  76. package/dist/types-DOQ9wmX6.d.mts +12 -0
  77. package/dist/types-DZxCsbZE.d.cts +12 -0
  78. package/dist/types.cjs +0 -15
  79. package/dist/types.d.cts +2 -0
  80. package/dist/types.d.mts +2 -0
  81. package/dist/types.mjs +1 -0
  82. package/dist/utils.cjs +27 -73
  83. package/dist/utils.d.cts +12 -0
  84. package/dist/utils.d.mts +12 -0
  85. package/dist/utils.mjs +25 -0
  86. package/package.json +14 -14
  87. package/dist/call-session/inbound.d.ts +0 -8
  88. package/dist/call-session/inbound.js +0 -64
  89. package/dist/call-session/index.d.ts +0 -46
  90. package/dist/call-session/index.js +0 -248
  91. package/dist/call-session/outbound.d.ts +0 -11
  92. package/dist/call-session/outbound.js +0 -71
  93. package/dist/call-session/streamer.d.ts +0 -17
  94. package/dist/call-session/streamer.js +0 -83
  95. package/dist/codec.d.ts +0 -15
  96. package/dist/codec.js +0 -66
  97. package/dist/dtmf.d.ts +0 -7
  98. package/dist/dtmf.js +0 -47
  99. package/dist/index.d.ts +0 -28
  100. package/dist/index.js +0 -242
  101. package/dist/sip-message/inbound/index.d.ts +0 -5
  102. package/dist/sip-message/inbound/index.js +0 -22
  103. package/dist/sip-message/index.d.ts +0 -5
  104. package/dist/sip-message/index.js +0 -12
  105. package/dist/sip-message/outbound/index.d.ts +0 -5
  106. package/dist/sip-message/outbound/index.js +0 -12
  107. package/dist/sip-message/outbound/request.d.ts +0 -7
  108. package/dist/sip-message/outbound/request.js +0 -33
  109. package/dist/sip-message/outbound/response.d.ts +0 -6
  110. package/dist/sip-message/outbound/response.js +0 -26
  111. package/dist/sip-message/response-codes.d.ts +0 -4
  112. package/dist/sip-message/response-codes.js +0 -83
  113. package/dist/sip-message/sip-message.d.ts +0 -11
  114. package/dist/sip-message/sip-message.js +0 -34
  115. package/dist/types.d.ts +0 -9
  116. package/dist/types.js +0 -0
  117. package/dist/utils.d.ts +0 -8
  118. package/dist/utils.js +0 -41
@@ -0,0 +1,103 @@
1
+ import { t as InboundMessage } from "./index-Cf2Cev52.cjs";
2
+ import { t as OutboundMessage } from "./index-XMDop59x.cjs";
3
+ import { t as DTMF } from "./dtmf-DcQ-5vSG.cjs";
4
+ import { t as Codec } from "./codec-C-VrtVkq.cjs";
5
+ import { t as SoftPhoneOptions } from "./types-DZxCsbZE.cjs";
6
+ import EventEmitter from "node:events";
7
+ import { TLSSocket } from "node:tls";
8
+ import { Buffer } from "node:buffer";
9
+ import dgram from "node:dgram";
10
+ import { RtpPacket, SrtpSession } from "werift-rtp";
11
+
12
+ //#region src/call-session/streamer.d.ts
13
+ declare class Streamer extends EventEmitter {
14
+ paused: boolean;
15
+ private callSession;
16
+ private buffer;
17
+ private originalBuffer;
18
+ constructor(callSession: CallSession, buffer: Buffer);
19
+ start(): void;
20
+ stop(): void;
21
+ pause(): void;
22
+ resume(): void;
23
+ get finished(): boolean;
24
+ private sendPacket;
25
+ }
26
+ //#endregion
27
+ //#region src/call-session/index.d.ts
28
+ type DtmfChar = (typeof DTMF.phoneChars)[number];
29
+ declare abstract class CallSession extends EventEmitter {
30
+ softphone: Softphone;
31
+ sipMessage: InboundMessage;
32
+ socket: dgram.Socket;
33
+ localPeer: string;
34
+ remotePeer: string;
35
+ remoteIP: string;
36
+ remotePort: number;
37
+ disposed: boolean;
38
+ srtpSession: SrtpSession;
39
+ encoder: {
40
+ encode: (pcm: Buffer) => Buffer;
41
+ };
42
+ decoder: {
43
+ decode: (audio: Buffer) => Buffer;
44
+ };
45
+ sdp: string;
46
+ ssrc: number;
47
+ sequenceNumber: number;
48
+ timestamp: number;
49
+ constructor(softphone: Softphone, sipMessage: InboundMessage);
50
+ set remoteKey(key: string);
51
+ get callId(): string | undefined;
52
+ send(data: string | Buffer): void;
53
+ hangup(): Promise<void>;
54
+ sendDTMF(char: DtmfChar): void;
55
+ sendDTMFs(s: string, delay?: number): Promise<void>;
56
+ streamAudio(input: Buffer): Streamer;
57
+ sendPacket(rtpPacket: RtpPacket): void;
58
+ protected startLocalServices(): void;
59
+ protected dispose(): void;
60
+ transfer(transferTo: string): Promise<void>;
61
+ toggleReceive(toReceive: boolean): Promise<void>;
62
+ hold(): Promise<void>;
63
+ unhold(): Promise<void>;
64
+ }
65
+ //#endregion
66
+ //#region src/call-session/outbound.d.ts
67
+ declare class OutboundCallSession extends CallSession {
68
+ constructor(softphone: Softphone, answerMessage: InboundMessage);
69
+ init(): void;
70
+ cancel(): Promise<void>;
71
+ get sessionId(): string;
72
+ get partyId(): string;
73
+ }
74
+ //#endregion
75
+ //#region src/index.d.ts
76
+ declare class Softphone extends EventEmitter {
77
+ sipInfo: SoftPhoneOptions;
78
+ client: TLSSocket;
79
+ codec: Codec;
80
+ fakeDomain: string;
81
+ fakeEmail: string;
82
+ private intervalHandle?;
83
+ private connected;
84
+ constructor(sipInfo: SoftPhoneOptions);
85
+ private instanceId;
86
+ private registerCallId;
87
+ register(): Promise<void>;
88
+ enableDebugMode(): void;
89
+ revoke(): void;
90
+ send(message: OutboundMessage, waitForReply?: true): Promise<InboundMessage>;
91
+ send(message: OutboundMessage, waitForReply?: false): Promise<undefined>;
92
+ answer(inviteMessage: InboundMessage): Promise<InboundCallSession>;
93
+ decline(inviteMessage: InboundMessage): Promise<void>;
94
+ call(callee: string): Promise<OutboundCallSession>;
95
+ }
96
+ //#endregion
97
+ //#region src/call-session/inbound.d.ts
98
+ declare class InboundCallSession extends CallSession {
99
+ constructor(softphone: Softphone, inviteMessage: InboundMessage);
100
+ answer(): Promise<void>;
101
+ }
102
+ //#endregion
103
+ export { Streamer as a, CallSession as i, Softphone as n, OutboundCallSession as r, InboundCallSession as t };
@@ -0,0 +1,8 @@
1
+ import { t as SipMessage } from "./sip-message-PaPho4qU.mjs";
2
+
3
+ //#region src/sip-message/outbound/index.d.ts
4
+ declare class OutboundMessage extends SipMessage {
5
+ constructor(subject?: string, headers?: {}, body?: string);
6
+ }
7
+ //#endregion
8
+ export { OutboundMessage as t };
@@ -0,0 +1,8 @@
1
+ import { t as SipMessage } from "./sip-message-PaPho4qU.mjs";
2
+
3
+ //#region src/sip-message/inbound/index.d.ts
4
+ declare class InboundMessage extends SipMessage {
5
+ static fromString(str: string): SipMessage;
6
+ }
7
+ //#endregion
8
+ export { InboundMessage as t };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,8 @@
1
+ import { t as SipMessage } from "./sip-message-B2D5MPBI.cjs";
2
+
3
+ //#region src/sip-message/inbound/index.d.ts
4
+ declare class InboundMessage extends SipMessage {
5
+ static fromString(str: string): SipMessage;
6
+ }
7
+ //#endregion
8
+ export { InboundMessage as t };
@@ -0,0 +1,8 @@
1
+ import { t as SipMessage } from "./sip-message-B2D5MPBI.cjs";
2
+
3
+ //#region src/sip-message/outbound/index.d.ts
4
+ declare class OutboundMessage extends SipMessage {
5
+ constructor(subject?: string, headers?: {}, body?: string);
6
+ }
7
+ //#endregion
8
+ export { OutboundMessage as t };
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.cjs CHANGED
@@ -1,260 +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().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 = `
1
+ const require_chunk = require("./chunk-CKQMccvm.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_chunk.__toESM(node_events, 1);
13
+ let node_tls = require("node:tls");
14
+ node_tls = require_chunk.__toESM(node_tls, 1);
15
+ let wait_for_async = require("wait-for-async");
16
+ wait_for_async = require_chunk.__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 = `
215
140
  v=0
216
141
  o=- ${Date.now()} 0 IN IP4 ${this.client.localAddress}
217
142
  s=rc-softphone-ts
218
143
  c=IN IP4 ${this.client.localAddress}
219
144
  t=0 0
220
- m=audio ${(0, import_utils.randomInt)()} RTP/SAVP ${this.codec.id} 101
145
+ m=audio ${require_utils.randomInt()} RTP/SAVP ${this.codec.id} 101
221
146
  a=rtpmap:${this.codec.id} ${this.codec.name}
222
147
  a=rtpmap:101 telephone-event/8000
223
148
  a=fmtp:101 0-15
224
149
  a=sendrecv
225
- 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}
226
151
  `.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;
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,2 @@
1
+ import { n as Softphone } from "./inbound-DquvTSj1.cjs";
2
+ export = Softphone;
@@ -0,0 +1,2 @@
1
+ import { n as Softphone } from "./inbound--wGoGqLS.mjs";
2
+ export { Softphone as default };