Major code rework
This commit is contained in:
@@ -1,19 +1,17 @@
|
||||
import { Server as WsServer } from 'ws'
|
||||
|
||||
import { consoleError, consoleInfo } from '../helpers/errors'
|
||||
import { DeemixApp } from '../app'
|
||||
import wsModules from './modules'
|
||||
|
||||
// ? Is this needed?
|
||||
// ? https://github.com/websockets/ws#how-to-detect-and-close-broken-connections
|
||||
|
||||
export const registerWebsocket = (wss: WsServer) => {
|
||||
export const registerWebsocket = (wss: WsServer, deemix: DeemixApp) => {
|
||||
wss.on('connection', ws => {
|
||||
ws.on('message', message => {
|
||||
const data = JSON.parse(message.toString())
|
||||
|
||||
wsModules.forEach(module => {
|
||||
if (data.key === module.eventName) {
|
||||
module.cb(data.data, ws, wss)
|
||||
module.cb(data.data, ws, wss, deemix)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Server as WsServer } from 'ws'
|
||||
import { consoleInfo } from '../../helpers/errors'
|
||||
import { cancelAllDownloads } from '../../main'
|
||||
import { DeemixApp } from '../../app'
|
||||
|
||||
const eventName = 'cancelAllDownloads'
|
||||
|
||||
const cb = (_: any, __: any, ___: WsServer) => {
|
||||
cancelAllDownloads()
|
||||
const cb = (_: any, __: any, ___: WsServer, deemix: DeemixApp) => {
|
||||
deemix.cancelAllDownloads()
|
||||
consoleInfo(`Queue cleared`)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Server as WsServer } from 'ws'
|
||||
import { consoleInfo } from '../../helpers/errors'
|
||||
import { clearCompletedDownloads } from '../../main'
|
||||
import { DeemixApp } from '../../app'
|
||||
|
||||
const eventName = 'removeFinishedDownloads'
|
||||
|
||||
const cb = (_: any, __: any, ___: WsServer) => {
|
||||
clearCompletedDownloads()
|
||||
const cb = (_: any, __: any, ___: WsServer, deemix: DeemixApp) => {
|
||||
deemix.clearCompletedDownloads()
|
||||
consoleInfo('Completed downloads cleared')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Server as WsServer } from 'ws'
|
||||
import { consoleInfo } from '../../helpers/errors'
|
||||
import { cancelDownload } from '../../main'
|
||||
import { DeemixApp } from '../../app'
|
||||
|
||||
const eventName = 'removeFromQueue'
|
||||
|
||||
const cb = (data: any, __: any, ___: WsServer) => {
|
||||
cancelDownload(data)
|
||||
const cb = (data: any, __: any, ___: WsServer, deemix: DeemixApp) => {
|
||||
deemix.cancelDownload(data)
|
||||
consoleInfo(`Cancelled ${data}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Server as WsServer } from 'ws'
|
||||
import { consoleInfo } from '../../helpers/errors'
|
||||
import { saveSettings, listener } from '../../main'
|
||||
import { DeemixApp } from '../../app'
|
||||
import { Settings, SpotifySettings } from '../../types'
|
||||
|
||||
const eventName = 'saveSettings'
|
||||
@@ -10,11 +10,11 @@ export interface SaveSettingsData {
|
||||
spotifySettings: SpotifySettings
|
||||
}
|
||||
|
||||
const cb = (data: SaveSettingsData, _: any, __: WsServer) => {
|
||||
const cb = (data: SaveSettingsData, _: any, __: WsServer, deemix: DeemixApp) => {
|
||||
const { settings, spotifySettings } = data
|
||||
saveSettings(settings, spotifySettings)
|
||||
deemix.saveSettings(settings, spotifySettings)
|
||||
consoleInfo('Settings saved')
|
||||
listener.send('updateSettings', { settings, spotifySettings })
|
||||
deemix.listener.send('updateSettings', { settings, spotifySettings })
|
||||
}
|
||||
|
||||
export default { eventName, cb }
|
||||
|
||||
Reference in New Issue
Block a user