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.
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/call-session/inbound.cjs +41 -83
- package/dist/call-session/inbound.d.cts +10 -0
- package/dist/call-session/inbound.d.ts +8 -5
- package/dist/call-session/inbound.js +36 -49
- package/dist/call-session/index.cjs +212 -269
- package/dist/call-session/index.d.cts +48 -0
- package/dist/call-session/index.d.ts +44 -39
- package/dist/call-session/index.js +204 -239
- package/dist/call-session/outbound.cjs +56 -99
- package/dist/call-session/outbound.d.cts +13 -0
- package/dist/call-session/outbound.d.ts +11 -8
- package/dist/call-session/outbound.js +54 -68
- package/dist/call-session/streamer.cjs +66 -111
- package/dist/call-session/streamer.d.cts +19 -0
- package/dist/call-session/streamer.d.ts +16 -13
- package/dist/call-session/streamer.js +61 -79
- package/dist/codec.cjs +68 -84
- package/dist/codec.d.cts +17 -0
- package/dist/codec.d.ts +15 -12
- package/dist/codec.js +65 -63
- package/dist/dtmf.cjs +42 -64
- package/dist/dtmf.d.cts +9 -0
- package/dist/dtmf.d.ts +9 -7
- package/dist/dtmf.js +40 -44
- package/dist/index.cjs +166 -248
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +28 -24
- package/dist/index.js +156 -224
- package/dist/sip-message/inbound/index.cjs +16 -50
- package/dist/sip-message/inbound/index.d.cts +7 -0
- package/dist/sip-message/inbound/index.d.ts +5 -2
- package/dist/sip-message/inbound/index.js +14 -19
- package/dist/sip-message/index.cjs +11 -49
- package/dist/sip-message/index.d.cts +6 -0
- package/dist/sip-message/index.d.ts +6 -5
- package/dist/sip-message/index.js +6 -12
- package/dist/sip-message/outbound/index.cjs +10 -40
- package/dist/sip-message/outbound/index.d.cts +7 -0
- package/dist/sip-message/outbound/index.d.ts +5 -2
- package/dist/sip-message/outbound/index.js +9 -10
- package/dist/sip-message/outbound/request.cjs +20 -61
- package/dist/sip-message/outbound/request.d.cts +9 -0
- package/dist/sip-message/outbound/request.d.ts +7 -4
- package/dist/sip-message/outbound/request.js +17 -29
- package/dist/sip-message/outbound/response.cjs +25 -54
- package/dist/sip-message/outbound/response.d.cts +8 -0
- package/dist/sip-message/outbound/response.d.ts +6 -3
- package/dist/sip-message/outbound/response.js +24 -24
- package/dist/sip-message/response-codes.cjs +80 -100
- package/dist/sip-message/response-codes.d.cts +5 -0
- package/dist/sip-message/response-codes.d.ts +4 -2
- package/dist/sip-message/response-codes.js +80 -81
- package/dist/sip-message/sip-message.cjs +25 -52
- package/dist/sip-message/sip-message.d.cts +12 -0
- package/dist/sip-message/sip-message.d.ts +11 -9
- package/dist/sip-message/sip-message.js +25 -33
- package/dist/types.cjs +0 -15
- package/dist/types.d.cts +12 -0
- package/dist/types.d.ts +11 -8
- package/dist/types.js +1 -0
- package/dist/utils.cjs +27 -73
- package/dist/utils.d.cts +12 -0
- package/dist/utils.d.ts +12 -8
- package/dist/utils.js +15 -31
- package/package.json +5 -5
|
@@ -1,71 +1,57 @@
|
|
|
1
|
-
import { RequestMessage } from "../sip-message/index.js";
|
|
2
1
|
import { extractAddress, withoutTag } from "../utils.js";
|
|
2
|
+
import RequestMessage from "../sip-message/outbound/request.js";
|
|
3
|
+
import "../sip-message/index.js";
|
|
3
4
|
import CallSession from "./index.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
55
|
-
await this.softphone.send(requestMessage);
|
|
56
|
-
}
|
|
57
|
-
get sessionId() {
|
|
58
|
-
const header = this.sipMessage.headers["p-rc-api-ids"];
|
|
59
|
-
const match = header.match(/party-id=([^;]+);session-id=([^;]+)/);
|
|
60
|
-
return match[2];
|
|
61
|
-
}
|
|
62
|
-
get partyId() {
|
|
63
|
-
const header = this.sipMessage.headers["p-rc-api-ids"];
|
|
64
|
-
const match = header.match(/party-id=([^;]+);session-id=([^;]+)/);
|
|
65
|
-
return match[1];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
var outbound_default = OutboundCallSession;
|
|
69
|
-
export {
|
|
70
|
-
outbound_default as default
|
|
5
|
+
//#region src/call-session/outbound.ts
|
|
6
|
+
var OutboundCallSession = class extends CallSession {
|
|
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 RequestMessage(`ACK ${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 RequestMessage(`CANCEL ${extractAddress(this.remotePeer)} SIP/2.0`, {
|
|
41
|
+
"Call-ID": this.callId,
|
|
42
|
+
From: this.localPeer,
|
|
43
|
+
To: 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
|
+
}
|
|
71
55
|
};
|
|
56
|
+
//#endregion
|
|
57
|
+
export { OutboundCallSession as default };
|
|
@@ -1,112 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let node_buffer = require("node:buffer");
|
|
3
|
+
let node_events = require("node:events");
|
|
4
|
+
node_events = require_runtime.__toESM(node_events, 1);
|
|
5
|
+
let werift_rtp = require("werift-rtp");
|
|
6
|
+
//#region src/call-session/streamer.ts
|
|
7
|
+
var Streamer = class extends node_events.default {
|
|
8
|
+
paused = false;
|
|
9
|
+
callSession;
|
|
10
|
+
buffer;
|
|
11
|
+
originalBuffer;
|
|
12
|
+
constructor(callSession, buffer) {
|
|
13
|
+
super();
|
|
14
|
+
this.callSession = callSession;
|
|
15
|
+
this.buffer = buffer;
|
|
16
|
+
this.originalBuffer = buffer;
|
|
17
|
+
}
|
|
18
|
+
start() {
|
|
19
|
+
this.buffer = this.originalBuffer;
|
|
20
|
+
this.paused = false;
|
|
21
|
+
this.sendPacket();
|
|
22
|
+
}
|
|
23
|
+
stop() {
|
|
24
|
+
this.buffer = node_buffer.Buffer.alloc(0);
|
|
25
|
+
}
|
|
26
|
+
pause() {
|
|
27
|
+
this.paused = true;
|
|
28
|
+
}
|
|
29
|
+
resume() {
|
|
30
|
+
this.paused = false;
|
|
31
|
+
this.sendPacket();
|
|
32
|
+
}
|
|
33
|
+
get finished() {
|
|
34
|
+
return this.callSession.disposed || this.buffer.length < this.callSession.softphone.codec.packetSize;
|
|
35
|
+
}
|
|
36
|
+
sendPacket() {
|
|
37
|
+
if (!this.paused && !this.finished) {
|
|
38
|
+
const temp = this.callSession.encoder.encode(this.buffer.subarray(0, this.callSession.softphone.codec.packetSize));
|
|
39
|
+
const rtpPacket = new werift_rtp.RtpPacket(new werift_rtp.RtpHeader({
|
|
40
|
+
version: 2,
|
|
41
|
+
padding: false,
|
|
42
|
+
paddingSize: 0,
|
|
43
|
+
extension: false,
|
|
44
|
+
marker: false,
|
|
45
|
+
payloadOffset: 12,
|
|
46
|
+
payloadType: this.callSession.softphone.codec.id,
|
|
47
|
+
sequenceNumber: this.callSession.sequenceNumber,
|
|
48
|
+
timestamp: this.callSession.timestamp,
|
|
49
|
+
ssrc: this.callSession.ssrc,
|
|
50
|
+
csrcLength: 0,
|
|
51
|
+
csrc: [],
|
|
52
|
+
extensionProfile: 48862,
|
|
53
|
+
extensionLength: void 0,
|
|
54
|
+
extensions: []
|
|
55
|
+
}), temp);
|
|
56
|
+
this.callSession.send(this.callSession.srtpSession.encrypt(rtpPacket.payload, rtpPacket.header));
|
|
57
|
+
this.callSession.sequenceNumber += 1;
|
|
58
|
+
if (this.callSession.sequenceNumber > 65535) this.callSession.sequenceNumber = 0;
|
|
59
|
+
this.callSession.timestamp += this.callSession.softphone.codec.timestampInterval;
|
|
60
|
+
this.buffer = this.buffer.subarray(this.callSession.softphone.codec.packetSize);
|
|
61
|
+
if (this.finished) this.emit("finished");
|
|
62
|
+
else setTimeout(() => this.sendPacket(), 20);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
10
65
|
};
|
|
11
|
-
|
|
12
|
-
|
|
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 streamer_exports = {};
|
|
29
|
-
__export(streamer_exports, {
|
|
30
|
-
default: () => streamer_default
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(streamer_exports);
|
|
33
|
-
var import_node_buffer = require("node:buffer");
|
|
34
|
-
var import_node_events = __toESM(require("node:events"), 1);
|
|
35
|
-
var import_werift_rtp = require("werift-rtp");
|
|
36
|
-
class Streamer extends import_node_events.default {
|
|
37
|
-
paused = false;
|
|
38
|
-
callSession;
|
|
39
|
-
buffer;
|
|
40
|
-
originalBuffer;
|
|
41
|
-
constructor(callSesstion, buffer) {
|
|
42
|
-
super();
|
|
43
|
-
this.callSession = callSesstion;
|
|
44
|
-
this.buffer = buffer;
|
|
45
|
-
this.originalBuffer = buffer;
|
|
46
|
-
}
|
|
47
|
-
start() {
|
|
48
|
-
this.buffer = this.originalBuffer;
|
|
49
|
-
this.paused = false;
|
|
50
|
-
this.sendPacket();
|
|
51
|
-
}
|
|
52
|
-
stop() {
|
|
53
|
-
this.buffer = import_node_buffer.Buffer.alloc(0);
|
|
54
|
-
}
|
|
55
|
-
pause() {
|
|
56
|
-
this.paused = true;
|
|
57
|
-
}
|
|
58
|
-
resume() {
|
|
59
|
-
this.paused = false;
|
|
60
|
-
this.sendPacket();
|
|
61
|
-
}
|
|
62
|
-
get finished() {
|
|
63
|
-
return this.callSession.disposed || this.buffer.length < this.callSession.softphone.codec.packetSize;
|
|
64
|
-
}
|
|
65
|
-
sendPacket() {
|
|
66
|
-
if (!this.paused && !this.finished) {
|
|
67
|
-
const temp = this.callSession.encoder.encode(
|
|
68
|
-
this.buffer.subarray(0, this.callSession.softphone.codec.packetSize)
|
|
69
|
-
);
|
|
70
|
-
const rtpPacket = new import_werift_rtp.RtpPacket(
|
|
71
|
-
new import_werift_rtp.RtpHeader({
|
|
72
|
-
version: 2,
|
|
73
|
-
padding: false,
|
|
74
|
-
paddingSize: 0,
|
|
75
|
-
extension: false,
|
|
76
|
-
marker: false,
|
|
77
|
-
payloadOffset: 12,
|
|
78
|
-
payloadType: this.callSession.softphone.codec.id,
|
|
79
|
-
sequenceNumber: this.callSession.sequenceNumber,
|
|
80
|
-
timestamp: this.callSession.timestamp,
|
|
81
|
-
ssrc: this.callSession.ssrc,
|
|
82
|
-
csrcLength: 0,
|
|
83
|
-
csrc: [],
|
|
84
|
-
extensionProfile: 48862,
|
|
85
|
-
extensionLength: void 0,
|
|
86
|
-
extensions: []
|
|
87
|
-
}),
|
|
88
|
-
temp
|
|
89
|
-
);
|
|
90
|
-
this.callSession.send(
|
|
91
|
-
this.callSession.srtpSession.encrypt(
|
|
92
|
-
rtpPacket.payload,
|
|
93
|
-
rtpPacket.header
|
|
94
|
-
)
|
|
95
|
-
);
|
|
96
|
-
this.callSession.sequenceNumber += 1;
|
|
97
|
-
if (this.callSession.sequenceNumber > 65535) {
|
|
98
|
-
this.callSession.sequenceNumber = 0;
|
|
99
|
-
}
|
|
100
|
-
this.callSession.timestamp += this.callSession.softphone.codec.timestampInterval;
|
|
101
|
-
this.buffer = this.buffer.subarray(
|
|
102
|
-
this.callSession.softphone.codec.packetSize
|
|
103
|
-
);
|
|
104
|
-
if (this.finished) {
|
|
105
|
-
this.emit("finished");
|
|
106
|
-
} else {
|
|
107
|
-
setTimeout(() => this.sendPacket(), 20);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
var streamer_default = Streamer;
|
|
66
|
+
//#endregion
|
|
67
|
+
module.exports = Streamer;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import CallSession from "./index.cjs";
|
|
2
|
+
import EventEmitter from "node:events";
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
4
|
+
|
|
5
|
+
//#region src/call-session/streamer.d.ts
|
|
6
|
+
declare class Streamer extends EventEmitter {
|
|
7
|
+
paused: boolean;
|
|
8
|
+
private callSession;
|
|
9
|
+
private buffer;
|
|
10
|
+
private originalBuffer;
|
|
11
|
+
constructor(callSession: CallSession, buffer: Buffer);
|
|
12
|
+
start(): void;
|
|
13
|
+
stop(): void;
|
|
14
|
+
pause(): void;
|
|
15
|
+
resume(): void;
|
|
16
|
+
get finished(): boolean;
|
|
17
|
+
private sendPacket;
|
|
18
|
+
}
|
|
19
|
+
export = Streamer;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import CallSession from "./index.js";
|
|
1
2
|
import { Buffer } from "node:buffer";
|
|
2
3
|
import EventEmitter from "node:events";
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
//#region src/call-session/streamer.d.ts
|
|
4
6
|
declare class Streamer extends EventEmitter {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
paused: boolean;
|
|
8
|
+
private callSession;
|
|
9
|
+
private buffer;
|
|
10
|
+
private originalBuffer;
|
|
11
|
+
constructor(callSession: CallSession, buffer: Buffer);
|
|
12
|
+
start(): void;
|
|
13
|
+
stop(): void;
|
|
14
|
+
pause(): void;
|
|
15
|
+
resume(): void;
|
|
16
|
+
get finished(): boolean;
|
|
17
|
+
private sendPacket;
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Streamer as default };
|
|
@@ -1,83 +1,65 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
2
|
import EventEmitter from "node:events";
|
|
3
3
|
import { RtpHeader, RtpPacket } from "werift-rtp";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
64
|
-
this.callSession.sequenceNumber += 1;
|
|
65
|
-
if (this.callSession.sequenceNumber > 65535) {
|
|
66
|
-
this.callSession.sequenceNumber = 0;
|
|
67
|
-
}
|
|
68
|
-
this.callSession.timestamp += this.callSession.softphone.codec.timestampInterval;
|
|
69
|
-
this.buffer = this.buffer.subarray(
|
|
70
|
-
this.callSession.softphone.codec.packetSize
|
|
71
|
-
);
|
|
72
|
-
if (this.finished) {
|
|
73
|
-
this.emit("finished");
|
|
74
|
-
} else {
|
|
75
|
-
setTimeout(() => this.sendPacket(), 20);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
var streamer_default = Streamer;
|
|
81
|
-
export {
|
|
82
|
-
streamer_default as default
|
|
4
|
+
//#region src/call-session/streamer.ts
|
|
5
|
+
var Streamer = class extends EventEmitter {
|
|
6
|
+
paused = false;
|
|
7
|
+
callSession;
|
|
8
|
+
buffer;
|
|
9
|
+
originalBuffer;
|
|
10
|
+
constructor(callSession, buffer) {
|
|
11
|
+
super();
|
|
12
|
+
this.callSession = callSession;
|
|
13
|
+
this.buffer = buffer;
|
|
14
|
+
this.originalBuffer = buffer;
|
|
15
|
+
}
|
|
16
|
+
start() {
|
|
17
|
+
this.buffer = this.originalBuffer;
|
|
18
|
+
this.paused = false;
|
|
19
|
+
this.sendPacket();
|
|
20
|
+
}
|
|
21
|
+
stop() {
|
|
22
|
+
this.buffer = Buffer.alloc(0);
|
|
23
|
+
}
|
|
24
|
+
pause() {
|
|
25
|
+
this.paused = true;
|
|
26
|
+
}
|
|
27
|
+
resume() {
|
|
28
|
+
this.paused = false;
|
|
29
|
+
this.sendPacket();
|
|
30
|
+
}
|
|
31
|
+
get finished() {
|
|
32
|
+
return this.callSession.disposed || this.buffer.length < this.callSession.softphone.codec.packetSize;
|
|
33
|
+
}
|
|
34
|
+
sendPacket() {
|
|
35
|
+
if (!this.paused && !this.finished) {
|
|
36
|
+
const temp = this.callSession.encoder.encode(this.buffer.subarray(0, this.callSession.softphone.codec.packetSize));
|
|
37
|
+
const rtpPacket = new RtpPacket(new RtpHeader({
|
|
38
|
+
version: 2,
|
|
39
|
+
padding: false,
|
|
40
|
+
paddingSize: 0,
|
|
41
|
+
extension: false,
|
|
42
|
+
marker: false,
|
|
43
|
+
payloadOffset: 12,
|
|
44
|
+
payloadType: this.callSession.softphone.codec.id,
|
|
45
|
+
sequenceNumber: this.callSession.sequenceNumber,
|
|
46
|
+
timestamp: this.callSession.timestamp,
|
|
47
|
+
ssrc: this.callSession.ssrc,
|
|
48
|
+
csrcLength: 0,
|
|
49
|
+
csrc: [],
|
|
50
|
+
extensionProfile: 48862,
|
|
51
|
+
extensionLength: void 0,
|
|
52
|
+
extensions: []
|
|
53
|
+
}), temp);
|
|
54
|
+
this.callSession.send(this.callSession.srtpSession.encrypt(rtpPacket.payload, rtpPacket.header));
|
|
55
|
+
this.callSession.sequenceNumber += 1;
|
|
56
|
+
if (this.callSession.sequenceNumber > 65535) this.callSession.sequenceNumber = 0;
|
|
57
|
+
this.callSession.timestamp += this.callSession.softphone.codec.timestampInterval;
|
|
58
|
+
this.buffer = this.buffer.subarray(this.callSession.softphone.codec.packetSize);
|
|
59
|
+
if (this.finished) this.emit("finished");
|
|
60
|
+
else setTimeout(() => this.sendPacket(), 20);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
83
63
|
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { Streamer as default };
|
package/dist/codec.cjs
CHANGED
|
@@ -1,85 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let node_buffer = require("node:buffer");
|
|
3
|
+
let _evan_opus = require("@evan/opus");
|
|
4
|
+
//#region src/codec.ts
|
|
5
|
+
var Codec = class {
|
|
6
|
+
id;
|
|
7
|
+
name;
|
|
8
|
+
packetSize;
|
|
9
|
+
timestampInterval;
|
|
10
|
+
createEncoder;
|
|
11
|
+
createDecoder;
|
|
12
|
+
constructor(name) {
|
|
13
|
+
this.name = name;
|
|
14
|
+
switch (name) {
|
|
15
|
+
case "OPUS/16000":
|
|
16
|
+
this.createEncoder = () => {
|
|
17
|
+
const encoder = new _evan_opus.Encoder({
|
|
18
|
+
channels: 1,
|
|
19
|
+
sample_rate: 16e3
|
|
20
|
+
});
|
|
21
|
+
return { encode: (pcm) => node_buffer.Buffer.from(encoder.encode(pcm)) };
|
|
22
|
+
};
|
|
23
|
+
this.createDecoder = () => {
|
|
24
|
+
const decoder = new _evan_opus.Decoder({
|
|
25
|
+
channels: 1,
|
|
26
|
+
sample_rate: 16e3
|
|
27
|
+
});
|
|
28
|
+
return { decode: (opus) => node_buffer.Buffer.from(decoder.decode(opus)) };
|
|
29
|
+
};
|
|
30
|
+
this.id = 109;
|
|
31
|
+
this.packetSize = 640;
|
|
32
|
+
this.timestampInterval = 320;
|
|
33
|
+
break;
|
|
34
|
+
case "OPUS/48000/2":
|
|
35
|
+
this.createEncoder = () => {
|
|
36
|
+
const encoder = new _evan_opus.Encoder({
|
|
37
|
+
channels: 2,
|
|
38
|
+
sample_rate: 48e3
|
|
39
|
+
});
|
|
40
|
+
return { encode: (pcm) => node_buffer.Buffer.from(encoder.encode(pcm)) };
|
|
41
|
+
};
|
|
42
|
+
this.createDecoder = () => {
|
|
43
|
+
const decoder = new _evan_opus.Decoder({
|
|
44
|
+
channels: 2,
|
|
45
|
+
sample_rate: 48e3
|
|
46
|
+
});
|
|
47
|
+
return { decode: (opus) => node_buffer.Buffer.from(decoder.decode(opus)) };
|
|
48
|
+
};
|
|
49
|
+
this.id = 111;
|
|
50
|
+
this.packetSize = 3840;
|
|
51
|
+
this.timestampInterval = 960;
|
|
52
|
+
break;
|
|
53
|
+
case "PCMU/8000":
|
|
54
|
+
this.createEncoder = () => {
|
|
55
|
+
return { encode: (pcm) => pcm };
|
|
56
|
+
};
|
|
57
|
+
this.createDecoder = () => {
|
|
58
|
+
return { decode: (audio) => audio };
|
|
59
|
+
};
|
|
60
|
+
this.id = 0;
|
|
61
|
+
this.packetSize = 160;
|
|
62
|
+
this.timestampInterval = 160;
|
|
63
|
+
break;
|
|
64
|
+
default: throw new Error(`unsupported codec: ${name}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
8
67
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var codec_exports = {};
|
|
19
|
-
__export(codec_exports, {
|
|
20
|
-
default: () => codec_default
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(codec_exports);
|
|
23
|
-
var import_node_buffer = require("node:buffer");
|
|
24
|
-
var import_opus = require("@evan/opus");
|
|
25
|
-
class Codec {
|
|
26
|
-
id;
|
|
27
|
-
name;
|
|
28
|
-
packetSize;
|
|
29
|
-
timestampInterval;
|
|
30
|
-
createEncoder;
|
|
31
|
-
createDecoder;
|
|
32
|
-
constructor(name) {
|
|
33
|
-
this.name = name;
|
|
34
|
-
switch (name) {
|
|
35
|
-
case "OPUS/16000": {
|
|
36
|
-
this.createEncoder = () => {
|
|
37
|
-
const encoder = new import_opus.Encoder({ channels: 1, sample_rate: 16e3 });
|
|
38
|
-
return { encode: (pcm) => import_node_buffer.Buffer.from(encoder.encode(pcm)) };
|
|
39
|
-
};
|
|
40
|
-
this.createDecoder = () => {
|
|
41
|
-
const decoder = new import_opus.Decoder({ channels: 1, sample_rate: 16e3 });
|
|
42
|
-
return {
|
|
43
|
-
decode: (opus) => import_node_buffer.Buffer.from(decoder.decode(opus))
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
this.id = 109;
|
|
47
|
-
this.packetSize = 640;
|
|
48
|
-
this.timestampInterval = 320;
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case "OPUS/48000/2": {
|
|
52
|
-
this.createEncoder = () => {
|
|
53
|
-
const encoder = new import_opus.Encoder({ channels: 2, sample_rate: 48e3 });
|
|
54
|
-
return { encode: (pcm) => import_node_buffer.Buffer.from(encoder.encode(pcm)) };
|
|
55
|
-
};
|
|
56
|
-
this.createDecoder = () => {
|
|
57
|
-
const decoder = new import_opus.Decoder({ channels: 2, sample_rate: 48e3 });
|
|
58
|
-
return {
|
|
59
|
-
decode: (opus) => import_node_buffer.Buffer.from(decoder.decode(opus))
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
this.id = 111;
|
|
63
|
-
this.packetSize = 3840;
|
|
64
|
-
this.timestampInterval = 960;
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
case "PCMU/8000": {
|
|
68
|
-
this.createEncoder = () => {
|
|
69
|
-
return { encode: (pcm) => pcm };
|
|
70
|
-
};
|
|
71
|
-
this.createDecoder = () => {
|
|
72
|
-
return { decode: (audio) => audio };
|
|
73
|
-
};
|
|
74
|
-
this.id = 0;
|
|
75
|
-
this.packetSize = 160;
|
|
76
|
-
this.timestampInterval = 160;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
default: {
|
|
80
|
-
throw new Error(`unsupported codec: ${name}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
var codec_default = Codec;
|
|
68
|
+
//#endregion
|
|
69
|
+
module.exports = Codec;
|
package/dist/codec.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
|
|
3
|
+
//#region src/codec.d.ts
|
|
4
|
+
declare class Codec {
|
|
5
|
+
id: number;
|
|
6
|
+
name: "OPUS/16000" | "OPUS/48000/2" | "PCMU/8000";
|
|
7
|
+
packetSize: number;
|
|
8
|
+
timestampInterval: number;
|
|
9
|
+
createEncoder: () => {
|
|
10
|
+
encode: (pcm: Buffer) => Buffer;
|
|
11
|
+
};
|
|
12
|
+
createDecoder: () => {
|
|
13
|
+
decode: (audio: Buffer) => Buffer;
|
|
14
|
+
};
|
|
15
|
+
constructor(name: "OPUS/16000" | "OPUS/48000/2" | "PCMU/8000");
|
|
16
|
+
}
|
|
17
|
+
export = Codec;
|