11import type { TLSConfig } from '../network/types' ;
22import type { IncomingMessage , ServerResponse } from 'http' ;
3+ import type tls from 'tls' ;
34import https from 'https' ;
45import { startStop , status } from '@matrixai/async-init' ;
56import Logger from '@matrixai/logger' ;
@@ -24,7 +25,6 @@ class WebSocketServer extends EventTarget {
2425 * @param obj
2526 * @param obj.connectionCallback -
2627 * @param obj.tlsConfig - TLSConfig containing the private key and cert chain used for TLS.
27- * @param obj.basePath - Directory path used for storing temp cert files for starting the `uWebsocket` server.
2828 * @param obj.host - Listen address to bind to.
2929 * @param obj.port - Listen port to bind to.
3030 * @param obj.maxIdleTimeout - Timeout time for when the connection is cleaned up after no activity.
@@ -38,7 +38,6 @@ class WebSocketServer extends EventTarget {
3838 static async createWebSocketServer ( {
3939 connectionCallback,
4040 tlsConfig,
41- basePath,
4241 host,
4342 port,
4443 maxIdleTimeout = 120 ,
@@ -48,7 +47,6 @@ class WebSocketServer extends EventTarget {
4847 } : {
4948 connectionCallback : ConnectionCallback ;
5049 tlsConfig : TLSConfig ;
51- basePath ?: string ;
5250 host ?: string ;
5351 port ?: number ;
5452 maxIdleTimeout ?: number ;
@@ -66,7 +64,6 @@ class WebSocketServer extends EventTarget {
6664 await wsServer . start ( {
6765 connectionCallback,
6866 tlsConfig,
69- basePath,
7067 host,
7168 port,
7269 } ) ;
@@ -106,7 +103,6 @@ class WebSocketServer extends EventTarget {
106103 connectionCallback,
107104 } : {
108105 tlsConfig : TLSConfig ;
109- basePath ?: string ;
110106 host ?: string ;
111107 port ?: number ;
112108 connectionCallback ?: ConnectionCallback ;
@@ -212,6 +208,15 @@ class WebSocketServer extends EventTarget {
212208 return this . _host ;
213209 }
214210
211+ @startStop . ready ( new webSocketErrors . ErrorWebSocketServerNotRunning ( ) )
212+ public setTlsConfig ( tlsConfig : TLSConfig ) : void {
213+ const tlsServer = this . server as tls . Server ;
214+ tlsServer . setSecureContext ( {
215+ key : tlsConfig . keyPrivatePem ,
216+ cert : tlsConfig . certChainPem ,
217+ } ) ;
218+ }
219+
215220 /**
216221 * Handles the creation of the `ReadableWritablePair` and provides it to the
217222 * StreamPair handler.
0 commit comments