Skip to content

Commit

Permalink
refactor: websocket servers instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Sep 22, 2022
1 parent 1a6c2fe commit 4788e04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/ServerlessOffline.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ export default class ServerlessOffline {
this.#lambda,
)

await this.#webSocket.createServer()

this.#webSocket.create(events)

await this.#webSocket.start()
Expand Down
22 changes: 19 additions & 3 deletions src/events/websocket/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,32 @@ import WebSocketServer from './WebSocketServer.js'
export default class WebSocket {
#httpServer = null

#lambda = null

#options = null

#serverless = null

#webSocketServer = null

constructor(serverless, options, lambda) {
const webSocketClients = new WebSocketClients(serverless, options, lambda)
this.#lambda = lambda
this.#options = options
this.#serverless = serverless
}

async createServer() {
const webSocketClients = new WebSocketClients(
this.#serverless,
this.#options,
this.#lambda,
)

this.#httpServer = new HttpServer(options, webSocketClients)
this.#httpServer = new HttpServer(this.#options, webSocketClients)

// share server
this.#webSocketServer = new WebSocketServer(
options,
this.#options,
webSocketClients,
this.#httpServer.server,
)
Expand Down

0 comments on commit 4788e04

Please sign in to comment.