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