summary refs log tree commit diff
path: root/webrtc
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-02-17 18:54:16 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-02-17 18:54:16 +1100
commitd491bcd8bed78703331bc6550cf3d52e3647e764 (patch)
treeaf0eb8e0514c7b903a040fa75ed74fd0825079ab /webrtc
parentMerge branch 'master' into maddyrtc (diff)
downloadserver-d491bcd8bed78703331bc6550cf3d52e3647e764.tar.xz
Discord.js gateway connection when connecting to voice will close 4002 decode error due to not sending self_video field. temp solution: remove it from server.
this commit will probably be reverted later; I'm just trying to see if a proper ( not self signed ) SSL cert on slowcord.maddy.k.vu will fix this SSL error I'm receiving.
Diffstat (limited to 'webrtc')
-rw-r--r--webrtc/.vscode/launch.json4
-rw-r--r--webrtc/src/Server.ts14
-rw-r--r--webrtc/src/opcodes/Identify.ts45
-rw-r--r--webrtc/src/opcodes/index.ts6
4 files changed, 55 insertions, 14 deletions
diff --git a/webrtc/.vscode/launch.json b/webrtc/.vscode/launch.json
index 92403164..49584172 100644
--- a/webrtc/.vscode/launch.json
+++ b/webrtc/.vscode/launch.json
@@ -17,7 +17,9 @@
 			],
 			"cwd": "${workspaceRoot}",
 			"protocol": "inspector",
-			"internalConsoleOptions": "openOnSessionStart"
+			"internalConsoleOptions": "openOnSessionStart",
+			"sourceMaps": true,
+			"resolveSourceMapLocations": null,
 		}
 	]
 }
\ No newline at end of file
diff --git a/webrtc/src/Server.ts b/webrtc/src/Server.ts
index dcbf216a..0145a221 100644
--- a/webrtc/src/Server.ts
+++ b/webrtc/src/Server.ts
@@ -1,7 +1,7 @@
 import { Server as WebSocketServer } from "ws";
-import { WebSocket, Payload, CLOSECODES } from "@fosscord/gateway";
+import { WebSocket, CLOSECODES } from "@fosscord/gateway";
 import { Config, initDatabase } from "@fosscord/util";
-import OPCodeHandlers from "./opcodes";
+import OPCodeHandlers, { Payload } from "./opcodes";
 import { setHeartbeat } from "./util";
 import * as mediasoup from "mediasoup";
 import { types as MediasoupTypes } from "mediasoup";
@@ -26,8 +26,16 @@ export class Server {
 			socket.on("message", async (message: string) => {
 				const payload: Payload = JSON.parse(message);
 
+				console.log(payload);
+
 				if (OPCodeHandlers[payload.op])
-					await OPCodeHandlers[payload.op].call(this, socket, payload);
+					try {
+						await OPCodeHandlers[payload.op].call(this, socket, payload);
+					}
+					catch (e) {
+						console.error(e);
+						socket.close(CLOSECODES.Unknown_error);
+					}
 				else {
 					console.error(`Unimplemented`, payload);
 					socket.close(CLOSECODES.Unknown_opcode);
diff --git a/webrtc/src/opcodes/Identify.ts b/webrtc/src/opcodes/Identify.ts
index 82f327be..e965e3de 100644
--- a/webrtc/src/opcodes/Identify.ts
+++ b/webrtc/src/opcodes/Identify.ts
@@ -1,9 +1,38 @@
-import { WebSocket } from "@fosscord/gateway";
+import { WebSocket, CLOSECODES } from "@fosscord/gateway";
 import { Payload } from "./index";
-import { VoiceOPCodes } from "@fosscord/util";
+import { VoiceOPCodes, Session, User, Guild } from "@fosscord/util";
 import { Server } from "../Server";
 
-export async function onIdentify(this: Server, socket: WebSocket, data: Payload) {
+export interface IdentifyPayload extends Payload {
+	d: {
+		server_id: string,	//guild id
+		session_id: string,	//gateway session
+		streams: Array<{
+			type: string,
+			rid: string,	//number
+			quality: number,
+		}>,
+		token: string,		//voice_states token
+		user_id: string,
+		video: boolean,
+	};
+}
+
+export async function onIdentify(this: Server, socket: WebSocket, data: IdentifyPayload) {
+
+	const session = await Session.findOneOrFail(
+		{ session_id: data.d.session_id, },
+		{
+			where: { user_id: data.d.user_id },
+			relations: ["user"]
+		}
+	);
+	const user = session.user;
+	const guild = await Guild.findOneOrFail({ id: data.d.server_id });
+
+	if (!guild.members.find(x => x.id === user.id))
+		return socket.close(CLOSECODES.Invalid_intent);
+
 	var transport = await this.mediasoupRouters[0].createWebRtcTransport({
 		listenIps: [{ ip: "0.0.0.0", announcedIp: "127.0.0.1" }],
 		enableUdp: true,
@@ -40,15 +69,17 @@ export async function onIdentify(this: Server, socket: WebSocket, data: Payload)
 	socket.send(JSON.stringify({
 		op: VoiceOPCodes.READY,
 		d: {
-			streams: [],
+			streams: [...data.d.streams.map(x => ({ ...x, rtx_ssrc: 1311886, ssrc: 1311885, active: false, }))],
 			ssrc: 1,
 			ip: transport.iceCandidates[0].ip,
 			port: transport.iceCandidates[0].port,
 			modes: [
 				"aead_aes256_gcm_rtpsize",
-				// "xsalsa20_poly1305",
-				// "xsalsa20_poly1305_suffix",
-				// "xsalsa20_poly1305_lite",
+				"aead_aes256_gcm",
+				"xsalsa20_poly1305_lite_rtpsize",
+				"xsalsa20_poly1305_lite",
+				"xsalsa20_poly1305_suffix",
+				"xsalsa20_poly1305"
 			],
 			heartbeat_interval: 1,
 			experiments: [],
diff --git a/webrtc/src/opcodes/index.ts b/webrtc/src/opcodes/index.ts
index 36d30e7d..9b1eb270 100644
--- a/webrtc/src/opcodes/index.ts
+++ b/webrtc/src/opcodes/index.ts
@@ -3,9 +3,9 @@ import { VoiceOPCodes } from "@fosscord/util";
 
 export interface Payload {
 	op: number;
-	d?: any;
-	s?: number;
-	t?: string;
+	d: any;
+	s: number;
+	t: string;
 }
 
 import { onIdentify } from "./Identify";