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
@@ -1,244 +1,209 @@
1
+ import DTMF from "../dtmf.js";
2
+ import { branch, extractAddress, localKey, randomInt } from "../utils.js";
3
+ import RequestMessage from "../sip-message/outbound/request.js";
4
+ import ResponseMessage from "../sip-message/outbound/response.js";
5
+ import "../sip-message/index.js";
6
+ import Streamer from "./streamer.js";
1
7
  import { Buffer } from "node:buffer";
2
- import dgram from "node:dgram";
3
8
  import EventEmitter from "node:events";
4
9
  import waitFor from "wait-for-async";
10
+ import dgram from "node:dgram";
5
11
  import { RtpHeader, RtpPacket, SrtpSession } from "werift-rtp";
6
- import DTMF from "../dtmf.js";
7
- import {
8
- RequestMessage,
9
- ResponseMessage
10
- } from "../sip-message/index.js";
11
- import { branch, extractAddress, localKey, randomInt } from "../utils.js";
12
- import Streamer from "./streamer.js";
13
- class CallSession extends EventEmitter {
14
- softphone;
15
- sipMessage;
16
- socket;
17
- localPeer;
18
- remotePeer;
19
- remoteIP;
20
- remotePort;
21
- disposed = false;
22
- srtpSession;
23
- encoder;
24
- decoder;
25
- sdp;
26
- // for audio streaming
27
- ssrc = randomInt();
28
- sequenceNumber = randomInt();
29
- timestamp = randomInt();
30
- constructor(softphone, sipMessage) {
31
- super();
32
- this.softphone = softphone;
33
- this.encoder = softphone.codec.createEncoder();
34
- this.decoder = softphone.codec.createDecoder();
35
- this.sipMessage = sipMessage;
36
- if (this.sipMessage.body.length > 0) {
37
- this.remoteIP = this.sipMessage.body.match(/c=IN IP4 ([\d.]+)/)[1];
38
- this.remotePort = parseInt(
39
- this.sipMessage.body.match(/m=audio (\d+) /)[1],
40
- 10
41
- );
42
- }
43
- }
44
- set remoteKey(key) {
45
- const localKeyBuffer = Buffer.from(localKey, "base64");
46
- const remoteKeyBuffer = Buffer.from(key, "base64");
47
- this.srtpSession = new SrtpSession({
48
- profile: 1,
49
- keys: {
50
- localMasterKey: localKeyBuffer.subarray(0, 16),
51
- localMasterSalt: localKeyBuffer.subarray(16, 30),
52
- remoteMasterKey: remoteKeyBuffer.subarray(0, 16),
53
- remoteMasterSalt: remoteKeyBuffer.subarray(16, 30)
54
- }
55
- });
56
- }
57
- get callId() {
58
- return this.sipMessage.getHeader("Call-ID");
59
- }
60
- send(data) {
61
- this.socket.send(data, this.remotePort, this.remoteIP);
62
- }
63
- async hangup() {
64
- const requestMessage = new RequestMessage(
65
- `BYE sip:${this.softphone.sipInfo.domain} SIP/2.0`,
66
- {
67
- "Call-ID": this.callId,
68
- From: this.localPeer,
69
- To: this.remotePeer,
70
- Via: `SIP/2.0/TLS ${this.softphone.fakeDomain};branch=${branch()}`
71
- }
72
- );
73
- await this.softphone.send(requestMessage);
74
- }
75
- sendDTMF(char) {
76
- const payloads = DTMF.charToPayloads(char);
77
- const timestamp = this.timestamp;
78
- let first = true;
79
- for (const payload of payloads) {
80
- const rtpHeader = new RtpHeader({
81
- version: 2,
82
- padding: false,
83
- paddingSize: 0,
84
- extension: false,
85
- marker: first,
86
- payloadOffset: 12,
87
- payloadType: 101,
88
- sequenceNumber: this.sequenceNumber,
89
- timestamp,
90
- ssrc: this.ssrc,
91
- csrcLength: 0,
92
- csrc: [],
93
- extensionProfile: 48862,
94
- extensionLength: void 0,
95
- extensions: []
96
- });
97
- const rtpPacket = new RtpPacket(rtpHeader, payload);
98
- this.send(this.srtpSession.encrypt(rtpPacket.payload, rtpPacket.header));
99
- this.sequenceNumber = (this.sequenceNumber + 1) % 65536;
100
- first = false;
101
- }
102
- this.timestamp += 800;
103
- }
104
- async sendDTMFs(s, delay = 500) {
105
- for (const c of s) {
106
- this.sendDTMF(c);
107
- await waitFor({ interval: delay });
108
- }
109
- }
110
- // buffer is the content of a audio file, it is supposed to be uncompressed PCM data
111
- // The audio should be playable by command: play -t raw -b 16 -r 16000 -e signed-integer test.wav
112
- streamAudio(input) {
113
- const streamer = new Streamer(this, input);
114
- streamer.start();
115
- return streamer;
116
- }
117
- // send a single rtp packet
118
- sendPacket(rtpPacket) {
119
- if (this.disposed) {
120
- return;
121
- }
122
- this.send(this.srtpSession.encrypt(rtpPacket.payload, rtpPacket.header));
123
- }
124
- startLocalServices() {
125
- this.socket = dgram.createSocket("udp4");
126
- this.socket.on("message", (message) => {
127
- const rtpPacket = RtpPacket.deSerialize(
128
- this.srtpSession.decrypt(message)
129
- );
130
- this.emit("rtpPacket", rtpPacket);
131
- if (rtpPacket.header.payloadType === 101) {
132
- this.emit("dtmfPacket", rtpPacket);
133
- const char = DTMF.payloadToChar(rtpPacket.payload);
134
- if (char) {
135
- this.emit("dtmf", char);
136
- }
137
- } else if (rtpPacket.header.payloadType === this.softphone.codec.id) {
138
- 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) {
139
- return;
140
- }
141
- try {
142
- rtpPacket.payload = this.decoder.decode(rtpPacket.payload);
143
- this.emit("audioPacket", rtpPacket);
144
- } catch {
145
- console.error("Audio packet decode failed", rtpPacket);
146
- }
147
- }
148
- });
149
- this.socket.bind();
150
- this.send("hello");
151
- const byeHandler = (inboundMessage) => {
152
- if (inboundMessage.getHeader("Call-ID") !== this.callId) {
153
- return;
154
- }
155
- if (inboundMessage.headers.CSeq.endsWith(" BYE")) {
156
- this.softphone.off("message", byeHandler);
157
- this.dispose();
158
- }
159
- };
160
- this.softphone.on("message", byeHandler);
161
- }
162
- dispose() {
163
- this.disposed = true;
164
- this.emit("disposed");
165
- this.removeAllListeners();
166
- this.socket?.removeAllListeners();
167
- this.socket?.close();
168
- }
169
- async transfer(transferTo) {
170
- const requestMessage = new RequestMessage(
171
- `REFER sip:${this.softphone.sipInfo.username}@${this.softphone.sipInfo.outboundProxy};transport=tls SIP/2.0`,
172
- {
173
- Via: `SIP/2.0/TLS ${this.softphone.client.localAddress}:${this.softphone.client.localPort};rport;branch=${branch()};alias`,
174
- "Max-Forwards": 70,
175
- From: this.localPeer,
176
- To: this.remotePeer,
177
- Contact: `<sip:${this.softphone.sipInfo.username}@${this.softphone.client.localAddress}:${this.softphone.client.localPort};transport=TLS;ob>`,
178
- "Call-ID": this.callId,
179
- Event: "refer",
180
- Expires: 600,
181
- Supported: "replaces, 100rel, timer, norefersub",
182
- Accept: "message/sipfrag;version=2.0",
183
- "Allow-Events": "presence, message-summary, refer",
184
- "Refer-To": `sip:${transferTo}@${this.softphone.sipInfo.domain}`,
185
- "Referred-By": `<sip:${this.softphone.sipInfo.username}@${this.softphone.sipInfo.domain}>`
186
- }
187
- );
188
- await this.softphone.send(requestMessage);
189
- return new Promise((resolve) => {
190
- const notifyHandler = (inboundMessage) => {
191
- if (!inboundMessage.subject.startsWith("NOTIFY ")) {
192
- return;
193
- }
194
- const responseMessage = new ResponseMessage(inboundMessage, 200);
195
- this.softphone.send(responseMessage);
196
- if (inboundMessage.body.trim() === "SIP/2.0 200 OK") {
197
- this.softphone.off("message", notifyHandler);
198
- resolve();
199
- }
200
- };
201
- this.softphone.on("message", notifyHandler);
202
- });
203
- }
204
- async toggleReceive(toReceive) {
205
- let newSDP = this.sdp;
206
- if (!toReceive) {
207
- newSDP = newSDP.replace(/a=sendrecv/, "a=sendonly");
208
- }
209
- const requestMessage = new RequestMessage(
210
- `INVITE ${extractAddress(this.remotePeer)} SIP/2.0`,
211
- {
212
- "Call-Id": this.callId,
213
- From: this.localPeer,
214
- To: this.remotePeer,
215
- Via: `SIP/2.0/TLS ${this.softphone.client.localAddress}:${this.softphone.client.localPort};rport;branch=${branch()};alias`,
216
- "Content-Type": "application/sdp",
217
- Contact: ` <sip:${this.softphone.sipInfo.username}@${this.softphone.client.localAddress}:${this.softphone.client.localPort};transport=TLS;ob>`
218
- },
219
- newSDP
220
- );
221
- const replyMessage = await this.softphone.send(requestMessage, true);
222
- const ackMessage = new RequestMessage(
223
- `ACK ${extractAddress(this.remotePeer)} SIP/2.0`,
224
- {
225
- "Call-Id": this.callId,
226
- From: this.localPeer,
227
- To: this.remotePeer,
228
- Via: replyMessage.headers.Via,
229
- CSeq: replyMessage.headers.CSeq.replace(" INVITE", " ACK")
230
- }
231
- );
232
- await this.softphone.send(ackMessage);
233
- }
234
- async hold() {
235
- return this.toggleReceive(false);
236
- }
237
- async unhold() {
238
- return this.toggleReceive(true);
239
- }
240
- }
241
- var call_session_default = CallSession;
242
- export {
243
- call_session_default as default
12
+ //#region src/call-session/index.ts
13
+ const isDtmfChar = (value) => DTMF.phoneChars.includes(value);
14
+ var CallSession = class extends EventEmitter {
15
+ softphone;
16
+ sipMessage;
17
+ socket;
18
+ localPeer;
19
+ remotePeer;
20
+ remoteIP;
21
+ remotePort;
22
+ disposed = false;
23
+ srtpSession;
24
+ encoder;
25
+ decoder;
26
+ sdp;
27
+ ssrc = randomInt();
28
+ sequenceNumber = randomInt();
29
+ timestamp = randomInt();
30
+ constructor(softphone, sipMessage) {
31
+ super();
32
+ this.softphone = softphone;
33
+ this.encoder = softphone.codec.createEncoder();
34
+ this.decoder = softphone.codec.createDecoder();
35
+ this.sipMessage = sipMessage;
36
+ if (this.sipMessage.body.length > 0) {
37
+ this.remoteIP = this.sipMessage.body.match(/c=IN IP4 ([\d.]+)/)[1];
38
+ this.remotePort = parseInt(this.sipMessage.body.match(/m=audio (\d+) /)[1], 10);
39
+ }
40
+ }
41
+ set remoteKey(key) {
42
+ const localKeyBuffer = Buffer.from(localKey, "base64");
43
+ const remoteKeyBuffer = Buffer.from(key, "base64");
44
+ this.srtpSession = new SrtpSession({
45
+ profile: 1,
46
+ keys: {
47
+ localMasterKey: localKeyBuffer.subarray(0, 16),
48
+ localMasterSalt: localKeyBuffer.subarray(16, 30),
49
+ remoteMasterKey: remoteKeyBuffer.subarray(0, 16),
50
+ remoteMasterSalt: remoteKeyBuffer.subarray(16, 30)
51
+ }
52
+ });
53
+ }
54
+ get callId() {
55
+ return this.sipMessage.getHeader("Call-ID");
56
+ }
57
+ send(data) {
58
+ this.socket.send(data, this.remotePort, this.remoteIP);
59
+ }
60
+ async hangup() {
61
+ const requestMessage = new RequestMessage(`BYE sip:${this.softphone.sipInfo.domain} SIP/2.0`, {
62
+ "Call-ID": this.callId,
63
+ From: this.localPeer,
64
+ To: this.remotePeer,
65
+ Via: `SIP/2.0/TLS ${this.softphone.fakeDomain};branch=${branch()}`
66
+ });
67
+ await this.softphone.send(requestMessage);
68
+ }
69
+ sendDTMF(char) {
70
+ const payloads = DTMF.charToPayloads(char);
71
+ const timestamp = this.timestamp;
72
+ let first = true;
73
+ for (const payload of payloads) {
74
+ const rtpPacket = new RtpPacket(new RtpHeader({
75
+ version: 2,
76
+ padding: false,
77
+ paddingSize: 0,
78
+ extension: false,
79
+ marker: first,
80
+ payloadOffset: 12,
81
+ payloadType: 101,
82
+ sequenceNumber: this.sequenceNumber,
83
+ timestamp,
84
+ ssrc: this.ssrc,
85
+ csrcLength: 0,
86
+ csrc: [],
87
+ extensionProfile: 48862,
88
+ extensionLength: void 0,
89
+ extensions: []
90
+ }), payload);
91
+ this.send(this.srtpSession.encrypt(rtpPacket.payload, rtpPacket.header));
92
+ this.sequenceNumber = (this.sequenceNumber + 1) % 65536;
93
+ first = false;
94
+ }
95
+ this.timestamp += 800;
96
+ }
97
+ async sendDTMFs(s, delay = 500) {
98
+ for (const c of s) {
99
+ if (!isDtmfChar(c)) throw new Error(`invalid phone char: ${c}`);
100
+ this.sendDTMF(c);
101
+ await waitFor({ interval: delay });
102
+ }
103
+ }
104
+ streamAudio(input) {
105
+ const streamer = new Streamer(this, input);
106
+ streamer.start();
107
+ return streamer;
108
+ }
109
+ sendPacket(rtpPacket) {
110
+ if (this.disposed) return;
111
+ this.send(this.srtpSession.encrypt(rtpPacket.payload, rtpPacket.header));
112
+ }
113
+ startLocalServices() {
114
+ this.socket = dgram.createSocket("udp4");
115
+ this.socket.on("message", (message) => {
116
+ const rtpPacket = RtpPacket.deSerialize(this.srtpSession.decrypt(message));
117
+ this.emit("rtpPacket", rtpPacket);
118
+ if (rtpPacket.header.payloadType === 101) {
119
+ this.emit("dtmfPacket", rtpPacket);
120
+ const char = DTMF.payloadToChar(rtpPacket.payload);
121
+ if (char) this.emit("dtmf", char);
122
+ } else if (rtpPacket.header.payloadType === this.softphone.codec.id) {
123
+ 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) return;
124
+ try {
125
+ rtpPacket.payload = this.decoder.decode(rtpPacket.payload);
126
+ this.emit("audioPacket", rtpPacket);
127
+ } catch {
128
+ console.error("Audio packet decode failed", rtpPacket);
129
+ }
130
+ }
131
+ });
132
+ this.socket.bind();
133
+ this.send("hello");
134
+ const byeHandler = (inboundMessage) => {
135
+ if (inboundMessage.getHeader("Call-ID") !== this.callId) return;
136
+ if (inboundMessage.headers.CSeq.endsWith(" BYE")) {
137
+ this.softphone.off("message", byeHandler);
138
+ this.dispose();
139
+ }
140
+ };
141
+ this.softphone.on("message", byeHandler);
142
+ }
143
+ dispose() {
144
+ this.disposed = true;
145
+ this.emit("disposed");
146
+ this.removeAllListeners();
147
+ this.socket?.removeAllListeners();
148
+ this.socket?.close();
149
+ }
150
+ async transfer(transferTo) {
151
+ const requestMessage = new RequestMessage(`REFER sip:${this.softphone.sipInfo.username}@${this.softphone.sipInfo.outboundProxy};transport=tls SIP/2.0`, {
152
+ Via: `SIP/2.0/TLS ${this.softphone.client.localAddress}:${this.softphone.client.localPort};rport;branch=${branch()};alias`,
153
+ "Max-Forwards": 70,
154
+ From: this.localPeer,
155
+ To: this.remotePeer,
156
+ Contact: `<sip:${this.softphone.sipInfo.username}@${this.softphone.client.localAddress}:${this.softphone.client.localPort};transport=TLS;ob>`,
157
+ "Call-ID": this.callId,
158
+ Event: "refer",
159
+ Expires: 600,
160
+ Supported: "replaces, 100rel, timer, norefersub",
161
+ Accept: "message/sipfrag;version=2.0",
162
+ "Allow-Events": "presence, message-summary, refer",
163
+ "Refer-To": `sip:${transferTo}@${this.softphone.sipInfo.domain}`,
164
+ "Referred-By": `<sip:${this.softphone.sipInfo.username}@${this.softphone.sipInfo.domain}>`
165
+ });
166
+ await this.softphone.send(requestMessage);
167
+ return new Promise((resolve) => {
168
+ const notifyHandler = (inboundMessage) => {
169
+ if (!inboundMessage.subject.startsWith("NOTIFY ")) return;
170
+ const responseMessage = new ResponseMessage(inboundMessage, 200);
171
+ this.softphone.send(responseMessage);
172
+ if (inboundMessage.body.trim() === "SIP/2.0 200 OK") {
173
+ this.softphone.off("message", notifyHandler);
174
+ resolve();
175
+ }
176
+ };
177
+ this.softphone.on("message", notifyHandler);
178
+ });
179
+ }
180
+ async toggleReceive(toReceive) {
181
+ let newSDP = this.sdp;
182
+ if (!toReceive) newSDP = newSDP.replace(/a=sendrecv/, "a=sendonly");
183
+ const requestMessage = new RequestMessage(`INVITE ${extractAddress(this.remotePeer)} SIP/2.0`, {
184
+ "Call-Id": this.callId,
185
+ From: this.localPeer,
186
+ To: this.remotePeer,
187
+ Via: `SIP/2.0/TLS ${this.softphone.client.localAddress}:${this.softphone.client.localPort};rport;branch=${branch()};alias`,
188
+ "Content-Type": "application/sdp",
189
+ Contact: ` <sip:${this.softphone.sipInfo.username}@${this.softphone.client.localAddress}:${this.softphone.client.localPort};transport=TLS;ob>`
190
+ }, newSDP);
191
+ const replyMessage = await this.softphone.send(requestMessage, true);
192
+ const ackMessage = new RequestMessage(`ACK ${extractAddress(this.remotePeer)} SIP/2.0`, {
193
+ "Call-Id": this.callId,
194
+ From: this.localPeer,
195
+ To: this.remotePeer,
196
+ Via: replyMessage.headers.Via,
197
+ CSeq: replyMessage.headers.CSeq.replace(" INVITE", " ACK")
198
+ });
199
+ await this.softphone.send(ackMessage);
200
+ }
201
+ async hold() {
202
+ return this.toggleReceive(false);
203
+ }
204
+ async unhold() {
205
+ return this.toggleReceive(true);
206
+ }
244
207
  };
208
+ //#endregion
209
+ export { CallSession as default };
@@ -1,100 +1,57 @@
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 });
1
+ const require_utils = require("../utils.cjs");
2
+ const require_sip_message_outbound_request = require("../sip-message/outbound/request.cjs");
3
+ require("../sip-message/index.cjs");
4
+ const require_call_session_index = require("./index.cjs");
5
+ //#region src/call-session/outbound.ts
6
+ var OutboundCallSession = class extends require_call_session_index {
7
+ constructor(softphone, answerMessage) {
8
+ super(softphone, answerMessage);
9
+ this.localPeer = answerMessage.headers.From;
10
+ this.remotePeer = answerMessage.headers.To;
11
+ this.remoteKey = answerMessage.body.match(/AES_CM_128_HMAC_SHA1_80 inline:([\w+/]+)/)[1];
12
+ this.init();
13
+ }
14
+ init() {
15
+ const answerHandler = (message) => {
16
+ if (message.headers.CSeq !== this.sipMessage.headers.CSeq) return;
17
+ if (message.subject.startsWith("SIP/2.0 486")) {
18
+ this.softphone.off("message", answerHandler);
19
+ this.emit("busy");
20
+ this.dispose();
21
+ return;
22
+ }
23
+ if (message.subject.startsWith("SIP/2.0 200")) {
24
+ this.softphone.off("message", answerHandler);
25
+ this.emit("answered");
26
+ const ackMessage = new require_sip_message_outbound_request(`ACK ${require_utils.extractAddress(this.remotePeer)} SIP/2.0`, {
27
+ "Call-ID": this.callId,
28
+ From: this.localPeer,
29
+ To: this.remotePeer,
30
+ Via: this.sipMessage.headers.Via,
31
+ CSeq: this.sipMessage.headers.CSeq.replace(" INVITE", " ACK")
32
+ });
33
+ this.softphone.send(ackMessage);
34
+ }
35
+ };
36
+ this.softphone.on("message", answerHandler);
37
+ this.once("answered", () => this.startLocalServices());
38
+ }
39
+ async cancel() {
40
+ const requestMessage = new require_sip_message_outbound_request(`CANCEL ${require_utils.extractAddress(this.remotePeer)} SIP/2.0`, {
41
+ "Call-ID": this.callId,
42
+ From: this.localPeer,
43
+ To: require_utils.withoutTag(this.remotePeer),
44
+ Via: this.sipMessage.headers.Via,
45
+ CSeq: this.sipMessage.headers.CSeq.replace(" INVITE", " CANCEL")
46
+ });
47
+ await this.softphone.send(requestMessage);
48
+ }
49
+ get sessionId() {
50
+ return this.sipMessage.headers["p-rc-api-ids"].match(/party-id=([^;]+);session-id=([^;]+)/)[2];
51
+ }
52
+ get partyId() {
53
+ return this.sipMessage.headers["p-rc-api-ids"].match(/party-id=([^;]+);session-id=([^;]+)/)[1];
54
+ }
10
55
  };
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 outbound_exports = {};
29
- __export(outbound_exports, {
30
- default: () => outbound_default
31
- });
32
- module.exports = __toCommonJS(outbound_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 OutboundCallSession extends import_index.default {
37
- constructor(softphone, answerMessage) {
38
- super(softphone, answerMessage);
39
- this.localPeer = answerMessage.headers.From;
40
- this.remotePeer = answerMessage.headers.To;
41
- this.remoteKey = answerMessage.body.match(
42
- /AES_CM_128_HMAC_SHA1_80 inline:([\w+/]+)/
43
- )[1];
44
- this.init();
45
- }
46
- init() {
47
- const answerHandler = (message) => {
48
- if (message.headers.CSeq !== this.sipMessage.headers.CSeq) {
49
- return;
50
- }
51
- if (message.subject.startsWith("SIP/2.0 486")) {
52
- this.softphone.off("message", answerHandler);
53
- this.emit("busy");
54
- this.dispose();
55
- return;
56
- }
57
- if (message.subject.startsWith("SIP/2.0 200")) {
58
- this.softphone.off("message", answerHandler);
59
- this.emit("answered");
60
- const ackMessage = new import_sip_message.RequestMessage(
61
- `ACK ${(0, import_utils.extractAddress)(this.remotePeer)} SIP/2.0`,
62
- {
63
- "Call-ID": this.callId,
64
- From: this.localPeer,
65
- To: this.remotePeer,
66
- Via: this.sipMessage.headers.Via,
67
- CSeq: this.sipMessage.headers.CSeq.replace(" INVITE", " ACK")
68
- }
69
- );
70
- this.softphone.send(ackMessage);
71
- }
72
- };
73
- this.softphone.on("message", answerHandler);
74
- this.once("answered", () => this.startLocalServices());
75
- }
76
- async cancel() {
77
- const requestMessage = new import_sip_message.RequestMessage(
78
- `CANCEL ${(0, import_utils.extractAddress)(this.remotePeer)} SIP/2.0`,
79
- {
80
- "Call-ID": this.callId,
81
- From: this.localPeer,
82
- To: (0, import_utils.withoutTag)(this.remotePeer),
83
- Via: this.sipMessage.headers.Via,
84
- CSeq: this.sipMessage.headers.CSeq.replace(" INVITE", " CANCEL")
85
- }
86
- );
87
- await this.softphone.send(requestMessage);
88
- }
89
- get sessionId() {
90
- const header = this.sipMessage.headers["p-rc-api-ids"];
91
- const match = header.match(/party-id=([^;]+);session-id=([^;]+)/);
92
- return match[2];
93
- }
94
- get partyId() {
95
- const header = this.sipMessage.headers["p-rc-api-ids"];
96
- const match = header.match(/party-id=([^;]+);session-id=([^;]+)/);
97
- return match[1];
98
- }
99
- }
100
- var outbound_default = OutboundCallSession;
56
+ //#endregion
57
+ module.exports = OutboundCallSession;
@@ -0,0 +1,13 @@
1
+ import InboundMessage from "../sip-message/inbound/index.cjs";
2
+ import CallSession from "./index.cjs";
3
+ import Softphone from "../index.cjs";
4
+
5
+ //#region src/call-session/outbound.d.ts
6
+ declare class OutboundCallSession extends CallSession {
7
+ constructor(softphone: Softphone, answerMessage: InboundMessage);
8
+ init(): void;
9
+ cancel(): Promise<void>;
10
+ get sessionId(): string;
11
+ get partyId(): string;
12
+ }
13
+ export = OutboundCallSession;
@@ -1,11 +1,14 @@
1
- import type Softphone from "../index.js";
2
- import { type InboundMessage } from "../sip-message/index.js";
1
+ import InboundMessage from "../sip-message/inbound/index.js";
3
2
  import CallSession from "./index.js";
3
+ import Softphone from "../index.js";
4
+
5
+ //#region src/call-session/outbound.d.ts
4
6
  declare class OutboundCallSession extends CallSession {
5
- constructor(softphone: Softphone, answerMessage: InboundMessage);
6
- init(): void;
7
- cancel(): Promise<void>;
8
- get sessionId(): string;
9
- get partyId(): string;
7
+ constructor(softphone: Softphone, answerMessage: InboundMessage);
8
+ init(): void;
9
+ cancel(): Promise<void>;
10
+ get sessionId(): string;
11
+ get partyId(): string;
10
12
  }
11
- export default OutboundCallSession;
13
+ //#endregion
14
+ export { OutboundCallSession as default };