Code Monkey home page Code Monkey logo

Comments (4)

pladaria avatar pladaria commented on August 19, 2024

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

from reconnecting-websocket.

lagden avatar lagden commented on August 19, 2024

@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/[email protected]/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>

from reconnecting-websocket.

pladaria avatar pladaria commented on August 19, 2024

@lagden Thanks for reporting! Event handlers were not supporting objects with handleEvent

from reconnecting-websocket.

pladaria avatar pladaria commented on August 19, 2024

@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!

from reconnecting-websocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.