Refactor server websocket dependency tree to fix jest tests
This commit is contained in:
parent
be15aff40f
commit
4c301e962f
3 changed files with 13 additions and 6 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in a new issue