-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·43 lines (31 loc) · 950 Bytes
/
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
const express = require("express")
const http = require("http")
const fs = require("fs")
let socketIO = require("socket.io")
let app = express()
let server = http.createServer(app)
let io = socketIO.listen(server)
/*
let canvas = []
for(let y = 0 ; y < 40 ; ++y){
canvas[y] = []
for(let x = 0 ; x < 60 ; ++x){
canvas[y][x] = "white"
}
}
fs.writeFile("Dessin.txt", JSON.stringify(canvas), (err)=>{if(err){console.eror(err)}})
*/
let canvas = JSON.parse( fs.readFileSync("Dessin.txt") )
app.get("/",(req, res)=>{
res.sendFile(__dirname + '/web/index.html')
})
app.use("/folder",express.static("web"))
io.on("connection", (socket)=>{
socket.emit("board", canvas)
socket.on("color", (carre)=>{
canvas[carre.y][carre.x] = carre.color
io.emit("new", carre)
fs.writeFile("Dessin.txt", JSON.stringify(canvas), (err)=>{if(err){console.eror(err)}})
})
})
server.listen(333)