diff options
-rw-r--r-- | gateway/src/opcodes/Identify.ts | 2 | ||||
-rw-r--r-- | webrtc/package-lock.json | 134 | ||||
-rw-r--r-- | webrtc/src/Server.ts | 33 | ||||
-rw-r--r-- | webrtc/src/opcodes/Identify.ts | 5 | ||||
-rw-r--r-- | webrtc/src/opcodes/SelectProtocol.ts | 66 | ||||
-rw-r--r-- | webrtc/src/start.ts | 7 |
6 files changed, 201 insertions, 46 deletions
diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index eb15c28f..42b3713c 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -34,6 +34,8 @@ import { Recipient } from "@fosscord/util"; // TODO: check if already identified export async function onIdentify(this: WebSocket, data: Payload) { + console.log(data); + clearTimeout(this.readyTimeout); check.call(this, IdentifySchema, data.d); diff --git a/webrtc/package-lock.json b/webrtc/package-lock.json index afba7e76..d09123ee 100644 --- a/webrtc/package-lock.json +++ b/webrtc/package-lock.json @@ -69,11 +69,24 @@ "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==", "dev": true }, + "node_modules/@types/debug": { + "version": "4.1.7", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.7.tgz", + "integrity": "sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==", + "dependencies": { + "@types/ms": "*" + } + }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=" }, + "node_modules/@types/ms": { + "version": "0.7.31", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", + "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==" + }, "node_modules/@types/node": { "version": "15.6.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz", @@ -86,6 +99,11 @@ "integrity": "sha512-GVO0gnmbyO3Oxm2HdPsYUNcyihZE3GyCY8ysMYHuQGfLhGZq89Nm4lSzULWTzZoyHtg+VO/IdrnxZHPnPSGnAg==", "dev": true }, + "node_modules/@types/uuid": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", + "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==" + }, "node_modules/@types/ws": { "version": "7.4.4", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.4.tgz", @@ -130,6 +148,14 @@ "sprintf-js": "~1.0.2" } }, + "node_modules/awaitqueue": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/awaitqueue/-/awaitqueue-2.3.3.tgz", + "integrity": "sha512-RbzQg6VtPUtyErm55iuQLTrBJ2uihy5BKBOEkyBwv67xm5Fn2o/j+Bz+a5BmfSoe2oZ5dcz9Z3fExS8pL+LLhw==", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -273,6 +299,14 @@ "node": ">=8.0.0" } }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -365,6 +399,48 @@ "url": "https://opencollective.com/mediasoup" } }, + "node_modules/mediasoup-sdp-bridge": { + "version": "3.6.5", + "resolved": "git+ssh://git@github.com/versatica/mediasoup-sdp-bridge.git#b1a40b97f27b3fd218334f40448a61d704877952", + "license": "ISC", + "dependencies": { + "@types/debug": "^4.1.5", + "@types/node": "^14.0.5", + "@types/uuid": "^8.0.0", + "awaitqueue": "^2.1.1", + "debug": "^4.1.1", + "h264-profile-level-id": "^1.0.1", + "sdp-transform": "^2.14.0", + "supports-color": "^7.1.0", + "uuid": "^8.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mediasoup" + }, + "peerDependencies": { + "mediasoup": "^3.5.15" + } + }, + "node_modules/mediasoup-sdp-bridge/node_modules/@types/node": { + "version": "14.18.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.12.tgz", + "integrity": "sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==" + }, + "node_modules/mediasoup-sdp-bridge/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/mediasoup/node_modules/@types/node": { "version": "16.11.19", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.19.tgz", @@ -604,11 +680,24 @@ "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==", "dev": true }, + "@types/debug": { + "version": "4.1.7", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.7.tgz", + "integrity": "sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==", + "requires": { + "@types/ms": "*" + } + }, "@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=" }, + "@types/ms": { + "version": "0.7.31", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", + "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==" + }, "@types/node": { "version": "15.6.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz", @@ -621,6 +710,11 @@ "integrity": "sha512-GVO0gnmbyO3Oxm2HdPsYUNcyihZE3GyCY8ysMYHuQGfLhGZq89Nm4lSzULWTzZoyHtg+VO/IdrnxZHPnPSGnAg==", "dev": true }, + "@types/uuid": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", + "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==" + }, "@types/ws": { "version": "7.4.4", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.4.tgz", @@ -656,6 +750,11 @@ "sprintf-js": "~1.0.2" } }, + "awaitqueue": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/awaitqueue/-/awaitqueue-2.3.3.tgz", + "integrity": "sha512-RbzQg6VtPUtyErm55iuQLTrBJ2uihy5BKBOEkyBwv67xm5Fn2o/j+Bz+a5BmfSoe2oZ5dcz9Z3fExS8pL+LLhw==" + }, "base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -741,6 +840,11 @@ "debug": "^4.1.1" } }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, "ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -809,6 +913,36 @@ } } }, + "mediasoup-sdp-bridge": { + "version": "git+ssh://git@github.com/versatica/mediasoup-sdp-bridge.git#b1a40b97f27b3fd218334f40448a61d704877952", + "from": "git+ssh://git@github.com/versatica/mediasoup-sdp-bridge.git#b1a40b97f27b3fd218334f40448a61d704877952", + "requires": { + "@types/debug": "^4.1.5", + "@types/node": "^14.0.5", + "@types/uuid": "^8.0.0", + "awaitqueue": "^2.1.1", + "debug": "^4.1.1", + "h264-profile-level-id": "^1.0.1", + "sdp-transform": "^2.14.0", + "supports-color": "^7.1.0", + "uuid": "^8.1.0" + }, + "dependencies": { + "@types/node": { + "version": "14.18.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.12.tgz", + "integrity": "sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==" + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, "minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", diff --git a/webrtc/src/Server.ts b/webrtc/src/Server.ts index 42b82c6a..5b76759a 100644 --- a/webrtc/src/Server.ts +++ b/webrtc/src/Server.ts @@ -19,6 +19,8 @@ export class Server { public mediasoupProducers: MediasoupTypes.Producer[] = []; public mediasoupConsumers: MediasoupTypes.Consumer[] = []; + public testUdp = udp.createSocket("udp6"); + constructor() { this.ws = new WebSocketServer({ port, @@ -45,6 +47,12 @@ export class Server { }); }); + // this.testUdp.bind(50001); + // this.testUdp.on("message", (msg, rinfo) => { + // if (msg[0] === 0 && msg[1] === 1 && msg[2] === 0) { //idk stun? + + // } + // }) } async listen(): Promise<void> { @@ -59,7 +67,7 @@ export class Server { async createWorkers(): Promise<void> { const numWorkers = 1; for (let i = 0; i < numWorkers; i++) { - const worker = await mediasoup.createWorker({ logLevel: "debug" }); + const worker = await mediasoup.createWorker({ logLevel: "debug", logTags: ["dtls", "ice", "info", "message", "bwe"] }); if (!worker) return; worker.on("died", () => { @@ -76,10 +84,24 @@ export class Server { await transport.enableTraceEvent(); - transport.on("connect", () => { - console.log("transport connect") + transport.on('dtlsstatechange', (dtlsstate) => { + console.log(dtlsstate); }) + transport.on("sctpstatechange", (sctpstate) => { + console.log(sctpstate) + }) + + router.observer.on("newrtpobserver", (rtpObserver: MediasoupTypes.RtpObserver) => { + console.log("new RTP observer created [id:%s]", rtpObserver.id); + + // rtpObserver.observer.on("") + }) + + transport.on("connect", () => { + console.log("transport connect"); + }); + transport.observer.on("newproducer", (producer: MediasoupTypes.Producer) => { console.log("new producer created [id:%s]", producer.id); @@ -114,9 +136,10 @@ export class Server { kind: "audio", mimeType: "audio/opus", clockRate: 48000, - channels: 2 + channels: 2, + preferredPayloadType: 111, }, - ] + ], }); this.mediasoupWorkers.push(worker); diff --git a/webrtc/src/opcodes/Identify.ts b/webrtc/src/opcodes/Identify.ts index 9baa16e3..82a82dc1 100644 --- a/webrtc/src/opcodes/Identify.ts +++ b/webrtc/src/opcodes/Identify.ts @@ -34,11 +34,8 @@ export async function onIdentify(this: Server, socket: WebSocket, data: Identify return socket.close(CLOSECODES.Invalid_intent); var transport = this.mediasoupTransports[0] || await this.mediasoupRouters[0].createWebRtcTransport({ - listenIps: [{ ip: "10.22.64.69" }], + listenIps: [{ ip: "10.22.64.63" }], enableUdp: true, - enableTcp: true, - preferUdp: true, - enableSctp: true, }); socket.send(JSON.stringify({ diff --git a/webrtc/src/opcodes/SelectProtocol.ts b/webrtc/src/opcodes/SelectProtocol.ts index dc9d2b88..98899caf 100644 --- a/webrtc/src/opcodes/SelectProtocol.ts +++ b/webrtc/src/opcodes/SelectProtocol.ts @@ -6,7 +6,6 @@ import * as mediasoup from "mediasoup"; import { RtpCodecCapability } from "mediasoup/node/lib/RtpParameters"; import * as sdpTransform from 'sdp-transform'; - /* Sent by client: @@ -68,31 +67,8 @@ import * as sdpTransform from 'sdp-transform'; "rtc_connection_id": "3faa0b80-b3e2-4bae-b291-273801fbb7ab" } } - -Sent by server: - -{ - "op": 4, - "d": { - "video_codec": "H264", - "sdp": " - m=audio 50001 ICE/SDP - a=fingerprint:sha-256 4A:79:94:16:44:3F:BD:05:41:5A:C7:20:F3:12:54:70:00:73:5D:33:00:2D:2C:80:9B:39:E1:9F:2D:A7:49:87 - c=IN IP4 109.200.214.158 - a=rtcp:50001 - a=ice-ufrag:CLzn - a=ice-pwd:qEmIcNwigd07mu46Ok0XCh - a=fingerprint:sha-256 4A:79:94:16:44:3F:BD:05:41:5A:C7:20:F3:12:54:70:00:73:5D:33:00:2D:2C:80:9B:39:E1:9F:2D:A7:49:87 - a=candidate:1 1 UDP 4261412862 109.200.214.158 50001 typ host - ", - "media_session_id": "807955cb953e98c5b90704cf048e81ec", - "audio_codec": "opus" - } -} - */ - export async function onSelectProtocol(this: Server, socket: WebSocket, data: Payload) { const rtpCapabilities = this.mediasoupRouters[0].rtpCapabilities; const codecs = rtpCapabilities.codecs as RtpCodecCapability[]; @@ -124,27 +100,49 @@ export async function onSelectProtocol(this: Server, socket: WebSocket, data: Pa 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, + // }); + + /* + { + "video_codec":"H264", + "sdp": + " + m=audio 50010 ICE/SDP + a=fingerprint:sha-256 4A:79:94:16:44:3F:BD:05:41:5A:C7:20:F3:12:54:70:00:73:5D:33:00:2D:2C:80:9B:39:E1:9F:2D:A7:49:87 + c=IN IP4 109.200.214.158 + a=rtcp:50010 + a=ice-ufrag:+npq + a=ice-pwd:+jf7jAesMeHHby43FRqWTy + a=fingerprint:sha-256 4A:79:94:16:44:3F:BD:05:41:5A:C7:20:F3:12:54:70:00:73:5D:33:00:2D:2C:80:9B:39:E1:9F:2D:A7:49:87 + a=candidate:1 1 UDP 4261412862 109.200.214.158 50010 typ host", + "media_session_id":"59265c94fa13e313492c372c4c8da801 + ", + "audio_codec":"opus" + } + */ socket.send(JSON.stringify({ op: VoiceOPCodes.SESSION_DESCRIPTION, d: { video_codec: videoCodec?.mimeType?.substring(6) || undefined, - mode: "xsalsa20_poly1305_lite", + // 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 IPV4 ${transport.iceCandidates[0].ip}\n` - + `a=rtcp: ${transport.iceCandidates[0].port}\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-1 ${transport.dtlsParameters.fingerprints[0].value}\n` - + `a=candidate:1 1 ${transport.iceCandidates[0].protocol} ${transport.iceCandidates[0].priority} ${transport.iceCandidates[0].ip} ${transport.iceCandidates[0].port} typ ${transport.iceCandidates[0].type}` + + `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}` } })); } \ No newline at end of file diff --git a/webrtc/src/start.ts b/webrtc/src/start.ts index 98f06ad5..f902ec1b 100644 --- a/webrtc/src/start.ts +++ b/webrtc/src/start.ts @@ -1,9 +1,10 @@ -//testing -process.env.DATABASE = "../bundle/database.db"; - import { config } from "dotenv"; config(); +//testing +process.env.DATABASE = "../bundle/database.db"; +process.env.DEBUG = "mediasoup*" + import { Server } from "./Server"; const server = new Server(); |