-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (29 loc) · 1015 Bytes
/
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
const express = require('express');
const http = require('http');
const { Server } = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = new Server(server);
// Serve static files (for the HTML page)
app.use(express.static(__dirname + '/public'));
const socketIdAdmin = "asdASdSaDasd"
// Socket.io connection
io.on('connection', (socket) => {
console.log('a user connected');
socket.on('message', (msg) => {
console.log('Message received:', msg);
// Broadcast the message to all clients
io.emit('message', msg);
});
socket.on('mouse', (msg) => {
const data = { ...msg, socketId: socket.id }; // Attach the socket ID to the message
io.emit('mouse', data); // Broadcast the message to all clients
});
socket.on('disconnect', () => {
console.log('user disconnected');
});
});
// Start the server
server.listen(9010, () => {
console.log('Server is running on http://localhost:3000');
});