Open jokari4242 opened 7 years ago
Anyone was able to solve this issue?
I got the same problem and have no idea to fix this one.
Hello. what messages you have in log of your WebsocketServer?
Hi, anyone got a fix to this issue?
I am having the same issue. does anyone knows what it is?
@haskasu Hello. what messages you have in log of your WebsocketServer?
I think the ping should be from the client. The server should close any inactive connection after a timeout, to avoid running out of resources.
var pingpong = function (){
session.publish( myroute , {message: "ping"});
};
var intervalvar = setInterval(pingpong, timeout_in_milliseconds);
Hi, anyone was able to solve this issue?
Hi, anyone was able to solve this issue?
try this #197 (comment)
This seems to be also happening to me since Evgen14 reported it. No changes to code was made and it just stopped working... Any solution so far?
Related to #351. Does anyone has this running on Symfony 4?
The demo app was upgraded to run Symfony 4.2 over the weekend and personally I've got an app in production I upgraded to Symfony 4.2 last Friday (upgraded from 3.4 to 4.1 4 months ago). So whatever issue you're running into is not related to Symfony version support.
I'm also running this bundle (v1.8.13) in a Symfony 4.1.7 application without problems
The demo app was upgraded to run Symfony 4.2 over the weekend and personally I've got an app in production I upgraded to Symfony 4.2 last Friday (upgraded from 3.4 to 4.1 4 months ago). So whatever issue you're running into is not related to Symfony version support.
The demo app uses the dev-master version of the bundle. That way it works. With 1.8* it doesn't.
I've created this project that I can't get running: https://github.com/klodoma/symfony4-websocket
composer update
php bin/console server:run
php bin/console gos:websocket:server
Any help/ideas are appreciated!
There's also a 1.x branch on the demo app corresponding with the 1.x branch on this repo.
There's also a 1.x branch on the demo app corresponding with the 1.x branch on this repo.
Didn't noticed that. I'll have a look. Thanks!
Ok, I've solved it for my case. I had these missing in services.yml:
# RPC handlers need to have the `gos_web_socket.rpc` tag, so by convention we will tag all handlers in the directory
AppBundle\Rpc\:
resource: '../../src/AppBundle/Rpc'
tags:
- { name: gos_web_socket.rpc }
# RPC handlers need to have the `gos_web_socket.topic` tag, so by convention we will tag all handlers in the directory
AppBundle\Topic\:
resource: '../../src/AppBundle/Topic'
tags:
- { name: gos_web_socket.topic }
Yeah, that would make sense (1.x doesn't support autoconfiguration of the RPC and Topic services).
Something I need to port from my current setup is adding logging and a little more error trapping to the RpcDispatcher since right now that can be a bit of a black box if it fails (and I think in your case it was the RPC calls that was causing your disconnect). If you're comfortable with it, you can use a compiler pass to replace the dispatcher service until that happens.
<?php declare(strict_types=1);
namespace App\Websocket\DependencyInjection\CompilerPass;
use App\Websocket\Server\Dispatcher\RpcDispatcher;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class ReplaceRpcDispatcherPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
// Change to our custom RPC Dispatcher and add appropriate method calls
if ($container->hasDefinition('gos_web_socket.rpc.dispatcher')) {
$container->getDefinition('gos_web_socket.rpc.dispatcher')
->setClass(RpcDispatcher::class)
->addMethodCall('setLogger', [new Reference('monolog.logger.websocket')]);
}
}
}
<?php declare(strict_types = 1);
namespace App\Websocket\Server\Dispatcher;
use Gos\Bundle\WebSocketBundle\Router\WampRequest;
use Gos\Bundle\WebSocketBundle\RPC\RpcResponse;
use Gos\Bundle\WebSocketBundle\Server\App\Dispatcher\RpcDispatcherInterface;
use Gos\Bundle\WebSocketBundle\Server\App\Registry\RpcRegistry;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Ratchet\ConnectionInterface;
class RpcDispatcher implements RpcDispatcherInterface, LoggerAwareInterface
{
use LoggerAwareTrait;
/**
* @var RpcRegistry
*/
private $rpcRegistry;
public function __construct(RpcRegistry $rpcRegistry)
{
$this->rpcRegistry = $rpcRegistry;
}
public function dispatch(ConnectionInterface $conn, $id, $topic, WampRequest $request, array $params)
{
$callback = $request->getRoute()->getCallback();
try {
$procedure = $this->rpcRegistry->getRpc($callback);
} catch (\Throwable $e) {
// Log the error
$this->logger->error(
sprintf(
'Could not find RPC handler in registry for callback "%s".',
$callback
),
[
'exception' => $e,
]
);
$conn->callError(
$id,
$topic,
$e->getMessage(),
[
'code' => $e->getCode(),
'rpc' => $topic,
'params' => $params,
'request' => $request,
]
);
return;
}
$method = $this->toCamelCase($request->getAttributes()->get('method'));
if (!method_exists($procedure, $method)) {
// Log the error
$this->logger->error(
sprintf(
'Method "%s" not found in %s',
$method,
get_class($procedure)
),
[
'called_method' => $request->getAttributes()->get('method'),
]
);
$conn->callError(
$id,
$topic,
'Could not execute RPC callback, method not found',
[
'code' => 404,
'rpc' => $topic,
'params' => $params,
'request' => $request,
]
);
return;
}
try {
$result = call_user_func([$procedure, $method], $conn, $request, $params);
} catch (\Throwable $e) {
// Log the error
$this->logger->error(
'Websocket error processing RPC function.',
[
'exception' => $e,
'rpc' => $topic,
]
);
$conn->callError(
$id,
$topic,
$e->getMessage(),
[
'code' => $e->getCode(),
'rpc' => $topic,
'params' => $params,
'request' => $request,
]
);
return;
}
if ($result === null) {
$this->logger->error(
sprintf(
'Null return from RPC handler %s::%s()',
get_class($procedure),
$method
)
);
$conn->callError(
$id,
$topic,
'RPC Error',
[
'code' => 500,
'rpc' => $topic,
'params' => $params,
'request' => $request,
]
);
return;
}
if ($result instanceof RpcResponse) {
$result = $result->getData();
} elseif (!is_array($result)) {
$result = [$result];
}
$conn->callResult($id, $result);
}
private function toCamelCase(?string $str): string
{
return preg_replace_callback(
'/_([a-z])/',
function ($c): string {
return strtoupper($c[1]);
},
$str
);
}
}
Hi!
Thanks for this nice bundle,
I have a pb, like a timeout or i don't know...
When the page is loaded, everything works well, user are authentified, and can suscribe to room.
When a little period of inactivity or when i'm using back navigator function, i have this message, in console of developper tools:
And when i'm publish something :
Here, the script use for connect client to websocket
If someone can help me, thanks a lot :-)