File tree 2 files changed +21
-5
lines changed
packages/transport-websockets
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -341,20 +341,20 @@ export class WebSocketListener extends TypedEventEmitter<ListenerEvents> impleme
341
341
}
342
342
343
343
getAddrs ( ) : Multiaddr [ ] {
344
+ if ( this . listeningMultiaddr == null ) {
345
+ throw new Error ( 'Listener is not ready yet' )
346
+ }
347
+
344
348
const address = this . server . address ( )
345
349
346
350
if ( address == null ) {
347
- throw new Error ( 'Listener is not ready yet' )
351
+ return [ ]
348
352
}
349
353
350
354
if ( typeof address === 'string' ) {
351
355
throw new Error ( 'Wrong address type received - expected AddressInfo, got string - are you trying to listen on a unix socket?' )
352
356
}
353
357
354
- if ( this . listeningMultiaddr == null ) {
355
- throw new Error ( 'Listener is not ready yet' )
356
- }
357
-
358
358
const options = this . listeningMultiaddr . toOptions ( )
359
359
const multiaddrs : Multiaddr [ ] = [ ]
360
360
Original file line number Diff line number Diff line change @@ -73,6 +73,22 @@ describe('listen', () => {
73
73
void listener . listen ( ma )
74
74
} )
75
75
76
+ it ( 'should return an empty address list when `getAddrs` called before listening has finished' , async ( ) => {
77
+ listener = ws . createListener ( { upgrader } )
78
+
79
+ void listener . listen ( ma )
80
+
81
+ // call getAddrs before sockets have opened
82
+ expect ( listener . getAddrs ( ) ) . to . be . empty ( )
83
+ } )
84
+
85
+ it ( 'should throw when `.getAddrs` called before `.listen`' , async ( ) => {
86
+ listener = ws . createListener ( { upgrader } )
87
+
88
+ // call getAddrs before sockets have opened
89
+ expect ( ( ) => listener . getAddrs ( ) ) . to . throw ( / n o t r e a d y / )
90
+ } )
91
+
76
92
it ( 'should error on starting two listeners on same address' , async ( ) => {
77
93
listener = ws . createListener ( { upgrader } )
78
94
const dumbServer = http . createServer ( )
You can’t perform that action at this time.
0 commit comments