-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (45 loc) · 1.13 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
const express = require("express");
var app = express();
const cors = require("cors");
app.use(cors());
const http = require("http");
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server, {
cors: {
origin: "http://localhost:3000",
},
});
function setUpCamera(socket) {
// redis_s.on('message',(channel,message)=>{
// if(channel=='camera'){
// socket.emit('data', "data:image/jpeg;base64," + message.toString("base64"));
// }
// })
}
function handleDisconnect(socket) {
socket.on("disconnect", () => {
console.log("user disconnected");
});
}
async function onConnection(socket) {
console.log("a user connected");
setUpCamera(socket);
handleDisconnect(socket);
socket.on("record", (msg) => {
if (msg === "start") {
console.log("start");
}
if (msg === "stop") {
console.log("record");
}
});
}
function setUpSocket() {
io.on("connection", onConnection);
}
setUpSocket();
//TODO we are currently serving react from local host 3000 on windows?
server.listen(3000, "0.0.0.0", () => {
console.log("listening on *:3000");
});