Closed bvandenbos closed 6 years ago
I got the same issue with reconnecting-websocket v3.2.2:
Here is my code:
const Html5WebSocket = require('html5-websocket');
const ReconnectingWebsocket = require('reconnecting-websocket');
private socket: WebSocket;
// ...
public connect(clientId?: string): void {
this.socket = new ReconnectingWebsocket(...);
}
public disconnect(): void {
// TS2554: Expected 0-2 arguments, but got 3.
this.socket.close(1000, '', {keepClosed: true, fastClose: true, delay: 0});
}
Luckily there is a workaround:
public disconnect(): void {
const socket: any = this.socket; // Cast 'WebSocket' into 'any' in order to supply a third parameter
this.socket.close(1000, '', {keepClosed: true, fastClose: true, delay: 0});
}
Source: https://github.com/wireapp/wire-web-packages/pull/114
Any update on this?
Should be fixed in latest release. Thanks
@pladaria Can you provide an example on how to use this library with TypeScript? I tried to use it but it has some problems.
Here is my code:
import ReconnectingWebsocket = require("reconnecting-websocket");
const socket = new ReconnectingWebsocket(
() => this.buildWebSocketURL(),
undefined,
WebSocketClient.RECONNECTING_OPTIONS
);
It thows the following error:
Hi,
Thanks for checking the new library version!
esModuleInterop
enabled and use ES imports, this small node script works for me:import ReconnectingWebsocket from 'reconnecting-websocket';
import WebSocket from 'ws';
const getUrl = () => Promise.resolve('ws://echo.websocket.org/');
const OPTIONS = {WebSocket};
const rws = new ReconnectingWebsocket(getUrl, undefined, OPTIONS);
rws.addEventListener('open', () => {
rws.send('hi');
});
rws.addEventListener('message', (event) => {
console.log(event.data); // prints "hi"
});
Please don't hesitate to open an issue if you find any problem
@pladaria I checked the "close" function of v4.2.0 and it is defined to accept only 2 parameters ("code" and "reason"), so I guess there is no more support for a third ("options") parameter?
ReconnectingWebsocket
extendsWebSocket
but doesn't redefine theclose
method to take the third "options" parameter.Closing a reconnecting websocket like this:
Results in a typescript error;
Expected 0-2 arguments, but got 3
.