Open Mark-Lister opened 5 years ago
So a few things, first off this plugin comes with a helper that sets up the required websocket client for you, inspect the output to get started, it uses https://github.com/WyriHaximus/nodejs-persistent-autobahn . The telnet will do nothing as the server doesn't know what to do with an empty request.
The thing is without errors that says nothing, it could be your firewall or another tool that blocks the connection.
There are no examples, and tbh I'm not sure if there will be as I'm losing interest in maintaining this plugin. But it's a thin layer around https://github.com/voryx/Thruway
Updated with different error with editing config.
So a few things, first off this plugin comes with a helper that sets up the required websocket client for you, inspect the output to get started, it uses https://github.com/WyriHaximus/nodejs-persistent-autobahn . The telnet will do nothing as the server doesn't know what to do with an empty request.
The thing is without errors that says nothing, it could be your firewall or another tool that blocks the connection.
There are no examples, and tbh I'm not sure if there will be as I'm losing interest in maintaining this plugin. But it's a thin layer around https://github.com/voryx/Thruway
Oh great thanks a lot I got it working with autobahn. I just have one more question, now I can publish and subscribe to events on the client side is there a way I can publish an event from a controller for example when I add a new item to a table so I can get the clients to refresh their data? Thanks again.
Here is a listener you can build on, you'd still have to get the data to the listener from your controller but this is the recommended way to hook into pubsub and set up RPC's
<?php declare(strict_types=1);
namespace App\Listener;
use Cake\Event\EventListenerInterface;
use React\EventLoop\LoopInterface;
use React\EventLoop\Timer\TimerInterface;
use function React\Promise\resolve;
use Thruway\ClientSession;
use WyriHaximus\Ratchet\Event\OnSessionEndEvent;
use WyriHaximus\Ratchet\Event\OnSessionStartEvent;
useColours;
final class ColoursListener implements EventListenerInterface
{
const STATE_KEY = 'colour';
const COLOUR_DEFAULT = '1abc9c';
const COLOUR_TWITTER = '1da1f2';
private $colour = self::COLOUR_DEFAULT;
/**
* @var LoopInterface
*/
private $loop;
/**
* @var ClientSession
*/
private $session;
/**
* @var TimerInterface
*/
private $timer;
/**
* @var int
*/
private $timerInterval = 13;
/**
* @param LoopInterface $loop
*/
public function __construct(LoopInterface $loop, Colours $colours, int $timerInterval = 13)
{
$this->loop = $loop;
$this->timerInterval = $timerInterval;
$colours->subscribe(function (string $colour): void {
$this->colour = $colour;
if ($this->session === null) {
return;
}
$this->session->publish('colour', [$colour]);
});
}
public function implementedEvents()
{
return [
OnSessionStartEvent::realmEvent('header') => 'onSessionStart',
OnSessionEndEvent::realmEvent('header') => 'onSessionEnd',
];
}
public function onSessionStart(OnSessionStartEvent $event): void
{
$this->session = $event->getSession();
$this->session->register('colour', function () {
return resolve($this->colour);
});
$this->timer = $this->loop->addPeriodicTimer($this->timerInterval, function (): void {
$this->session->publish('colour', [$this->colour]);
});
}
public function onSessionEnd(OnSessionEndEvent $event): void
{
$this->session = null;
$this->loop->cancelTimer($this->timer);
}
}
Hi, I'm using cakephp 3.6 and php 7.3 I just downloaded this plugin. I've managed to get the server started but I cant seem to connect to it using this code
I always get the error
WebSocket connection to 'wss://***.***.**.**:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT
I can connect to this port using telnet I get this
This is my configuration in app.php
This is the output of the shell : cake WyriHaximus/Ratchet.websocket start -v
netstat -npl gives
Thanks.
UPDATE When I change the address to the domain name from the external IP in the config and Javascript I get this error instead.
WebSocket connection to 'wss://****.*************.com:8080/' failed: WebSocket opening handshake timed out