-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (33 loc) · 1.02 KB
/
server.js
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
const express = require('express');
const { createServer } = require('node:http');
const { join } = require('node:path');
const { Server } = require('socket.io');
const app = express();
const server = createServer(app);
const io = new Server(server,{
cors: {
origin: '*',
}
});
app.use(express.static(join(__dirname, 'public')));
io.on('connection', (socket) => {
console.log('a user connected', socket.id);
socket.on('offer', (offer) => {
// console.log('offer', offer);
socket.broadcast.emit('offer', offer);
});
socket.on('answer', (answer) => {
console.log('answer', answer);
socket.broadcast.emit('answer', answer);
});
socket.on('candidate', (candidate) => {
console.log('candidate', candidate);
socket.broadcast.emit('candidate', candidate);
});
socket.on('disconnect', () => {
console.log('user disconnected', socket.id);
});
});
server.listen(3000, () => {
console.log('server running at http://localhost:3000');
});