From a3bc2e2ac87042f5e51ab6b923a5756f30992840 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Mon, 29 Jan 2018 10:44:04 +0800 Subject: [PATCH 1/2] add abort() into the websocket client --- types/websocket/index.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) 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; From 10d7c896cc3100bb6b7c69d9d001dc3c427bce76 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Thu, 8 Feb 2018 16:16:54 +0800 Subject: [PATCH 2/2] add test case --- types/websocket/websocket-tests.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) 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(); }