-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (46 loc) · 1.38 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
54
55
56
57
58
var express = require("express");
var app = express();
var port = process.env.PORT || 8080;
var socket = require("socket.io");
var server = app.listen(port, function () {
console.log(`listening on port ${port}`);
});
app.set("view engine", "ejs");
app.use(express.static(__dirname));
var io = socket(server);
var count = 0;
io.on("connection", function (socket) {
console.log("Connection made.." + count);
socket.on("clientStateEvent", function (data) {
io.sockets.emit("serverStateEvent", data);
});
socket.on("clientLineEvent", function (data) {
io.sockets.emit("serverLineEvent", data);
});
socket.on("clientEvent", function (data) {
io.sockets.emit("ServerEvent", { data });
});
var clientIds = [];
socket.on("clientPlayerConnected", async () => {
await io.sockets.clients((err, clients) => {
console.log(clients);
clientIds = clients;
});
io.sockets.emit("serverPlayerCount", clientIds.length);
});
socket.on("clientMyVideo", (data) => {
io.sockets.emit("serverMyVideo", data);
});
socket.on("disconnect", () => {
console.log("disconnected");
clientIds.forEach(function reduce(val, i, arr) {
if (val == socket.id) arr.splice(i, 1);
});
console.log(clientIds);
io.sockets.emit("serverPlayerCount", clientIds.length);
});
});
io.on("disconnect", function (socket) {
console.log("disconnectd");
c;
});