@@ -7,8 +7,8 @@ import WebSocket from 'ws';
77import { Timer } from '@matrixai/timer' ;
88import { Validator } from 'ip-num' ;
99import WebSocketStream from './WebSocketStream' ;
10- import * as clientRpcUtils from './utils' ;
11- import * as clientRPCErrors from './errors' ;
10+ import * as webSocketUtils from './utils' ;
11+ import * as webSocketErrors from './errors' ;
1212import { promise } from '../utils' ;
1313
1414const timeoutSymbol = Symbol ( 'TimedOutSymbol' ) ;
@@ -68,7 +68,7 @@ class WebSocketClient {
6868 } else if ( Validator . isValidIPv6String ( host ) [ 0 ] ) {
6969 this . host = `[${ host } ]` ;
7070 } else {
71- throw new clientRPCErrors . ErrorClientInvalidHost ( ) ;
71+ throw new webSocketErrors . ErrorClientInvalidHost ( ) ;
7272 }
7373 }
7474
@@ -85,7 +85,7 @@ class WebSocketClient {
8585 this . logger . info ( `Destroyed ${ this . constructor . name } ` ) ;
8686 }
8787
88- @createDestroy . ready ( new clientRPCErrors . ErrorClientDestroyed ( ) )
88+ @createDestroy . ready ( new webSocketErrors . ErrorClientDestroyed ( ) )
8989 public async stopConnections ( ) {
9090 for ( const activeConnection of this . activeConnections ) {
9191 activeConnection . end ( ) ;
@@ -95,7 +95,7 @@ class WebSocketClient {
9595 }
9696 }
9797
98- @createDestroy . ready ( new clientRPCErrors . ErrorClientDestroyed ( ) )
98+ @createDestroy . ready ( new webSocketErrors . ErrorClientDestroyed ( ) )
9999 public async startConnection ( {
100100 timeoutTimer,
101101 } : {
@@ -119,7 +119,7 @@ class WebSocketClient {
119119 // Handle connection failure
120120 const openErrorHandler = ( e ) => {
121121 connectProm . rejectP (
122- new clientRPCErrors . ErrorClientConnectionFailed ( undefined , {
122+ new webSocketErrors . ErrorClientConnectionFailed ( undefined , {
123123 cause : e ,
124124 } ) ,
125125 ) ;
@@ -129,10 +129,10 @@ class WebSocketClient {
129129 ws . once ( 'upgrade' , async ( request ) => {
130130 const tlsSocket = request . socket as TLSSocket ;
131131 const peerCert = tlsSocket . getPeerCertificate ( true ) ;
132- clientRpcUtils
132+ webSocketUtils
133133 . verifyServerCertificateChain (
134134 this . expectedNodeIds ,
135- clientRpcUtils . detailedToCertChain ( peerCert ) ,
135+ webSocketUtils . detailedToCertChain ( peerCert ) ,
136136 )
137137 . then ( authenticateProm . resolveP , authenticateProm . rejectP ) ;
138138 } ) ;
@@ -154,7 +154,7 @@ class WebSocketClient {
154154 await Promise . all ( [ authenticateProm . p , connectProm . p ] ) ,
155155 ] ) ;
156156 if ( result === timeoutSymbol ) {
157- throw new clientRPCErrors . ErrorClientConnectionTimedOut ( ) ;
157+ throw new webSocketErrors . ErrorClientConnectionTimedOut ( ) ;
158158 }
159159 } catch ( e ) {
160160 // Clean up
@@ -244,7 +244,7 @@ class WebSocketStreamClientInternal extends WebSocketStream {
244244 readableLogger . debug (
245245 `Closed early, ${ code } , ${ reason . toString ( ) } ` ,
246246 ) ;
247- const e = new clientRPCErrors . ErrorClientConnectionEndedEarly ( ) ;
247+ const e = new webSocketErrors . ErrorClientConnectionEndedEarly ( ) ;
248248 this . signalReadableEnd ( e ) ;
249249 controller . error ( e ) ;
250250 }
@@ -289,7 +289,7 @@ class WebSocketStreamClientInternal extends WebSocketStream {
289289 ws . once ( 'close' , ( code , reason ) => {
290290 if ( ! this . writableEnded_ ) {
291291 writableLogger . debug ( `Closed early, ${ code } , ${ reason . toString ( ) } ` ) ;
292- const e = new clientRPCErrors . ErrorClientConnectionEndedEarly ( ) ;
292+ const e = new webSocketErrors . ErrorClientConnectionEndedEarly ( ) ;
293293 this . signalWritableEnd ( e ) ;
294294 controller . error ( e ) ;
295295 }
@@ -304,9 +304,9 @@ class WebSocketStreamClientInternal extends WebSocketStream {
304304 ws . close ( ) ;
305305 }
306306 } ,
307- abort : ( ) => {
307+ abort : ( reason ) => {
308308 writableLogger . debug ( 'Aborted' ) ;
309- this . signalWritableEnd ( Error ( 'TMP ABORTED' ) ) ;
309+ this . signalWritableEnd ( reason ) ;
310310 if ( this . readableEnded_ ) {
311311 writableLogger . debug ( 'Closing socket' ) ;
312312 ws . close ( ) ;
@@ -321,7 +321,7 @@ class WebSocketStreamClientInternal extends WebSocketStream {
321321 // Opting to debug message here and not log an error, sending
322322 // failure is common if we send before the close event.
323323 writableLogger . debug ( 'failed to send' ) ;
324- const err = new clientRPCErrors . ErrorClientConnectionEndedEarly (
324+ const err = new webSocketErrors . ErrorClientConnectionEndedEarly (
325325 undefined ,
326326 {
327327 cause : e ,
@@ -356,7 +356,9 @@ class WebSocketStreamClientInternal extends WebSocketStream {
356356 logger . debug ( 'WebSocket closed' ) ;
357357 const err =
358358 code !== 1000
359- ? Error ( `TMP WebSocket ended with code ${ code } , ${ reason . toString ( ) } ` )
359+ ? new webSocketErrors . ErrorClientConnectionEndedEarly (
360+ `ended with code ${ code } , ${ reason . toString ( ) } ` ,
361+ )
360362 : undefined ;
361363 this . signalWebSocketEnd ( err ) ;
362364 logger . debug ( 'Cleaning up timers' ) ;
@@ -367,7 +369,7 @@ class WebSocketStreamClientInternal extends WebSocketStream {
367369 }
368370
369371 end ( ) : void {
370- this . ws . close ( 4001 , 'TMP ENDING CONNECTION ' ) ;
372+ this . ws . close ( 4001 , 'Ending connection ' ) ;
371373 }
372374}
373375
0 commit comments