Implemented simple queue structure
This commit is contained in:
@@ -6,14 +6,6 @@ import wsModules from './modules'
|
||||
// ? Is this needed?
|
||||
// ? https://github.com/websockets/ws#how-to-detect-and-close-broken-connections
|
||||
|
||||
export const broadcast = function(wss:WsServer, key:string, data:any) {
|
||||
wss.clients.forEach(client => {
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
client.send(JSON.stringify({key, data}))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const registerWebsocket = (wss: WsServer) => {
|
||||
wss.on('connection', ws => {
|
||||
ws.on('message', (message)=>{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Server as WsServer } from 'ws'
|
||||
import { consoleInfo } from '../../helpers/errors'
|
||||
import { saveSettings } from '../../main'
|
||||
import { broadcast } from '../index'
|
||||
import { saveSettings, listener } from '../../main'
|
||||
|
||||
const eventName = 'saveSettings'
|
||||
|
||||
@@ -9,7 +8,7 @@ const cb = (data: any, ws: any, wss: WsServer) => {
|
||||
const {settings, spotifySettings} = data
|
||||
saveSettings(settings)
|
||||
consoleInfo('Settings saved')
|
||||
broadcast(wss, 'updateSettings', {settings, spotifySettings})
|
||||
listener.send('updateSettings', {settings, spotifySettings})
|
||||
}
|
||||
|
||||
export default { eventName, cb }
|
||||
|
||||
Reference in New Issue
Block a user