forked from miguelgrinberg/python-socketio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiddle.js
More file actions
28 lines (22 loc) · 838 Bytes
/
fiddle.js
File metadata and controls
28 lines (22 loc) · 838 Bytes
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
const express = require('express');
const { createServer } = require("http");
const { Server } = require("socket.io");
const { instrument } = require("@socket.io/admin-ui");
const app = express();
const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: { origin: 'https://admin.socket.io', credentials: true },
});
const port = process.env.PORT || 5000;
app.use(express.static(__dirname + '/fiddle_public'));
io.on('connection', socket => {
console.log(`connect auth=${JSON.stringify(socket.handshake.auth)} sid=${socket.id}`);
socket.emit('hello', 1, '2', {
hello: 'you'
});
socket.on('disconnect', () => {
console.log(`disconnect ${socket.id}`);
});
});
instrument(io, {auth: false, mode: 'development'});
httpServer.listen(port, () => console.log(`server listening on port ${port}`));