summary refs log tree commit diff
path: root/webrtc/src/opcodes/Resume.ts
blob: 856b550c3ebf992f15e42e02f95b85b4636bfe5f (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
import { CLOSECODES, WebSocket } from "@fosscord/gateway";
import { Payload } from "./index";
import { Server } from "../Server"
import { Guild, Session, VoiceOPCodes } from "@fosscord/util";

export async function onResume(this: Server, socket: WebSocket, data: Payload) {
	const session = await Session.findOneOrFail(
		{ session_id: data.d.session_id, },
		{
			where: { user_id: data.d.user_id },
			relations: ["user"]
		}
	);
	const user = session.user;
	const guild = await Guild.findOneOrFail({ id: data.d.server_id }, { relations: ["members"] });

	if (!guild.members.find(x => x.id === user.id))
		return socket.close(CLOSECODES.Invalid_intent);

	socket.send(JSON.stringify({
		op: VoiceOPCodes.RESUMED,
		d: null,
	}))
}