forked from vimlesh1975/teleprompter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
86 lines (66 loc) · 2.32 KB
/
server.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// server.js
const express = require('express');
const next = require('next');
const http = require('http');
const socketIO = require('socket.io');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(async () => {
const server = express();
const httpServer = http.createServer(server);
const io = socketIO(httpServer);
const shuttle = require('shuttle-control-usb');
shuttle.on('connected', (deviceInfo) => {
console.log('Connected to ' + deviceInfo.name);
});
shuttle.on('buttondown', data => {
io.emit('buttondown1', data);
});
shuttle.on('disconnected', data => {
console.log(data);
});
shuttle.on('shuttle', data => {
io.emit('shuttle1', data);
});
shuttle.on('jog-dir', (data1) => {
io.emit('jog-dir1', data1);
});
shuttle.start();
io.on('connection', (socket) => {
console.log('Socket Client connected', socket.id);
socket.on('ServerConnectionStatus', (data) => {
// console.log('Received from API ::', data);
io.emit('ServerConnectionStatus2', data);
});
//from scroll page in caspar start
socket.on('setCurrentStoryNumber', (data) => {
io.emit('setCurrentStoryNumber2', data);
});
//from scroll page in caspar End
//webrtc code starts
socket.on('offer', (data) => {
socket.broadcast.emit('offer', data);
});
socket.on('answer', (data) => {
socket.broadcast.emit('answer', data);
});
socket.on('candidate', (data) => {
socket.broadcast.emit('candidate', data);
});
//webrtc code ends
// Handle disconnection
socket.on('disconnect', () => {
console.log('User disconnected:', socket.id);
socket.removeAllListeners();
socket.removeAllListeners('ServerConnectionStatus');
socket.removeAllListeners("connect");
socket.removeAllListeners("setCurrentStoryNumber");
});
});
server.all('*', (req, res) => handle(req, res));
const PORT = process.env.PORT || 3000;
httpServer.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
});