summary refs log tree commit diff
path: root/webrtc
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-02-04 18:46:09 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-02-04 18:46:09 +1100
commit9bdc7933a8ffbb7cbb55f70909b2073bba30bde8 (patch)
tree7a9b2dea5131f64bc861af3a60176ed1523ad8bb /webrtc
parentmmmm (diff)
downloadserver-9bdc7933a8ffbb7cbb55f70909b2073bba30bde8.tar.xz
;jondfgsk
Diffstat (limited to 'webrtc')
-rw-r--r--webrtc/src/Server.ts19
-rw-r--r--webrtc/src/opcodes/Identify.ts7
-rw-r--r--webrtc/src/opcodes/SelectProtocol.ts46
3 files changed, 37 insertions, 35 deletions
diff --git a/webrtc/src/Server.ts b/webrtc/src/Server.ts
index 1d2e73e7..dcbf216a 100644
--- a/webrtc/src/Server.ts
+++ b/webrtc/src/Server.ts
@@ -1,5 +1,5 @@
 import { Server as WebSocketServer } from "ws";
-import { WebSocket, Payload, } from "@fosscord/gateway";
+import { WebSocket, Payload, CLOSECODES } from "@fosscord/gateway";
 import { Config, initDatabase } from "@fosscord/util";
 import OPCodeHandlers from "./opcodes";
 import { setHeartbeat } from "./util";
@@ -28,8 +28,10 @@ export class Server {
 
 				if (OPCodeHandlers[payload.op])
 					await OPCodeHandlers[payload.op].call(this, socket, payload);
-				else
+				else {
 					console.error(`Unimplemented`, payload);
+					socket.close(CLOSECODES.Unknown_opcode);
+				}
 			});
 		});
 	}
@@ -46,7 +48,7 @@ export class Server {
 	async createWorkers(): Promise<void> {
 		const numWorkers = 1;
 		for (let i = 0; i < numWorkers; i++) {
-			const worker = await mediasoup.createWorker();
+			const worker = await mediasoup.createWorker({ logLevel: "debug" });
 			if (!worker) return;
 
 			worker.on("died", () => {
@@ -91,17 +93,6 @@ export class Server {
 						clockRate: 48000,
 						channels: 2
 					},
-					{
-						kind: "video",
-						mimeType: "video/H264",
-						clockRate: 90000,
-						parameters:
-						{
-							"packetization-mode": 1,
-							"profile-level-id": "42e01f",
-							"level-asymmetry-allowed": 1
-						}
-					}
 				]
 			});
 
diff --git a/webrtc/src/opcodes/Identify.ts b/webrtc/src/opcodes/Identify.ts
index c31870c8..82f327be 100644
--- a/webrtc/src/opcodes/Identify.ts
+++ b/webrtc/src/opcodes/Identify.ts
@@ -5,7 +5,7 @@ import { Server } from "../Server";
 
 export async function onIdentify(this: Server, socket: WebSocket, data: Payload) {
 	var transport = await this.mediasoupRouters[0].createWebRtcTransport({
-		listenIps: [{ ip: "127.0.0.1" }],
+		listenIps: [{ ip: "0.0.0.0", announcedIp: "127.0.0.1" }],
 		enableUdp: true,
 		enableTcp: true,
 		preferUdp: true,
@@ -40,10 +40,9 @@ export async function onIdentify(this: Server, socket: WebSocket, data: Payload)
 	socket.send(JSON.stringify({
 		op: VoiceOPCodes.READY,
 		d: {
+			streams: [],
 			ssrc: 1,
-			ip: "127.0.0.1",
-
-			//@ts-ignore
+			ip: transport.iceCandidates[0].ip,
 			port: transport.iceCandidates[0].port,
 			modes: [
 				"aead_aes256_gcm_rtpsize",
diff --git a/webrtc/src/opcodes/SelectProtocol.ts b/webrtc/src/opcodes/SelectProtocol.ts
index 08335ade..36527a8b 100644
--- a/webrtc/src/opcodes/SelectProtocol.ts
+++ b/webrtc/src/opcodes/SelectProtocol.ts
@@ -68,6 +68,8 @@ import * as sdpTransform from 'sdp-transform';
 	}
 */
 
+var test_hasMadeProducer = false;
+
 export async function onSelectProtocol(this: Server, socket: WebSocket, data: Payload) {
 	const rtpCapabilities = this.mediasoupRouters[0].rtpCapabilities;
 	const codecs = rtpCapabilities.codecs as RtpCodecCapability[];
@@ -85,23 +87,33 @@ export async function onSelectProtocol(this: Server, socket: WebSocket, data: Pa
 			})),
 	*/
 
-	const producer = await transport.produce({
-		kind: "audio",
-		rtpParameters: {
-			mid: "audio",
-			codecs: [{
-				clockRate: 48000,
-				payloadType: 111,
-				mimeType: "audio/opus",
-				channels: 2,
-			}],
-			headerExtensions: res.ext?.map(x => ({
-				id: x.value,
-				uri: x.uri,
-			}))
-		},
-		paused: false,
-	});
+	if (!test_hasMadeProducer) {
+		const producer = await transport.produce({
+			kind: "audio",
+			rtpParameters: {
+				mid: "audio",
+				codecs: [{
+					clockRate: 48000,
+					payloadType: 111,
+					mimeType: "audio/opus",
+					channels: 2,
+				}],
+				headerExtensions: res.ext?.map(x => ({
+					id: x.value,
+					uri: x.uri,
+				}))
+			},
+			paused: false,
+		});
+		
+		const consumer = await transport.consume({
+			producerId: producer.id,
+			paused: false,
+			rtpCapabilities,
+		})
+
+		test_hasMadeProducer = true;
+	}
 
 	socket.send(JSON.stringify({
 		op: VoiceOPCodes.SESSION_DESCRIPTION,