Merge pull request #23243 from jdneo/cs/wsabort

add abort() into the websocket client
This commit is contained in:
Daniel Rosenwasser
2018-02-13 11:47:33 -08:00
committed by GitHub
2 changed files with 16 additions and 0 deletions
+6
View File
@@ -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;
+10
View File
@@ -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();
}