-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.mjs
36 lines (28 loc) · 952 Bytes
/
server.mjs
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
import geckos, { iceServers } from '@geckos.io/server'
import http from 'http'
import express from 'express'
const port = 3000
const app = express()
const server = http.createServer(app)
const io = geckos({
iceServers: process.env.NODE_ENV === 'production' ? iceServers : [],
portRange: {
min: process.env.PORT_RANGE_MIN ? parseInt(process.env.PORT_RANGE_MIN) : 10000,
max: process.env.PORT_RANGE_MAX ? parseInt(process.env.PORT_RANGE_MAX) : 10007,
},
cors: { allowAuthorization: true },
})
app.use("/", express.static('public'))
io.addServer(server)
io.onConnection((channel) => {
channel.onDisconnect(() => {
console.log(`${channel.id} got disconnected`)
})
channel.emit('chat message', `Welcome to the chat ${channel.id}!`)
channel.on('chat message', (data) => {
channel.room.emit('chat message', data)
})
})
server.listen(port, () => {
console.log(`Example app listening on http://localhost:${port}/`)
})