Merge branch 'spacebarchat:master' into fix_relationship_events

This commit is contained in:
Leafus
2026-08-18 23:49:13 +02:00
committed by GitHub
6 changed files with 66 additions and 6 deletions
Binary file not shown.
+2 -3
View File
@@ -28,7 +28,6 @@ export interface VoiceIdentifySchema {
rid: string;
quality: number;
}[];
// Discord keeps changing the property name of this, probably will keep changing until Dave is finalized
max_secure_frames_version?: number;
max_dave_protocol_version?: number;
max_secure_frames_version?: number; // pre-release Dave max version field
max_dave_protocol_version?: number; // final Dave max version field
}
+16 -1
View File
@@ -17,9 +17,24 @@
*/
import { WebSocket } from "@spacebar/gateway";
import { mediaServer, Send, VoiceOPCodes, WebRtcWebSocket } from "@spacebar/webrtc";
export async function onClose(this: WebSocket, code: number, reason: string) {
export async function onClose(this: WebRtcWebSocket, code: number, reason: string) {
console.log("[WebRTC] closed", code, reason.toString());
if (this.user_id && this.webRtcClient) {
const { voiceRoomId } = this.webRtcClient;
const connectedClients = mediaServer.getClientsForRtcServer<WebRtcWebSocket>(voiceRoomId);
for (const client of connectedClients) {
await Send(client.websocket, {
op: VoiceOPCodes.CLIENTS_CONNECT,
d: {
user_id: this.user_id,
},
});
}
}
this.removeAllListeners();
}
+1 -1
View File
@@ -52,7 +52,7 @@ export async function Connection(this: WS.Server, socket: WebRtcWebSocket, reque
const { searchParams } = new URL(`http://localhost${request.url}`);
socket.encoding = "json";
socket.version = Number(searchParams.get("v")) || 5;
socket.version = Number(searchParams.get("v")) || 9;
if (socket.version < 3) return socket.close(CLOSECODES.Unknown_error, "invalid version");
setHeartbeat(socket);
+29 -1
View File
@@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { SelectProtocolSchema, validateSchema } from "@spacebar/schemas";
import { VoiceOPCodes, VoicePayload, WebRtcWebSocket, mediaServer, Send } from "@spacebar/webrtc";
import { mediaServer, Send, VoiceOPCodes, VoicePayload, WebRtcWebSocket } from "@spacebar/webrtc";
export async function onSelectProtocol(this: WebRtcWebSocket, payload: VoicePayload) {
if (!this.webRtcClient) return;
@@ -37,4 +37,32 @@ export async function onSelectProtocol(this: WebRtcWebSocket, payload: VoicePayl
audio_codec: "opus",
},
});
const { voiceRoomId } = this.webRtcClient;
const connectedClients = mediaServer.getClientsForRtcServer<WebRtcWebSocket>(voiceRoomId);
const clientConnectData = {
user_ids: connectedClients.values().map((c) => c.user_id),
};
for (const client of connectedClients) {
await Send(client.websocket, {
op: VoiceOPCodes.CLIENTS_CONNECT,
d: clientConnectData,
});
await Send(this, {
op: VoiceOPCodes.CLIENT_FLAGS,
d: {
user_id: client.user_id,
flags: 0, // TODO: clips flags, we currently just send "none"
},
});
await Send(this, {
op: VoiceOPCodes.CLIENT_PLATFORM,
d: {
user_id: client.user_id,
platform: 0, // TODO: send platform, currently we always say desktop...
},
});
}
}
+18
View File
@@ -29,12 +29,30 @@ export enum VoiceOPCodes {
RESUME = 7,
HELLO = 8,
RESUMED = 9,
// 10 is unknown
CLIENTS_CONNECT = 11,
VIDEO = 12,
CLIENT_DISCONNECT = 13,
SESSION_UPDATE = 14,
MEDIA_SINK_WANTS = 15,
VOICE_BACKEND_VERSION = 16,
CHANNEL_OPTIONS_UPDATE = 17,
CLIENT_FLAGS = 18,
CLIENT_PLATFORM = 20,
// crypto crap...
DAVE_PROTOCOL_PREPARE_TRANSITION = 21,
DAVE_PROTOCOL_EXECUTE_TRANSITION = 22,
DAVE_PROTOCOL_TRANSITION_READY = 23,
DAVE_PROTOCOL_PREPARE_EPOCH = 24,
MLS_EXTERNAL_SENDER_PACKAGE = 25,
MLS_KEY_PACKAGE = 26,
MLS_PROPOSALS = 27,
MLS_COMMIT_WELCOME = 28,
MLS_ANNOUNCE_COMMIT_TRANSITION = 29,
MLS_WELCOME = 30,
MLS_INVALID_COMMIT_WELCOME = 31,
// no more cypto crap?
NO_ROUTE = 32,
}
export type VoicePayload = Omit<Payload, "op"> & { op: VoiceOPCodes };