-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
37 lines (32 loc) · 955 Bytes
/
Copy pathapp.js
File metadata and controls
37 lines (32 loc) · 955 Bytes
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
// server.js
const express = require("express")
const app = express()
const estimateFunctions = require("./src/models/estimateFunctions")
const redisClient = require("./src/redis/redis-client")
const http = require("http").createServer(app)
const io = require("socket.io")(http)
const CronJob = require("cron").CronJob
new CronJob(
"*/15 * 6-24,0-1 * * *",
function() {
estimateFunctions.fetchEstimates(redisClient, io)
},
null,
true,
"America/New_York"
)
io.on("connection", function(client) {
// once a client has connected, we expect to get a ping from them saying what room they want to join
client.on("room", function(route) {
client.join(route)
redisClient
.getAsync(route)
.then(estimate => io.sockets.in(route).emit("estimate", estimate))
})
client.on("leaveRoom", function(route) {
client.leave(route)
})
})
const port = 8000
io.listen(port)
console.log("Socket.io listening on port", port)