@sonata-sdk/voice 0.1.3 → 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 +13 -2
- package/dist/gateway.d.ts +2 -0
- package/dist/gateway.js +4 -4
- package/package.json +1 -1
package/dist/connection.js
CHANGED
|
@@ -82,6 +82,8 @@ export class VoiceConnection extends EventEmitter {
|
|
|
82
82
|
try {
|
|
83
83
|
const { operationType, proposals } = d;
|
|
84
84
|
const result = session.processProposals(operationType, Buffer.from(proposals));
|
|
85
|
+
if (session.ready)
|
|
86
|
+
this.#daveReady = true;
|
|
85
87
|
if (result.commit && result.welcome) {
|
|
86
88
|
this.#gateway.sendDaveOp(28, Buffer.concat([result.commit, result.welcome]));
|
|
87
89
|
}
|
|
@@ -99,6 +101,8 @@ export class VoiceConnection extends EventEmitter {
|
|
|
99
101
|
return this.emit('error', new Error('No DAVE session'));
|
|
100
102
|
try {
|
|
101
103
|
session.processCommit(data);
|
|
104
|
+
if (session.ready)
|
|
105
|
+
this.#daveReady = true;
|
|
102
106
|
}
|
|
103
107
|
catch (e) {
|
|
104
108
|
this.emit('error', new Error(`DAVE commit: ${e.message}`));
|
|
@@ -110,6 +114,8 @@ export class VoiceConnection extends EventEmitter {
|
|
|
110
114
|
return this.emit('error', new Error('No DAVE session'));
|
|
111
115
|
try {
|
|
112
116
|
session.processWelcome(data);
|
|
117
|
+
if (session.ready)
|
|
118
|
+
this.#daveReady = true;
|
|
113
119
|
}
|
|
114
120
|
catch (e) {
|
|
115
121
|
this.emit('error', new Error(`DAVE welcome: ${e.message}`));
|
|
@@ -131,14 +137,19 @@ export class VoiceConnection extends EventEmitter {
|
|
|
131
137
|
sendAudioFrame(frame) {
|
|
132
138
|
if (this.#destroyed)
|
|
133
139
|
return;
|
|
140
|
+
let payload = frame;
|
|
141
|
+
const daveSession = this.#gateway.daveSession;
|
|
142
|
+
if (this.#daveReady && daveSession?.ready) {
|
|
143
|
+
payload = daveSession.encryptOpus(frame);
|
|
144
|
+
}
|
|
134
145
|
if (this.#encryption) {
|
|
135
|
-
const encrypted = this.#encryption.encrypt(
|
|
146
|
+
const encrypted = this.#encryption.encrypt(payload);
|
|
136
147
|
if (!encrypted)
|
|
137
148
|
return; // silence frame
|
|
138
149
|
this.#udp.send(encrypted);
|
|
139
150
|
}
|
|
140
151
|
else {
|
|
141
|
-
this.#udp.send(
|
|
152
|
+
this.#udp.send(payload);
|
|
142
153
|
}
|
|
143
154
|
this.statistics.packetsSent++;
|
|
144
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
|
}
|