Skip to content

Commit 1c5b741

Browse files
committed
Add UUID for connection ID
1 parent 5d067b9 commit 1c5b741

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"express": "^4.19.2",
14-
"socket.io": "^4.7.5"
14+
"socket.io": "^4.7.5",
15+
"uuid": "^9.0.1"
1516
}
1617
}

server.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { Server } = require('socket.io');
22
const express = require('express');
33
const { createServer } = require('http');
44
const cors = require('cors');
5+
const uuid = require('uuid');
56

67
const app = express();
78
app.use(cors());
@@ -14,14 +15,14 @@ app.get('/', (req, res) => {
1415
const httpServer = createServer(app);
1516
const io = new Server(httpServer, {
1617
cors: {
18+
// origin: '*',
1719
origin: ['https://cnotv-multi-game.netlify.app/', 'http://localhost:4000/'],
1820
methods: ['GET', 'POST'],
1921
},
2022
});
2123

2224
io.on('connection', (socket) => {
2325
const count = io.engine.clientsCount;
24-
const uuid = require('uuid');
2526

2627
io.engine.generateId = (req) => {
2728
return uuid.v4(); // must be unique across all Socket.IO servers
@@ -30,7 +31,7 @@ io.on('connection', (socket) => {
3031
console.log(`New connection: ${socket.id} - Total clients: ${count}`);
3132

3233
io.engine.on('connection_error', (err) => {
33-
console.log(err);
34+
console.log(err.message);
3435
});
3536
});
3637

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@ [email protected]:
571571
resolved "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
572572
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==
573573

574+
uuid@^9.0.1:
575+
version "9.0.1"
576+
resolved "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
577+
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==
578+
574579
vary@^1, vary@~1.1.2:
575580
version "1.1.2"
576581
resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"

0 commit comments

Comments
 (0)