Refactor server websocket dependency tree to fix jest tests

This commit is contained in:
Andrew Kingston 2022-09-13 09:54:25 +01:00
parent 3d57010a10
commit 00cbf6cf37
3 changed files with 13 additions and 6 deletions

View File

@ -10,7 +10,7 @@ import {
} from "@budibase/backend-core/objectStore"
import { PluginType, FileType, PluginSource } from "@budibase/types"
import env from "../../../environment"
import { ClientAppSocket } from "../../../app"
import { ClientAppSocket } from "../../../websocket"
export async function getPlugins(type?: PluginType) {
const db = getGlobalDB()

View File

@ -32,7 +32,7 @@ import * as migrations from "./migrations"
import { events, installation, tenancy } from "@budibase/backend-core"
import { createAdminUser, getChecklist } from "./utilities/workerRequests"
import { watch } from "./watch"
import { Websocket } from "./websocket"
import { initialise as initialiseWebsockets } from "./websocket"
const app = new Koa()
@ -77,9 +77,7 @@ if (env.isProd()) {
const server = http.createServer(app.callback())
destroyable(server)
// initialise websockets
export const ClientAppSocket = new Websocket(server, "/socket/client")
initialiseWebsockets(server)
let shuttingDown = false,
errCode = 0

View File

@ -1,7 +1,7 @@
import { Server } from "socket.io"
import http from "http"
export class Websocket {
class Websocket {
socketServer: Server
constructor(server: http.Server, path: string) {
@ -15,3 +15,12 @@ export class Websocket {
this.socketServer.sockets.emit(event, payload)
}
}
// Likely to be more socket instances in future
let ClientAppSocket: Websocket
export const initialise = (server: http.Server) => {
ClientAppSocket = new Websocket(server, "/socket/client")
}
export { ClientAppSocket }