-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.ts
57 lines (48 loc) · 1.46 KB
/
vite.config.ts
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
47
48
49
50
51
52
53
54
55
56
57
import { sveltekit } from "@sveltejs/kit/vite";
import { Server } from "socket.io";
import type { PluginOption, UserConfig } from "vite";
const socketioServer: PluginOption = {
name: "socketioServer",
configureServer(server) {
if (server.httpServer) {
const io = new Server(server.httpServer);
io.on("connection", (socket) => {
socket.on("join-room", async (roomID) => {
socket.join(roomID);
const users = await io.in(roomID).allSockets();
socket.to(roomID).emit("user-joined", socket.id);
socket.emit("users", [...users]);
});
socket.on("offer", (payload) => {
io.to(payload.target).emit("offer", payload);
});
socket.on("answer", (payload) => {
io.to(payload.target).emit("answer", payload);
});
socket.on("ice-candidate", (incoming) => {
io.to(incoming.target).emit("ice-candidate", incoming.candidate);
});
socket.on("end-call", (data) => {
io.to(data.to).emit("end-call", data);
});
socket.on("disconnecting", (reason) => {
for (const room of socket.rooms) {
if (room !== socket.id) {
socket.to(room).emit("user-left", socket.id);
}
}
});
});
}
},
};
const config: UserConfig = {
plugins: [sveltekit(), socketioServer],
server: {
port: 3000,
},
preview: {
port: 3000,
},
};
export default config;