Skip to content

Commit 060a4c2

Browse files
authored
refactor: Import WebSocketServer properly (#3290)
Updates the `dht` package’s `WebsocketServer` to correctly use the named `WebSocketServer` export introduced in ws v8+, improving clarity and type consistency. > [!NOTE] > The current `WebSocket.Server` way works as long as we target CJS and not ESM. The new way works for both. ### Changes - Updated `WebsocketServer.ts` (mind the low-key "s") to import the server using the proper `import { WebSocketServer } from 'ws'` syntax, distinguishing it from the WebSocket client type. - Replaced all `WebSocket.Server` type references and instantiations with `WebSocketServer` for consistent and accurate typing.
1 parent 20babce commit 060a4c2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/dht/src/connection/websocket/WebsocketServer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createServer as createHttpServer, Server as HttpServer, IncomingMessage, ServerResponse } from 'http'
22
import { createServer as createHttpsServer, Server as HttpsServer } from 'https'
33
import EventEmitter from 'eventemitter3'
4-
import WebSocket from 'ws'
4+
import WebSocket, { WebSocketServer } from 'ws'
55
import { WebsocketServerConnection } from './WebsocketServerConnection'
66
import { Logger, asAbortable } from '@streamr/utils'
77
import { createSelfSignedCertificate } from '@streamr/autocertifier-client'
@@ -29,7 +29,7 @@ interface Events {
2929
export class WebsocketServer extends EventEmitter<Events> {
3030

3131
private httpServer?: HttpServer | HttpsServer
32-
private wsServer?: WebSocket.Server
32+
private wsServer?: WebSocketServer
3333
private readonly abortController = new AbortController()
3434
private readonly options: WebsocketServerOptions
3535

@@ -154,9 +154,9 @@ export class WebsocketServer extends EventEmitter<Events> {
154154
})
155155
}
156156

157-
private createWsServer(): WebSocket.Server {
157+
private createWsServer(): WebSocketServer {
158158
const maxPayload = this.options.maxMessageSize ?? 1048576
159-
return this.wsServer = new WebSocket.Server({
159+
return this.wsServer = new WebSocketServer({
160160
noServer: true,
161161
maxPayload
162162
})

0 commit comments

Comments
 (0)