summary refs log tree commit diff
path: root/webrtc/src/Server.ts
blob: 6591691cbf8e1080225c732434b5ba3114469533 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Server as WebSocketServer } from "ws";
import { Config, db } from "@fosscord/util";
import mediasoup from "mediasoup";

var port = Number(process.env.PORT);
if (isNaN(port)) port = 3004;

export class Server {
	public ws: WebSocketServer;
	public turn: any;

	constructor() {
		this.ws = new WebSocketServer({
			port,
			maxPayload: 4096,
		});
		this.ws.on("connection", (socket) => {
			socket.on("message", (message) => {
				socket.emit(
					JSON.stringify({
						op: 2,
						d: {
							ssrc: 1,
							ip: "127.0.0.1",
							port: 3004,
							modes: [
								"xsalsa20_poly1305",
								"xsalsa20_poly1305_suffix",
								"xsalsa20_poly1305_lite",
							],
							heartbeat_interval: 1,
						},
					})
				);
			});
		});
	}

	async listen(): Promise<void> {
		// @ts-ignore
		await (db as Promise<Connection>);
		await Config.init();
		console.log("[DB] connected");
		console.log(`[WebRTC] online on 0.0.0.0:${port}`);
	}
}