Skip to content

Commit

Permalink
allow passing websocket server options (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
janthurau authored Sep 19, 2024
1 parent 524f2b6 commit 76692bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/server/src/Hocuspocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class Hocuspocus {
async listen(
portOrCallback: number | ((data: onListenPayload) => Promise<any>) | null = null,
callback: any = null,
websocketOptions: WebSocket.ServerOptions = {},
): Promise<Hocuspocus> {
if (typeof portOrCallback === 'number') {
this.configuration.port = portOrCallback
Expand All @@ -172,7 +173,7 @@ export class Hocuspocus {
})
}

this.server = new HocuspocusServer(this)
this.server = new HocuspocusServer(this, websocketOptions)

if (this.configuration.stopOnSignals) {
const signalHandler = async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/Server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
createServer, IncomingMessage, Server as HTTPServer, ServerResponse,
} from 'http'
import WebSocket, { WebSocketServer } from 'ws'
import WebSocket, { ServerOptions, WebSocketServer } from 'ws'
import { Hocuspocus } from './Hocuspocus.js'

export class Server {
Expand All @@ -11,10 +11,10 @@ export class Server {

hocuspocus: Hocuspocus

constructor(hocuspocus: Hocuspocus) {
constructor(hocuspocus: Hocuspocus, websocketOptions: ServerOptions = {}) {
this.hocuspocus = hocuspocus
this.httpServer = createServer(this.requestHandler)
this.webSocketServer = new WebSocketServer({ noServer: true })
this.webSocketServer = new WebSocketServer({ noServer: true, ...websocketOptions })

this.setupWebsocketConnection()
this.setupHttpUpgrade()
Expand Down

0 comments on commit 76692bc

Please sign in to comment.