@@ -24,18 +24,15 @@ export interface ReconnectingWebSocketOptions {
2424 maxBackoffMs ?: number ;
2525 jitterFactor ?: number ;
2626 /** Callback invoked when a refreshable certificate error is detected. Returns true if refresh succeeded. */
27- onCertificateExpired ? : ( ) => Promise < boolean > ;
27+ onCertificateRefreshNeeded : ( ) => Promise < boolean > ;
2828}
2929
3030export class ReconnectingWebSocket <
3131 TData = unknown ,
3232> implements UnidirectionalStream < TData > {
3333 readonly #socketFactory: SocketFactory < TData > ;
3434 readonly #logger: Logger ;
35- readonly #options: Required <
36- Omit < ReconnectingWebSocketOptions , "onCertificateExpired" >
37- > &
38- Pick < ReconnectingWebSocketOptions , "onCertificateExpired" > ;
35+ readonly #options: Required < ReconnectingWebSocketOptions > ;
3936 readonly #eventHandlers: {
4037 [ K in WebSocketEventType ] : Set < EventHandler < TData , K > > ;
4138 } = {
@@ -59,7 +56,7 @@ export class ReconnectingWebSocket<
5956 private constructor (
6057 socketFactory : SocketFactory < TData > ,
6158 logger : Logger ,
62- options : ReconnectingWebSocketOptions = { } ,
59+ options : ReconnectingWebSocketOptions ,
6360 onDispose ?: ( ) => void ,
6461 ) {
6562 this . #socketFactory = socketFactory ;
@@ -68,7 +65,7 @@ export class ReconnectingWebSocket<
6865 initialBackoffMs : options . initialBackoffMs ?? 250 ,
6966 maxBackoffMs : options . maxBackoffMs ?? 30000 ,
7067 jitterFactor : options . jitterFactor ?? 0.1 ,
71- onCertificateExpired : options . onCertificateExpired ,
68+ onCertificateRefreshNeeded : options . onCertificateRefreshNeeded ,
7269 } ;
7370 this . #backoffMs = this . #options. initialBackoffMs ;
7471 this . #onDispose = onDispose ;
@@ -77,7 +74,7 @@ export class ReconnectingWebSocket<
7774 static async create < TData > (
7875 socketFactory : SocketFactory < TData > ,
7976 logger : Logger ,
80- options : ReconnectingWebSocketOptions = { } ,
77+ options : ReconnectingWebSocketOptions ,
8178 onDispose ?: ( ) => void ,
8279 ) : Promise < ReconnectingWebSocket < TData > > {
8380 const instance = new ReconnectingWebSocket < TData > (
@@ -296,14 +293,10 @@ export class ReconnectingWebSocket<
296293
297294 /**
298295 * Attempt to refresh certificates and return true if refresh succeeded.
299- * Returns false if no callback configured or refresh failed.
300296 */
301297 private async attemptCertificateRefresh ( ) : Promise < boolean > {
302- if ( ! this . #options. onCertificateExpired ) {
303- return false ;
304- }
305298 try {
306- return await this . #options. onCertificateExpired ( ) ;
299+ return await this . #options. onCertificateRefreshNeeded ( ) ;
307300 } catch ( refreshError ) {
308301 this . #logger. error ( "Error during certificate refresh:" , refreshError ) ;
309302 return false ;
0 commit comments