-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (46 loc) · 1.26 KB
/
app.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
47
48
49
50
51
52
53
const express = require("express")
const { createServer } = require ('http')
const { Server } = require('socket.io')
const path = require('path')
const reload = require('reload')
const PORT = process.env.PORT||3000
const app = express();
const server = createServer(app);
const io = new Server(server);
app.use(express.static(path.join('public')));
//app.use(express.static('home'))
let codes = "console.log('Welcome to code Editor');"
io.on('connection', (socket) => {
//io.emit("connectedId")
socket.on("code",code=>{
codes = code
console.log(code);
io.emit("code",code)
})
socket.on("edit",(id,code,userId) =>{
io.emit("edit",id,code,userId)
})
socket.on("add",(id,sel) =>{
io.emit("add",id,sel)
})
socket.on("remove",(id,sel) =>{
io.emit("remove",id,sel)
})
socket.on("run",()=>{
io.emit("run")
})
socket.on("mousemove",(x,y,uid)=>{
io.emit("mousemove",x,y,uid)
})
socket.on("paste",(code)=>{
io.emit("paste",code)
})
io.emit("codeFile",codes)
});
reload(app).then(function (reloadReturned) {
server.listen(PORT, () => {
console.log('server running at http://localhost:'+PORT);
});
}).catch(function (err) {
console.error('Reload could not start, could not start server/sample app', err)
})