-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (21 loc) · 714 Bytes
/
index.js
File metadata and controls
33 lines (21 loc) · 714 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
29
30
31
32
33
"use strict";
const express = require('express')
, app = express()
, server = require('http').Server(app)
, io = require('socket.io')(server)
, port = Number(process.env.PORT) || 5000
app.use(express.static('lib'))
app.use(express.static('node_modules/ace-builds/src-noconflict'))
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
})
let nextUserId = 1
io.on('connection', function (socket) {
var userId = nextUserId++;
console.log('connection - assigning id ' + userId);
socket.emit('init', { id: userId })
socket.on('message', op => { socket.broadcast.emit('message', op) })
})
server.listen(port, function () {
console.log('listening on *:' + port);
})