Git Product home page Git Product logo

Comments (6)

KSDaemon avatar KSDaemon commented on June 15, 2024

Hi @martinpley Do you still get this error? I've just tested it in stable Chrome/Opera — works as expected.

from wampy.js.

KSDaemon avatar KSDaemon commented on June 15, 2024

Feel free to reopen, if this bug still exists, but please provide more info.

from wampy.js.

gdebrion avatar gdebrion commented on June 15, 2024

Hello,

I am using Wampy v0.1 and when the connection broke, the client re-connect but does not subscribe again to the channels. I have tried to put subscriptions in the onConnect function, but I have the same behavior…

Here's some details:

var ws = new Wampy('ws://blablabla:8080');
ws.options({
	reconnectInterval: 1000,
	maxRetries: 999,
	onConnect: function() {
		console.log('onConnect()');
		ws.subscribe('chat:test', function(data) {
			data = JSON.parse(data);

			if(typeof data.user !== 'undefined') {
				$('#panel-chat ul').append('<li><strong>'+data.user+':</strong> '+data.message+'</li>');
			}
			else {
				$('#panel-chat ul').append('<li><em>'+data.message+'</em></li>');
			}
		});

		ws.subscribe('commands:test', function(data) {
			console.log('command: '+data);
		});
	}
});

On the first connection, everything is ok. But if on the server side, when I shutdown the re-run the script, we can see that only connection is re-etablished, not subscriptions:

xxx@xxx:~/dev/wp-content/websockets$ php server.php 
90.107.224.xxx is connected…
90.107.224.xxx has subscribed to chat:test
^C
xxx@xxx:~/dev/wp-content/websockets$ php server.php 
90.107.224.xxx is connected…
[nothing more]

I don't think it's needed for this case, but the source of my server is:

<?php
namespace xxxWS;

use xxxWS\Token;
use Ratchet\ConnectionInterface as Conn;
use Ratchet\Wamp\WampServerInterface;

class xxxWS implements WampServerInterface {
	public function onPublish(Conn $conn, $topic, $event, array $exclude, array $eligible) {
		// Find the user name
		$token = new Token($event['token']);

		$topic->broadcast(json_encode(['user' => $token->getAlias(), 'message' => htmlspecialchars($event['message'])]));
	}

	public function onCall(Conn $conn, $id, $topic, array $params) {
		echo "Call: $id\n";
		$conn->callError($id, $topic, 'RPC not supported on this demo');
	}

	// No need to anything, since WampServer adds and removes subscribers to Topics automatically
	public function onSubscribe(Conn $conn, $topic) {
		echo $conn->remoteAddress." has subscribed to $topic\n";
		$conn->send(json_encode(['message' => "You are now connected to the chatroom…"]));
	}

	public function onUnSubscribe(Conn $conn, $topic) {}

	public function onOpen(Conn $conn) {
		echo $conn->remoteAddress." is connected…\n";
	}

	public function onClose(Conn $conn) {
		echo $conn->remoteAddress." has left…\n";
	}

	public function onError(Conn $conn, \Exception $e) {}
}

If you have any idea :)

from wampy.js.

KSDaemon avatar KSDaemon commented on June 15, 2024

Hi, @gdebrion! Well....instead of answers, i have a bunch of question :)

  • Any reason, why do you use obsolete version 0.1.0 instead of current? Yes, it's WAMP v1. But it is obsolete too
  • Why had you decided, that wampy v0.1.0 supports automatic resubscription? I don't see any mentions about it. So — No, it doesn't
  • I advice to use onReconnect callback for resubscription. I think it should suite your needs.

Hope, it helps!

from wampy.js.

gdebrion avatar gdebrion commented on June 15, 2024

Good questions!

I am stuck with the server that implements only Wamp v1. There are not so many JS library with v1 support… For the automatic resubscription, you are right, I thought it was automatic.

I wll try with the onReconnect callback ;)

from wampy.js.

KSDaemon avatar KSDaemon commented on June 15, 2024

@gdebrion why do you stuck with WAMP v1? Even in PHP world there is already v2 implementation: https://github.com/voryx/Thruway — have a look! If you are using nginx/openresty env — have a look at my Wiola implementation. There are a lot of various implementations! My advise is — not to start playing with v1, only v2!

from wampy.js.

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.