summary refs log tree commit diff
path: root/webrtc/src/opcodes/SelectProtocol.ts
diff options
context:
space:
mode:
Diffstat (limited to 'webrtc/src/opcodes/SelectProtocol.ts')
-rw-r--r--webrtc/src/opcodes/SelectProtocol.ts116
1 files changed, 71 insertions, 45 deletions
diff --git a/webrtc/src/opcodes/SelectProtocol.ts b/webrtc/src/opcodes/SelectProtocol.ts
index 98899caf..29b9c1f9 100644
--- a/webrtc/src/opcodes/SelectProtocol.ts
+++ b/webrtc/src/opcodes/SelectProtocol.ts
@@ -5,6 +5,7 @@ import { Server } from "../Server";
 import * as mediasoup from "mediasoup";
 import { RtpCodecCapability } from "mediasoup/node/lib/RtpParameters";
 import * as sdpTransform from 'sdp-transform';
+import sodium from "libsodium-wrappers";
 
 /*
 
@@ -70,42 +71,66 @@ import * as sdpTransform from 'sdp-transform';
 */
 
 export async function onSelectProtocol(this: Server, socket: WebSocket, data: Payload) {
-	const rtpCapabilities = this.mediasoupRouters[0].rtpCapabilities;
-	const codecs = rtpCapabilities.codecs as RtpCodecCapability[];
+	// const rtpCapabilities = this.mediasoupRouters[0].rtpCapabilities;
+	// const codecs = rtpCapabilities.codecs as RtpCodecCapability[];
 
-	const transport = this.mediasoupTransports[0];	//whatever
+	if (data.d.sdp) {
+		// const transport = this.mediasoupTransports[0];	//whatever
 
-	const res = sdpTransform.parse(data.d.sdp);
+		// const res = sdpTransform.parse(data.d.sdp);
 
-	const videoCodec = this.mediasoupRouters[0].rtpCapabilities.codecs!.find((x: any) => x.kind === "video");
-	const audioCodec = this.mediasoupRouters[0].rtpCapabilities.codecs!.find((x: any) => x.kind === "audio");
+		// const videoCodec = this.mediasoupRouters[0].rtpCapabilities.codecs!.find((x: any) => x.kind === "video");
+		// const audioCodec = this.mediasoupRouters[0].rtpCapabilities.codecs!.find((x: any) => x.kind === "audio");
 
-	const producer = this.mediasoupProducers[0] || await transport.produce({
-		kind: "audio",
-		rtpParameters: {
-			mid: "audio",
-			codecs: [{
-				clockRate: audioCodec!.clockRate,
-				payloadType: audioCodec!.preferredPayloadType as number,
-				mimeType: audioCodec!.mimeType,
-				channels: audioCodec?.channels,
-			}],
-			headerExtensions: res.ext?.map(x => ({
-				id: x.value,
-				uri: x.uri,
-			})),
-		},
-		paused: false,
-	});
+		// const producer = this.mediasoupProducers[0] || await transport.produce({
+		// 	kind: "audio",
+		// 	rtpParameters: {
+		// 		mid: "audio",
+		// 		codecs: [{
+		// 			clockRate: audioCodec!.clockRate,
+		// 			payloadType: audioCodec!.preferredPayloadType as number,
+		// 			mimeType: audioCodec!.mimeType,
+		// 			channels: audioCodec?.channels,
+		// 		}],
+		// 		headerExtensions: res.ext?.map(x => ({
+		// 			id: x.value,
+		// 			uri: x.uri,
+		// 		})),
+		// 	},
+		// 	paused: false,
+		// });
 
-	console.log("can consume: " + this.mediasoupRouters[0].canConsume({ producerId: producer.id, rtpCapabilities: rtpCapabilities }));
+		// console.log("can consume: " + this.mediasoupRouters[0].canConsume({ producerId: producer.id, rtpCapabilities: rtpCapabilities }));
 
-	// const consumer = this.mediasoupConsumers[0] || await transport.consume({
-	// 	producerId: producer.id,
-	// 	paused: false,
-	// 	rtpCapabilities,
-	// });
+		// // const consumer = this.mediasoupConsumers[0] || await transport.consume({
+		// // 	producerId: producer.id,
+		// // 	paused: false,
+		// // 	rtpCapabilities,
+		// // });
 
+		// socket.send(JSON.stringify({
+		// 	op: VoiceOPCodes.SESSION_DESCRIPTION,
+		// 	d: {
+		// 		video_codec: videoCodec?.mimeType?.substring(6) || undefined,
+		// 		// mode: "xsalsa20_poly1305_lite",
+		// 		media_session_id: transport.id,
+		// 		audio_codec: audioCodec?.mimeType.substring(6),
+		// 		secret_key: sodium.from_hex("724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed").buffer,
+		// 		sdp: `m=audio ${50001} ICE/SDP\n`
+		// 			+ `a=fingerprint:sha-256 ${transport.dtlsParameters.fingerprints.find(x => x.algorithm === "sha-256")?.value}\n`
+		// 			+ `c=IN IP4 ${transport.iceCandidates[0].ip}\n`
+		// 			+ `t=0 0\n`
+		// 			+ `a=ice-lite\n`
+		// 			+ `a=rtcp-mux\n`
+		// 			+ `a=rtcp:${50001}\n`
+		// 			+ `a=ice-ufrag:${transport.iceParameters.usernameFragment}\n`
+		// 			+ `a=ice-pwd:${transport.iceParameters.password}\n`
+		// 			+ `a=fingerprint:sha-256 ${transport.dtlsParameters.fingerprints.find(x => x.algorithm === "sha-256")?.value}\n`
+		// 			+ `a=candidate:1 1 ${transport.iceCandidates[0].protocol.toUpperCase()} ${transport.iceCandidates[0].priority} ${transport.iceCandidates[0].ip} ${50001} typ ${transport.iceCandidates[0].type}`
+		// 	}
+		// }));
+		return;
+	}
 	/*
 		{
 			"video_codec":"H264",
@@ -125,24 +150,25 @@ export async function onSelectProtocol(this: Server, socket: WebSocket, data: Pa
 		}
 	*/
 
+
+	/*
+		{
+			"video_codec": "H264",
+			"secret_key": [36, 80, 96, 53, 95, 149, 253, 16, 137, 186, 238, 222, 251, 180, 94, 150, 112, 137, 192, 109, 69, 79, 218, 111, 217, 197, 56, 74, 18, 41, 51, 140],
+			"mode": "aead_aes256_gcm_rtpsize",
+			"media_session_id": "797575a97a87b63e81e2399348b97ad1",
+			"audio_codec": "opus"
+		};
+	*/
+
 	socket.send(JSON.stringify({
-		op: VoiceOPCodes.SESSION_DESCRIPTION,
+		op:VoiceOPCodes.SESSION_DESCRIPTION,
 		d: {
-			video_codec: videoCodec?.mimeType?.substring(6) || undefined,
-			// mode: "xsalsa20_poly1305_lite",
-			media_session_id: transport.id,
-			audio_codec: audioCodec?.mimeType.substring(6),
-			sdp: `m=audio ${transport.iceCandidates[0].port} ICE/SDP\n`
-				+ `a=fingerprint:sha-256 ${transport.dtlsParameters.fingerprints.find(x => x.algorithm === "sha-256")?.value}\n`
-				+ `c=IN IP4 ${transport.iceCandidates[0].ip}\n`
-				+ `t=0 0\n`
-				+ `a=ice-lite\n`
-				+ `a=rtcp-mux\n`
-				+ `a=rtcp:${transport.iceCandidates[0].port}\n`
-				+ `a=ice-ufrag:${transport.iceParameters.usernameFragment}\n`
-				+ `a=ice-pwd:${transport.iceParameters.password}\n`
-				+ `a=fingerprint:sha-256 ${transport.dtlsParameters.fingerprints.find(x => x.algorithm === "sha-256")?.value}\n`
-				+ `a=candidate:1 1 ${transport.iceCandidates[0].protocol.toUpperCase()} ${transport.iceCandidates[0].priority} ${transport.iceCandidates[0].ip} ${transport.iceCandidates[0].port} typ ${transport.iceCandidates[0].type}`
+			video_codec: "H264",
+			secret_key: [...sodium.from_hex("724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed")],
+			mode: "aead_aes256_gcm_rtpsize",
+			media_session_id: "blah blah blah",
+			audio_codec: "opus",
 		}
 	}));
 }
\ No newline at end of file