-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
this._listeners.error is undefined #63
Comments
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 |
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. 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 ?
The text was updated successfully, but these errors were encountered: