@sonata-sdk/voice 0.1.2 → 0.1.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/connection.js +17 -5
- package/dist/gateway.d.ts +2 -0
- package/dist/gateway.js +4 -4
- package/package.json +1 -1
package/dist/connection.js
CHANGED
|
@@ -38,14 +38,15 @@ export class VoiceConnection extends EventEmitter {
|
|
|
38
38
|
}).catch((err) => this.emit('error', err));
|
|
39
39
|
});
|
|
40
40
|
this.#gateway.on('sessionDescription', (payload) => {
|
|
41
|
-
|
|
41
|
+
const secretKey = Buffer.from(payload.secret_key);
|
|
42
|
+
this.#udp.setSecretKey(secretKey);
|
|
42
43
|
this.udpInfo = {
|
|
43
44
|
ssrc: this.#gateway.ssrc,
|
|
44
45
|
ip: this.#gateway.ip,
|
|
45
46
|
port: this.#gateway.port,
|
|
46
|
-
secretKey
|
|
47
|
+
secretKey,
|
|
47
48
|
};
|
|
48
|
-
this.#encryption = new AudioEncryption(payload.mode,
|
|
49
|
+
this.#encryption = new AudioEncryption(payload.mode, secretKey, this.#gateway.ssrc);
|
|
49
50
|
this.state = { status: 'connected', reason: null, code: null };
|
|
50
51
|
this.emit('stateChange', { status: 'connecting' }, this.state);
|
|
51
52
|
this.emit('ready');
|
|
@@ -81,6 +82,8 @@ export class VoiceConnection extends EventEmitter {
|
|
|
81
82
|
try {
|
|
82
83
|
const { operationType, proposals } = d;
|
|
83
84
|
const result = session.processProposals(operationType, Buffer.from(proposals));
|
|
85
|
+
if (session.ready)
|
|
86
|
+
this.#daveReady = true;
|
|
84
87
|
if (result.commit && result.welcome) {
|
|
85
88
|
this.#gateway.sendDaveOp(28, Buffer.concat([result.commit, result.welcome]));
|
|
86
89
|
}
|
|
@@ -98,6 +101,8 @@ export class VoiceConnection extends EventEmitter {
|
|
|
98
101
|
return this.emit('error', new Error('No DAVE session'));
|
|
99
102
|
try {
|
|
100
103
|
session.processCommit(data);
|
|
104
|
+
if (session.ready)
|
|
105
|
+
this.#daveReady = true;
|
|
101
106
|
}
|
|
102
107
|
catch (e) {
|
|
103
108
|
this.emit('error', new Error(`DAVE commit: ${e.message}`));
|
|
@@ -109,6 +114,8 @@ export class VoiceConnection extends EventEmitter {
|
|
|
109
114
|
return this.emit('error', new Error('No DAVE session'));
|
|
110
115
|
try {
|
|
111
116
|
session.processWelcome(data);
|
|
117
|
+
if (session.ready)
|
|
118
|
+
this.#daveReady = true;
|
|
112
119
|
}
|
|
113
120
|
catch (e) {
|
|
114
121
|
this.emit('error', new Error(`DAVE welcome: ${e.message}`));
|
|
@@ -130,14 +137,19 @@ export class VoiceConnection extends EventEmitter {
|
|
|
130
137
|
sendAudioFrame(frame) {
|
|
131
138
|
if (this.#destroyed)
|
|
132
139
|
return;
|
|
140
|
+
let payload = frame;
|
|
141
|
+
const daveSession = this.#gateway.daveSession;
|
|
142
|
+
if (this.#daveReady && daveSession?.ready) {
|
|
143
|
+
payload = daveSession.encryptOpus(frame);
|
|
144
|
+
}
|
|
133
145
|
if (this.#encryption) {
|
|
134
|
-
const encrypted = this.#encryption.encrypt(
|
|
146
|
+
const encrypted = this.#encryption.encrypt(payload);
|
|
135
147
|
if (!encrypted)
|
|
136
148
|
return; // silence frame
|
|
137
149
|
this.#udp.send(encrypted);
|
|
138
150
|
}
|
|
139
151
|
else {
|
|
140
|
-
this.#udp.send(
|
|
152
|
+
this.#udp.send(payload);
|
|
141
153
|
}
|
|
142
154
|
this.statistics.packetsSent++;
|
|
143
155
|
this.statistics.packetsExpected++;
|
package/dist/gateway.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { DAVESession } from '@snazzah/davey';
|
|
2
3
|
export interface VoiceServerPayload {
|
|
3
4
|
token: string;
|
|
4
5
|
endpoint: string;
|
|
@@ -18,6 +19,7 @@ export interface SessionDescriptionPayload {
|
|
|
18
19
|
}
|
|
19
20
|
export declare class VoiceGateway extends EventEmitter {
|
|
20
21
|
#private;
|
|
22
|
+
daveSession: DAVESession | null;
|
|
21
23
|
get connected(): boolean;
|
|
22
24
|
get ssrc(): number;
|
|
23
25
|
get ip(): string;
|
package/dist/gateway.js
CHANGED
|
@@ -20,7 +20,7 @@ export class VoiceGateway extends EventEmitter {
|
|
|
20
20
|
#secretKey = null;
|
|
21
21
|
#connected = false;
|
|
22
22
|
#daveProtocolVersion = 0;
|
|
23
|
-
|
|
23
|
+
daveSession = null;
|
|
24
24
|
#daveKeypair = null;
|
|
25
25
|
#pendingBinary = [];
|
|
26
26
|
get connected() { return this.#connected; }
|
|
@@ -39,7 +39,7 @@ export class VoiceGateway extends EventEmitter {
|
|
|
39
39
|
try {
|
|
40
40
|
this.#daveKeypair = generateP256Keypair();
|
|
41
41
|
this.#channelId = channelId;
|
|
42
|
-
this
|
|
42
|
+
this.daveSession = new DAVESession(Number(DAVE_PROTOCOL_VERSION), this.#userId, channelId, this.#daveKeypair);
|
|
43
43
|
}
|
|
44
44
|
catch (e) {
|
|
45
45
|
this.emit('error', new Error(`DAVE init failed: ${e.message}`));
|
|
@@ -53,7 +53,7 @@ export class VoiceGateway extends EventEmitter {
|
|
|
53
53
|
this.#endpoint = endpoint.replace(/^wss:\/\//, '').replace(/\/\?v=\d+$/, '');
|
|
54
54
|
if (channelId) {
|
|
55
55
|
this.#channelId = channelId;
|
|
56
|
-
if (!this
|
|
56
|
+
if (!this.daveSession)
|
|
57
57
|
this.setDaveSession(channelId);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -91,7 +91,7 @@ export class VoiceGateway extends EventEmitter {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
#handleDaveBinary(data) {
|
|
94
|
-
if (!this
|
|
94
|
+
if (!this.daveSession) {
|
|
95
95
|
this.#pendingBinary.push(data);
|
|
96
96
|
return;
|
|
97
97
|
}
|