-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (32 loc) · 1.08 KB
/
index.js
File metadata and controls
44 lines (32 loc) · 1.08 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
const express = require('express');
const socketIo = require("socket.io");
const Yt = require("./modules");
if (process.argv[2] === undefined) {
throw new Error('link argument is required. try node index.js "<youtube live chat url>"');
}
const url = process.argv[2]
const yt = new Yt(url);
const app = express();
const port = 8000;
const server = app.listen(port, () => console.log(`listening on ${port}`));
const io = socketIo(server, {'transports': ['websocket', 'polling']});
//Whenever someone connects this gets executed
io.on('connection', async (socket) => {
console.log('a user connected');
//Whenever someone disconnects this piece of code executed
socket.on('disconnect', () => {
console.log('a user disconnected');
});
socket.on("selected", selected => {
io.emit("selected", selected);
});
socket.on("bannerShow", value => {
io.emit("bannerShow", value);
});
socket.on("style", value => {
io.emit("style", value);
});
});
yt.fetch(list => {
io.emit("live_chat", list);
});