more fuckery
This commit is contained in:
		
							parent
							
								
									aa0357e060
								
							
						
					
					
						commit
						7c87f8d60a
					
				
							
								
								
									
										14
									
								
								webrtc/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										14
									
								
								webrtc/package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -9,6 +9,7 @@ | |||||||
| 			"version": "1.0.0", | 			"version": "1.0.0", | ||||||
| 			"license": "ISC", | 			"license": "ISC", | ||||||
| 			"dependencies": { | 			"dependencies": { | ||||||
|  | 				"dotenv": "^12.0.4", | ||||||
| 				"mediasoup": "^3.9.5", | 				"mediasoup": "^3.9.5", | ||||||
| 				"node-turn": "^0.0.6", | 				"node-turn": "^0.0.6", | ||||||
| 				"tsconfig-paths": "^3.12.0", | 				"tsconfig-paths": "^3.12.0", | ||||||
| @ -210,6 +211,14 @@ | |||||||
| 				"node": ">=0.3.1" | 				"node": ">=0.3.1" | ||||||
| 			} | 			} | ||||||
| 		}, | 		}, | ||||||
|  | 		"node_modules/dotenv": { | ||||||
|  | 			"version": "12.0.4", | ||||||
|  | 			"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-12.0.4.tgz", | ||||||
|  | 			"integrity": "sha512-oWdqbSywffzH1l4WXKPHWA0TWYpqp7IyLfqjipT4upoIFS0HPMqtNotykQpD4iIg0BqtNmdgPCh2WMvMt7yTiw==", | ||||||
|  | 			"engines": { | ||||||
|  | 				"node": ">=12" | ||||||
|  | 			} | ||||||
|  | 		}, | ||||||
| 		"node_modules/esprima": { | 		"node_modules/esprima": { | ||||||
| 			"version": "4.0.1", | 			"version": "4.0.1", | ||||||
| 			"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", | 			"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", | ||||||
| @ -672,6 +681,11 @@ | |||||||
| 			"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", | 			"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", | ||||||
| 			"dev": true | 			"dev": true | ||||||
| 		}, | 		}, | ||||||
|  | 		"dotenv": { | ||||||
|  | 			"version": "12.0.4", | ||||||
|  | 			"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-12.0.4.tgz", | ||||||
|  | 			"integrity": "sha512-oWdqbSywffzH1l4WXKPHWA0TWYpqp7IyLfqjipT4upoIFS0HPMqtNotykQpD4iIg0BqtNmdgPCh2WMvMt7yTiw==" | ||||||
|  | 		}, | ||||||
| 		"esprima": { | 		"esprima": { | ||||||
| 			"version": "4.0.1", | 			"version": "4.0.1", | ||||||
| 			"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", | 			"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", | ||||||
|  | |||||||
| @ -18,6 +18,7 @@ | |||||||
| 		"typescript": "^4.3.2" | 		"typescript": "^4.3.2" | ||||||
| 	}, | 	}, | ||||||
| 	"dependencies": { | 	"dependencies": { | ||||||
|  | 		"dotenv": "^12.0.4", | ||||||
| 		"mediasoup": "^3.9.5", | 		"mediasoup": "^3.9.5", | ||||||
| 		"node-turn": "^0.0.6", | 		"node-turn": "^0.0.6", | ||||||
| 		"tsconfig-paths": "^3.12.0", | 		"tsconfig-paths": "^3.12.0", | ||||||
|  | |||||||
| @ -54,21 +54,32 @@ export class Server { | |||||||
| 			}); | 			}); | ||||||
| 
 | 
 | ||||||
| 			worker.observer.on("newrouter", async (router: MediasoupTypes.Router) => { | 			worker.observer.on("newrouter", async (router: MediasoupTypes.Router) => { | ||||||
| 				console.log("new router"); | 				console.log("new router created [id:%s]", router.id); | ||||||
| 
 | 
 | ||||||
| 				this.mediasoupRouters.push(router); | 				this.mediasoupRouters.push(router); | ||||||
| 
 | 
 | ||||||
| 				router.observer.on("newtransport", (transport: MediasoupTypes.Transport) => { | 				router.observer.on("newtransport", async (transport: MediasoupTypes.Transport) => { | ||||||
| 					console.log("new transport"); | 					console.log("new transport created [id:%s]", transport.id); | ||||||
|  | 
 | ||||||
|  | 					await transport.enableTraceEvent(); | ||||||
|  | 
 | ||||||
|  | 					transport.observer.on("newproducer", (producer: MediasoupTypes.Producer) => { | ||||||
|  | 						console.log("new producer created [id:%s]", producer.id); | ||||||
|  | 					}); | ||||||
|  | 
 | ||||||
|  | 					transport.observer.on("newconsumer", (consumer: MediasoupTypes.Consumer) => { | ||||||
|  | 						console.log("new consumer created [id:%s]", consumer.id); | ||||||
|  | 					}); | ||||||
|  | 
 | ||||||
|  | 					transport.observer.on("newdataproducer", (dataProducer) => { | ||||||
|  | 						console.log("new data producer created [id:%s]", dataProducer.id); | ||||||
|  | 					}); | ||||||
|  | 
 | ||||||
|  | 					transport.on("trace", (trace) => { | ||||||
|  | 						console.log(trace); | ||||||
|  | 					}); | ||||||
| 
 | 
 | ||||||
| 					this.mediasoupTransports.push(transport); | 					this.mediasoupTransports.push(transport); | ||||||
| 				}) |  | ||||||
| 
 |  | ||||||
| 				await router.createWebRtcTransport({ |  | ||||||
| 					listenIps: [{ ip: "127.0.0.1" }], |  | ||||||
| 					enableUdp: true, |  | ||||||
| 					enableTcp: true, |  | ||||||
| 					preferUdp: true |  | ||||||
| 				}); | 				}); | ||||||
| 			}); | 			}); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,4 +3,8 @@ import { Payload } from "./index"; | |||||||
| import { Server } from "../Server" | import { Server } from "../Server" | ||||||
| 
 | 
 | ||||||
| export async function onConnect(this: Server, socket: WebSocket, data: Payload) { | export async function onConnect(this: Server, socket: WebSocket, data: Payload) { | ||||||
|  | 	socket.send(JSON.stringify({ | ||||||
|  | 		op: 15, | ||||||
|  | 		d: { any: 100 } | ||||||
|  | 	})) | ||||||
| } | } | ||||||
| @ -1,9 +1,67 @@ | |||||||
| import { WebSocket } from "@fosscord/gateway"; | import { WebSocket } from "@fosscord/gateway"; | ||||||
| import { Payload } from "./index" | import { Payload } from "./index"; | ||||||
| import { VoiceOPCodes } from "@fosscord/util"; | import { VoiceOPCodes } from "@fosscord/util"; | ||||||
| import { Server } from "../Server" | import { Server } from "../Server"; | ||||||
|  | import * as mediasoup from "mediasoup"; | ||||||
|  | import { RtpCodecCapability } from "mediasoup/node/lib/RtpParameters"; | ||||||
|  | 
 | ||||||
|  | const test = "extmap-allow-mixed\na=ice-ufrag:ilWh\na=ice-pwd:Mx7TDnPKXDnTgYWC+qMaqspQ\na=ice-options:trickle\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\na=rtpmap:111 opus/48000/2\na=extmap:14 urn:ietf:params:rtp-hdrext:toffset\na=extmap:13 urn:3gpp:video-orientation\na=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\na=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\na=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space\na=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\na=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\na=rtpmap:96 VP8/90000\na=rtpmap:97 rtx/90000"; | ||||||
| 
 | 
 | ||||||
| export async function onIdentify(this: Server, socket: WebSocket, data: Payload) { | export async function onIdentify(this: Server, socket: WebSocket, data: Payload) { | ||||||
|  | 	var transport = await this.mediasoupRouters[0].createWebRtcTransport({ | ||||||
|  | 		listenIps: [{ ip: "127.0.0.1" }], | ||||||
|  | 		enableUdp: true, | ||||||
|  | 		enableTcp: true, | ||||||
|  | 		preferUdp: true, | ||||||
|  | 	}); | ||||||
|  | 
 | ||||||
|  | 	const rtpCapabilities = this.mediasoupRouters[0].rtpCapabilities; | ||||||
|  | 	const codecs = rtpCapabilities.codecs as RtpCodecCapability[]; | ||||||
|  | 
 | ||||||
|  | 	var producer = await transport.produce( | ||||||
|  | 		{ | ||||||
|  | 			kind: "audio", | ||||||
|  | 			rtpParameters: | ||||||
|  | 			{ | ||||||
|  | 				mid: "1", | ||||||
|  | 				codecs: codecs.filter(x => x.kind === "audio").map((x: RtpCodecCapability) => { | ||||||
|  | 					return { | ||||||
|  | 						mimeType: x.mimeType, | ||||||
|  | 						kind: x.kind, | ||||||
|  | 						clockRate: x.clockRate, | ||||||
|  | 						channels: x.channels, | ||||||
|  | 						payloadType: x.preferredPayloadType as number | ||||||
|  | 					}; | ||||||
|  | 				}), | ||||||
|  | 				headerExtensions: test.split("\na=").map((x, i) => ({ | ||||||
|  | 					id: i + 1, | ||||||
|  | 					uri: x, | ||||||
|  | 				})) | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  | 
 | ||||||
|  | 	const consumer = await transport.consume( | ||||||
|  | 		{ | ||||||
|  | 			producerId: producer.id, | ||||||
|  | 			rtpCapabilities: | ||||||
|  | 			{ | ||||||
|  | 				codecs: codecs.filter(x => x.kind === "audio").map((x: RtpCodecCapability) => { | ||||||
|  | 					return { | ||||||
|  | 						mimeType: x.mimeType, | ||||||
|  | 						kind: x.kind, | ||||||
|  | 						clockRate: x.clockRate, | ||||||
|  | 						channels: x.channels, | ||||||
|  | 						payloadType: x.preferredPayloadType as number | ||||||
|  | 					}; | ||||||
|  | 				}), | ||||||
|  | 				headerExtensions: test.split("\na=").map((x, i) => ({ | ||||||
|  | 					kind: "audio", | ||||||
|  | 					preferredId: i + 1, | ||||||
|  | 					uri: x, | ||||||
|  | 				})) | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  | 
 | ||||||
| 	socket.send(JSON.stringify({ | 	socket.send(JSON.stringify({ | ||||||
| 		op: VoiceOPCodes.READY, | 		op: VoiceOPCodes.READY, | ||||||
| 		d: { | 		d: { | ||||||
| @ -11,11 +69,11 @@ export async function onIdentify(this: Server, socket: WebSocket, data: Payload) | |||||||
| 			ip: "127.0.0.1", | 			ip: "127.0.0.1", | ||||||
| 
 | 
 | ||||||
| 			//@ts-ignore
 | 			//@ts-ignore
 | ||||||
| 			port: this.mediasoupTransports[0].iceCandidates.port, | 			port: transport.iceCandidates[0].port, | ||||||
| 			modes: [ | 			modes: [ | ||||||
| 				"xsalsa20_poly1305", | 				"xsalsa20_poly1305", | ||||||
| 				"xsalsa20_poly1305_suffix", | 				// "xsalsa20_poly1305_suffix",
 | ||||||
| 				"xsalsa20_poly1305_lite", | 				// "xsalsa20_poly1305_lite",
 | ||||||
| 			], | 			], | ||||||
| 			heartbeat_interval: 1, | 			heartbeat_interval: 1, | ||||||
| 		}, | 		}, | ||||||
|  | |||||||
| @ -1,17 +1,79 @@ | |||||||
| import { WebSocket } from "@fosscord/gateway"; | import { WebSocket } from "@fosscord/gateway"; | ||||||
| import { Payload } from "./index"; | import { Payload } from "./index"; | ||||||
| import { VoiceOPCodes } from "@fosscord/util"; | import { VoiceOPCodes } from "@fosscord/util"; | ||||||
| import { Server } from "../Server" | import { Server } from "../Server"; | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  | 	{ | ||||||
|  | 	op: 1, | ||||||
|  | 	d: { | ||||||
|  | 		protocol: "webrtc", | ||||||
|  | 		data: " | ||||||
|  | 			a=extmap-allow-mixed | ||||||
|  | 			a=ice-ufrag:ilWh | ||||||
|  | 			a=ice-pwd:Mx7TDnPKXDnTgYWC+qMaqspQ | ||||||
|  | 			a=ice-options:trickle | ||||||
|  | 			a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level | ||||||
|  | 			a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
 | ||||||
|  | 			a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
 | ||||||
|  | 			a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid | ||||||
|  | 			a=rtpmap:111 opus/48000/2 | ||||||
|  | 			a=extmap:14 urn:ietf:params:rtp-hdrext:toffset | ||||||
|  | 			a=extmap:13 urn:3gpp:video-orientation | ||||||
|  | 			a=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
 | ||||||
|  | 			a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
 | ||||||
|  | 			a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
 | ||||||
|  | 			a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space
 | ||||||
|  | 			a=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id | ||||||
|  | 			a=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id | ||||||
|  | 			a=rtpmap:96 VP8/90000 | ||||||
|  | 			a=rtpmap:97 rtx/90000 | ||||||
|  | 		", | ||||||
|  | 		sdp: "same data as in d.data? also not documented by discord", | ||||||
|  | 		codecs: [ | ||||||
|  | 		{ | ||||||
|  | 			name: "opus", | ||||||
|  | 			type: "audio", | ||||||
|  | 			priority: 1000, | ||||||
|  | 			payload_type: 111, | ||||||
|  | 			rtx_payload_type: null, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "H264", | ||||||
|  | 			type: "video", | ||||||
|  | 			priority: 1000, | ||||||
|  | 			payload_type: 102, | ||||||
|  | 			rtx_payload_type: 121, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "VP8", | ||||||
|  | 			type: "video", | ||||||
|  | 			priority: 2000, | ||||||
|  | 			payload_type: 96, | ||||||
|  | 			rtx_payload_type: 97, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "VP9", | ||||||
|  | 			type: "video", | ||||||
|  | 			priority: 3000, | ||||||
|  | 			payload_type: 98, | ||||||
|  | 			rtx_payload_type: 99, | ||||||
|  | 		}, | ||||||
|  | 		], | ||||||
|  | 		rtc_connection_id: "b3c8628a-edb5-49ae-b860-ab0d2842b104", | ||||||
|  | 	}, | ||||||
|  | 	} | ||||||
|  | */ | ||||||
| 
 | 
 | ||||||
| export async function onSelectProtocol(this: Server, socket: WebSocket, data: Payload) { | export async function onSelectProtocol(this: Server, socket: WebSocket, data: Payload) { | ||||||
| 	socket.send(JSON.stringify({ | 	socket.send(JSON.stringify({ | ||||||
| 		op: VoiceOPCodes.SESSION_DESCRIPTION, | 		op: VoiceOPCodes.SESSION_DESCRIPTION, | ||||||
| 		d: { | 		d: { | ||||||
| 			video_codec: "H264", | 			video_codec: data.d.codecs.find((x: any) => x.type === "video").name, | ||||||
| 			secret_key: new Array(32).fill(null).map(x => Math.random() * 256), | 			secret_key: new Array(32).fill(null).map(x => Math.random() * 256), | ||||||
| 			mode: "aead_aes256_gcm_rtpsize", | 			mode: "xsalsa20_poly1305", | ||||||
| 			media_session_id: this.mediasoupTransports[0].id, | 			media_session_id: this.mediasoupTransports[0].id, | ||||||
| 			audio_codec: "opus", | 			audio_codec: data.d.codecs.find((x: any) => x.type === "audio").name, | ||||||
| 		} | 		} | ||||||
| 	})); | 	})); | ||||||
| } | } | ||||||
| @ -1,4 +1,10 @@ | |||||||
|  | import { config } from "dotenv"; | ||||||
|  | config(); | ||||||
|  | 
 | ||||||
| import { Server } from "./Server"; | import { Server } from "./Server"; | ||||||
| 
 | 
 | ||||||
|  | //testing
 | ||||||
|  | process.env.DATABASE = "../bundle/database.db"; | ||||||
|  | 
 | ||||||
| const server = new Server(); | const server = new Server(); | ||||||
| server.listen(); | server.listen(); | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Madeline
						Madeline