ringcentral-softphone 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/call-session/index.cjs +4 -0
- package/dist/call-session/index.d.ts +3 -1
- package/dist/call-session/index.js +4 -0
- package/dist/call-session/streamer.cjs +2 -2
- package/dist/call-session/streamer.d.ts +1 -1
- package/dist/call-session/streamer.js +2 -2
- package/dist/dtmf.cjs +32 -31
- package/dist/dtmf.d.ts +5 -6
- package/dist/dtmf.js +32 -31
- package/dist/index.cjs +3 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
@@ -39,6 +39,7 @@ var import_dtmf = __toESM(require("../dtmf.js"), 1);
|
|
|
39
39
|
var import_sip_message = require("../sip-message/index.js");
|
|
40
40
|
var import_utils = require("../utils.js");
|
|
41
41
|
var import_streamer = __toESM(require("./streamer.js"), 1);
|
|
42
|
+
const isDtmfChar = (value) => import_dtmf.default.phoneChars.includes(value);
|
|
42
43
|
class CallSession extends import_node_events.default {
|
|
43
44
|
softphone;
|
|
44
45
|
sipMessage;
|
|
@@ -132,6 +133,9 @@ class CallSession extends import_node_events.default {
|
|
|
132
133
|
}
|
|
133
134
|
async sendDTMFs(s, delay = 500) {
|
|
134
135
|
for (const c of s) {
|
|
136
|
+
if (!isDtmfChar(c)) {
|
|
137
|
+
throw new Error(`invalid phone char: ${c}`);
|
|
138
|
+
}
|
|
135
139
|
this.sendDTMF(c);
|
|
136
140
|
await (0, import_wait_for_async.default)({ interval: delay });
|
|
137
141
|
}
|
|
@@ -2,9 +2,11 @@ import { Buffer } from "node:buffer";
|
|
|
2
2
|
import dgram from "node:dgram";
|
|
3
3
|
import EventEmitter from "node:events";
|
|
4
4
|
import { RtpPacket, SrtpSession } from "werift-rtp";
|
|
5
|
+
import DTMF from "../dtmf.js";
|
|
5
6
|
import type Softphone from "../index.js";
|
|
6
7
|
import { type InboundMessage } from "../sip-message/index.js";
|
|
7
8
|
import Streamer from "./streamer.js";
|
|
9
|
+
type DtmfChar = (typeof DTMF.phoneChars)[number];
|
|
8
10
|
declare abstract class CallSession extends EventEmitter {
|
|
9
11
|
softphone: Softphone;
|
|
10
12
|
sipMessage: InboundMessage;
|
|
@@ -30,7 +32,7 @@ declare abstract class CallSession extends EventEmitter {
|
|
|
30
32
|
get callId(): string | undefined;
|
|
31
33
|
send(data: string | Buffer): void;
|
|
32
34
|
hangup(): Promise<void>;
|
|
33
|
-
sendDTMF(char:
|
|
35
|
+
sendDTMF(char: DtmfChar): void;
|
|
34
36
|
sendDTMFs(s: string, delay?: number): Promise<void>;
|
|
35
37
|
streamAudio(input: Buffer): Streamer;
|
|
36
38
|
sendPacket(rtpPacket: RtpPacket): void;
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "../sip-message/index.js";
|
|
11
11
|
import { branch, extractAddress, localKey, randomInt } from "../utils.js";
|
|
12
12
|
import Streamer from "./streamer.js";
|
|
13
|
+
const isDtmfChar = (value) => DTMF.phoneChars.includes(value);
|
|
13
14
|
class CallSession extends EventEmitter {
|
|
14
15
|
softphone;
|
|
15
16
|
sipMessage;
|
|
@@ -103,6 +104,9 @@ class CallSession extends EventEmitter {
|
|
|
103
104
|
}
|
|
104
105
|
async sendDTMFs(s, delay = 500) {
|
|
105
106
|
for (const c of s) {
|
|
107
|
+
if (!isDtmfChar(c)) {
|
|
108
|
+
throw new Error(`invalid phone char: ${c}`);
|
|
109
|
+
}
|
|
106
110
|
this.sendDTMF(c);
|
|
107
111
|
await waitFor({ interval: delay });
|
|
108
112
|
}
|
|
@@ -38,9 +38,9 @@ class Streamer extends import_node_events.default {
|
|
|
38
38
|
callSession;
|
|
39
39
|
buffer;
|
|
40
40
|
originalBuffer;
|
|
41
|
-
constructor(
|
|
41
|
+
constructor(callSession, buffer) {
|
|
42
42
|
super();
|
|
43
|
-
this.callSession =
|
|
43
|
+
this.callSession = callSession;
|
|
44
44
|
this.buffer = buffer;
|
|
45
45
|
this.originalBuffer = buffer;
|
|
46
46
|
}
|
|
@@ -6,7 +6,7 @@ declare class Streamer extends EventEmitter {
|
|
|
6
6
|
private callSession;
|
|
7
7
|
private buffer;
|
|
8
8
|
private originalBuffer;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(callSession: CallSession, buffer: Buffer);
|
|
10
10
|
start(): void;
|
|
11
11
|
stop(): void;
|
|
12
12
|
pause(): void;
|
|
@@ -6,9 +6,9 @@ class Streamer extends EventEmitter {
|
|
|
6
6
|
callSession;
|
|
7
7
|
buffer;
|
|
8
8
|
originalBuffer;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(callSession, buffer) {
|
|
10
10
|
super();
|
|
11
|
-
this.callSession =
|
|
11
|
+
this.callSession = callSession;
|
|
12
12
|
this.buffer = buffer;
|
|
13
13
|
this.originalBuffer = buffer;
|
|
14
14
|
}
|
package/dist/dtmf.cjs
CHANGED
|
@@ -21,45 +21,46 @@ __export(dtmf_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(dtmf_exports);
|
|
23
23
|
var import_node_buffer = require("node:buffer");
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
24
|
+
const phoneChars = [
|
|
25
|
+
"0",
|
|
26
|
+
"1",
|
|
27
|
+
"2",
|
|
28
|
+
"3",
|
|
29
|
+
"4",
|
|
30
|
+
"5",
|
|
31
|
+
"6",
|
|
32
|
+
"7",
|
|
33
|
+
"8",
|
|
34
|
+
"9",
|
|
35
|
+
"*",
|
|
36
|
+
"#"
|
|
37
|
+
];
|
|
38
|
+
const payloads = [
|
|
39
|
+
393216,
|
|
40
|
+
393376,
|
|
41
|
+
393536,
|
|
42
|
+
8782624,
|
|
43
|
+
8782624,
|
|
44
|
+
8782624
|
|
45
|
+
];
|
|
46
|
+
const DTMF = {
|
|
47
|
+
phoneChars,
|
|
48
|
+
charToPayloads(char) {
|
|
49
|
+
const index = phoneChars.indexOf(char[0]);
|
|
49
50
|
if (index === -1) {
|
|
50
51
|
throw new Error("invalid phone char");
|
|
51
52
|
}
|
|
52
|
-
return
|
|
53
|
+
return payloads.map((payload) => {
|
|
53
54
|
const temp = payload + index * 16777216;
|
|
54
55
|
const buffer = import_node_buffer.Buffer.alloc(4);
|
|
55
56
|
buffer.writeIntBE(temp, 0, 4);
|
|
56
57
|
return buffer;
|
|
57
58
|
});
|
|
58
|
-
}
|
|
59
|
-
|
|
59
|
+
},
|
|
60
|
+
payloadToChar(payload) {
|
|
60
61
|
const intBE = payload.readIntBE(0, 4);
|
|
61
62
|
const index = (intBE - 393216) / 16777216;
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
}
|
|
63
|
+
return phoneChars[index];
|
|
64
|
+
}
|
|
65
|
+
};
|
|
65
66
|
var dtmf_default = DTMF;
|
package/dist/dtmf.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
2
|
+
declare const DTMF: {
|
|
3
|
+
phoneChars: readonly ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "#"];
|
|
4
|
+
charToPayloads(char: string): Buffer<ArrayBuffer>[];
|
|
5
|
+
payloadToChar(payload: Buffer): "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "*" | "#";
|
|
6
|
+
};
|
|
8
7
|
export default DTMF;
|
package/dist/dtmf.js
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
const phoneChars = [
|
|
3
|
+
"0",
|
|
4
|
+
"1",
|
|
5
|
+
"2",
|
|
6
|
+
"3",
|
|
7
|
+
"4",
|
|
8
|
+
"5",
|
|
9
|
+
"6",
|
|
10
|
+
"7",
|
|
11
|
+
"8",
|
|
12
|
+
"9",
|
|
13
|
+
"*",
|
|
14
|
+
"#"
|
|
15
|
+
];
|
|
16
|
+
const payloads = [
|
|
17
|
+
393216,
|
|
18
|
+
393376,
|
|
19
|
+
393536,
|
|
20
|
+
8782624,
|
|
21
|
+
8782624,
|
|
22
|
+
8782624
|
|
23
|
+
];
|
|
24
|
+
const DTMF = {
|
|
25
|
+
phoneChars,
|
|
26
|
+
charToPayloads(char) {
|
|
27
|
+
const index = phoneChars.indexOf(char[0]);
|
|
27
28
|
if (index === -1) {
|
|
28
29
|
throw new Error("invalid phone char");
|
|
29
30
|
}
|
|
30
|
-
return
|
|
31
|
+
return payloads.map((payload) => {
|
|
31
32
|
const temp = payload + index * 16777216;
|
|
32
33
|
const buffer = Buffer.alloc(4);
|
|
33
34
|
buffer.writeIntBE(temp, 0, 4);
|
|
34
35
|
return buffer;
|
|
35
36
|
});
|
|
36
|
-
}
|
|
37
|
-
|
|
37
|
+
},
|
|
38
|
+
payloadToChar(payload) {
|
|
38
39
|
const intBE = payload.readIntBE(0, 4);
|
|
39
40
|
const index = (intBE - 393216) / 16777216;
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
}
|
|
41
|
+
return phoneChars[index];
|
|
42
|
+
}
|
|
43
|
+
};
|
|
43
44
|
var dtmf_default = DTMF;
|
|
44
45
|
export {
|
|
45
46
|
dtmf_default as default
|
package/dist/index.cjs
CHANGED
|
@@ -137,7 +137,9 @@ Content-Length: 0`;
|
|
|
137
137
|
await sipRegister();
|
|
138
138
|
this.intervalHandle = setInterval(
|
|
139
139
|
() => {
|
|
140
|
-
sipRegister()
|
|
140
|
+
sipRegister().catch((error) => {
|
|
141
|
+
this.emit("registrationError", error);
|
|
142
|
+
});
|
|
141
143
|
},
|
|
142
144
|
30 * 1e3
|
|
143
145
|
// refresh registration every 30 seconds
|
package/dist/index.js
CHANGED
|
@@ -116,7 +116,9 @@ Content-Length: 0`;
|
|
|
116
116
|
await sipRegister();
|
|
117
117
|
this.intervalHandle = setInterval(
|
|
118
118
|
() => {
|
|
119
|
-
sipRegister()
|
|
119
|
+
sipRegister().catch((error) => {
|
|
120
|
+
this.emit("registrationError", error);
|
|
121
|
+
});
|
|
120
122
|
},
|
|
121
123
|
30 * 1e3
|
|
122
124
|
// refresh registration every 30 seconds
|