summary refs log tree commit diff
path: root/webrtc/src/Server.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-03-07 22:57:37 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-03-07 22:57:37 +1100
commite731a369e56fc02a667b9b28043ff23ea6c433be (patch)
tree7c34bbd157850d3681e8462472792d4ebae39f67 /webrtc/src/Server.ts
parentaugh (diff)
downloadserver-e731a369e56fc02a667b9b28043ff23ea6c433be.tar.xz
VOICE CONNECTS!!! Dtls stuck on "connecting" state + currently no way to edit/inspect packets received or use own packet format in mediasoup ( fork? )
Diffstat (limited to 'webrtc/src/Server.ts')
-rw-r--r--webrtc/src/Server.ts23
1 files changed, 16 insertions, 7 deletions
diff --git a/webrtc/src/Server.ts b/webrtc/src/Server.ts
index 1d18d6d1..42b82c6a 100644
--- a/webrtc/src/Server.ts
+++ b/webrtc/src/Server.ts
@@ -6,7 +6,7 @@ import { setHeartbeat } from "./util";
 import * as mediasoup from "mediasoup";
 import { types as MediasoupTypes } from "mediasoup";
 
-import Net from "net";
+import udp from "dgram";
 
 var port = Number(process.env.PORT);
 if (isNaN(port)) port = 3004;
@@ -16,6 +16,8 @@ export class Server {
 	public mediasoupWorkers: MediasoupTypes.Worker[] = [];
 	public mediasoupRouters: MediasoupTypes.Router[] = [];
 	public mediasoupTransports: MediasoupTypes.WebRtcTransport[] = [];
+	public mediasoupProducers: MediasoupTypes.Producer[] = [];
+	public mediasoupConsumers: MediasoupTypes.Consumer[] = [];
 
 	constructor() {
 		this.ws = new WebSocketServer({
@@ -28,8 +30,6 @@ export class Server {
 			socket.on("message", async (message: string) => {
 				const payload: Payload = JSON.parse(message);
 
-				// console.log(payload);
-
 				if (OPCodeHandlers[payload.op])
 					try {
 						await OPCodeHandlers[payload.op].call(this, socket, payload);
@@ -44,6 +44,7 @@ export class Server {
 				}
 			});
 		});
+
 	}
 
 	async listen(): Promise<void> {
@@ -73,18 +74,26 @@ export class Server {
 				router.observer.on("newtransport", async (transport: MediasoupTypes.WebRtcTransport) => {
 					console.log("new transport created [id:%s]", transport.id);
 
-					transport.observer.on("sctpstatechange", (state) => {
-						console.log(state)
-					});
-
 					await transport.enableTraceEvent();
 
+					transport.on("connect", () => {
+						console.log("transport connect")
+					})
+
 					transport.observer.on("newproducer", (producer: MediasoupTypes.Producer) => {
 						console.log("new producer created [id:%s]", producer.id);
+
+						this.mediasoupProducers.push(producer);
 					});
 
 					transport.observer.on("newconsumer", (consumer: MediasoupTypes.Consumer) => {
 						console.log("new consumer created [id:%s]", consumer.id);
+
+						this.mediasoupConsumers.push(consumer);
+
+						consumer.on("rtp", (rtpPacket) => {
+							console.log(rtpPacket);
+						});
 					});
 
 					transport.observer.on("newdataproducer", (dataProducer) => {