diff --git a/types/websocket/index.d.ts b/types/websocket/index.d.ts index 006d94800f..f67a5da142 100644 --- a/types/websocket/index.d.ts +++ b/types/websocket/index.d.ts @@ -571,6 +571,12 @@ declare class client extends events.EventEmitter { connect(requestUrl: url.Url, protocols?: string, origin?: string, headers?: object, extraRequestOptions?: http.RequestOptions): void; connect(requestUrl: string, protocols?: string, origin?: string, headers?: object, extraRequestOptions?: http.RequestOptions): void; + /** + * Will cancel an in-progress connection request before either the `connect` event or the `connectFailed` event has been emitted. + * If the `connect` or `connectFailed` event has already been emitted, calling `abort()` will do nothing. + */ + abort(): void; + // Events on(event: string, listener: () => void): this; on(event: 'connect', cb: (connection: connection) => void): this; diff --git a/types/websocket/websocket-tests.ts b/types/websocket/websocket-tests.ts index 3044f9bf7d..94f8a11e16 100644 --- a/types/websocket/websocket-tests.ts +++ b/types/websocket/websocket-tests.ts @@ -180,8 +180,18 @@ function clientTest2() { } +function testClientAbortApi() { + var ipArray = getLocalIpArray(); + var client = new websocket.client(); + client.connect(`ws://${ipArray[0]}:8888`, undefined, undefined, undefined, { + localAddress: ipArray[0] + }); + client.abort(); +} + { console.log(`websocket test start.`); serverTest2(); clientTest2(); + testClientAbortApi(); }