-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
62 lines (53 loc) · 1.54 KB
/
Copy pathmain.js
File metadata and controls
62 lines (53 loc) · 1.54 KB
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
59
60
61
62
var express = require("express");
var app = express();
var server = require("http").createServer(app);
var io = require("socket.io")(server);
var AuthedClient = null;
var CurrentVideo = {link:"anime.mp4", subs:[]};
var secretKey = "test123";
app.use(express.static("bower_components"));
app.use(express.static("static"));
io.on("connection", function(client){
console.log("New client! Their ip is: "+ client.request.connection.remoteAddress);
client.on("join", function(data){
client.emit("link", CurrentVideo);
});
//Add the client to AuthedClient if he logs in
client.on("login", function(data){
if(data == secretKey){
console.log("User logged in!");
AuthedClient = client;
client.emit("loginSuccess","true");
client.broadcast.emit("logout", true);
}else{
console.log("User failed to log in :(")
client.emit("loginSuccess","false");
}
});
//Log the client out
client.on("logout", function(data){
client.emit("logout", false);
AuthedClient = null;
});
//Sync the time
client.on("sync",function(data){
if(client == AuthedClient){
var timeObj = data;
client.broadcast.emit("sync", timeObj);
}
});
//Sync pause
client.on("pause", function(data){
if(client == AuthedClient){
client.broadcast.emit("pause", data);
}
});
//Send the link to clients
client.on("link",function(data){
if(client == AuthedClient){
CurrentVideo = data;
io.emit("link", data);
}
});
});
server.listen(3001);