Merge branch 'fix/recvData' into 'main'
Feat: Stream data by stream-id See merge request ayushm99/apl-nuke!1main v1.1.9
commit
3a5defdde4
@ -0,0 +1,50 @@
|
||||
const { v4 } = require('uuid')
|
||||
const crud = require('./crud')
|
||||
|
||||
const connections = {}
|
||||
|
||||
const subscribe = (ws, sid) => {
|
||||
const id = v4()
|
||||
connections[id] = {
|
||||
connection: ws,
|
||||
streamid: sid,
|
||||
}
|
||||
|
||||
ws.send(JSON.stringify({
|
||||
event: 'info',
|
||||
data: 'Welcome to APL Nuke v1.1.0!',
|
||||
}))
|
||||
|
||||
sendInitial(id)
|
||||
|
||||
ws.on('close', () => {
|
||||
delete connections[id]
|
||||
})
|
||||
}
|
||||
|
||||
const cModel = {
|
||||
'events': 'event',
|
||||
'matches': 'matches',
|
||||
'casters': 'casters',
|
||||
'hosts': 'hosts',
|
||||
}
|
||||
|
||||
const recvUpdate = async (channel, data) => {
|
||||
Object.keys(connections).forEach((k) => {
|
||||
sendInitial(k)
|
||||
})
|
||||
}
|
||||
|
||||
const sendInitial = async (id) => {
|
||||
const c = connections[id]
|
||||
const stream = await crud['streams'].getById(c.streamid)
|
||||
c.connection.send(JSON.stringify({
|
||||
event: 'streams:read',
|
||||
data: stream,
|
||||
}))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
subscribe,
|
||||
recvUpdate,
|
||||
}
|
Loading…
Reference in New Issue