Closed ezraroda closed 6 years ago
Hi,
I tried to reproduce your problem:
import ReconnectingWebsocket from "reconnecting-websocket";
import WebSocket from "ws";
const rws = new ReconnectingWebsocket("ws://lokalhost:8080", undefined, {WebSocket});
rws.addEventListener("error", () => {
console.log("error");
});
This works as expected.
Can you please send a snippet where your issue is reproduced? More details about the library version, environment, etc, would be helpful
@pladaria
The error was reproduced:
<!DOCTYPE html>
<html>
<head>
<title>Reconnecting WS</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Open console and send a message</h1>
<pre>echo.send('oohhyeahh!!')</pre>
<script type="module">
import ReconnectingWebSocket from 'https://unpkg.com/reconnecting-websocket@4.0.0-rc5/dist/reconnecting-websocket.mjs'
class Echo {
constructor() {
// Fail
this.ws = new ReconnectingWebSocket('wss://echo.websocket.org')
// Works
// this.ws = new WebSocket('wss://echo.websocket.org')
this.ws.addEventListener('open', this)
this.ws.addEventListener('message', this)
this.ws.addEventListener('close', this)
this.ws.addEventListener('error', this)
}
send(v = 'ulala') {
this.ws.send(v)
}
onopen() {
console.log('open')
this.ws.send('Hello echoooo...')
}
onmessage(event) {
console.log('message echo --->', event.data)
}
onclose() {
console.log('close')
}
onerror() {
console.log('error')
}
handleEvent(event) {
if (typeof this[`on${event.type}`] === 'function') {
this[`on${event.type}`](event)
}
}
}
window.echo = new Echo()
</script>
</body>
</html>
@lagden Thanks for reporting! Event handlers were not supporting objects with handleEvent
@lagden fixed in latest release
@ezraroda closing issue because I was unable to reproduce your problem. Here is my code trying to reproduce it: https://codesandbox.io/s/p4m2707om?expanddevtools=1 Please feel free to reopen this issue if you can reproduce it.
Thank you all for your feedback!
I'm running into the following scenario, I'm providing incorrect URL on perpouse with 0 retry option. const options = { connectionTimeout: 500, maxRetries: 0, debug: true };
const rws = new ReconnectingWebSocket('ws://**lokalhost**:8080', [], options);
Registering on error event listener:
Looks like any registered listener is removed on connection error and never get called from the internal _handleError
getting this error TypeError: this._listeners.error is undefined
Any recommendations how to handle initial connection errors ?