So i am trying to use Custom WebSocket Handlers in this package . I followed all the steps as stated in the documentation https://docs.beyondco.de/laravel-websockets/1.0/advanced-usage/custom-websocket-handlers.html . After that using a javascript i tried to establish connection and then send message from it , connection establishes but i receive the strange error
Starting the WebSocket server on port 4222...
New connection opened for app key .
Exception ErrorException thrown: Undefined property: Ratchet\Server\IoConnection::$app
Unknown app id: exception ErrorException thrown: Undefined property: Ratchet\Server\IoConnection::$app.
my javascript code is
`
var conn = new WebSocket('ws://127.0.0.1:4222/my-socket');
conn.onopen = function(e) {
conn.send('Hello World!');
};
conn.onmessage = function(e) {
console.log(e.data)
}
`
please Look at it ..
Hello @shahabgohar, same issue here.
I fixed it by setting $app and $socketId manually :
<?php
// ...
use BeyondCode\LaravelWebSockets\Apps\App;
// ...
public function onOpen(ConnectionInterface $connection)
{
$socketId = sprintf('%d.%d', random_int(1, 1000000000), random_int(1, 1000000000));
$connection->socketId = $socketId;
$connection->app = App::findById('YOUR_APP_ID');
// ...
Had the same issue, should be documented in the custom handler section and not just a super hard to find closed issue
@Tofandel agreed !!
Got answer after a week but by then i switched to swoole
It was way easier to implement
@maximerenou hi
I have added your this code answer in my application
<?php
// ...
use BeyondCode\LaravelWebSockets\Apps\App;
// ...
public function onOpen(ConnectionInterface $connection)
{
$socketId = sprintf('%d.%d', random_int(1, 1000000000), random_int(1, 1000000000));
$connection->socketId = $socketId;
$connection->app = App::findById('YOUR_APP_ID');
// ...
but it is still showing error this
New connection opened for app key your-pusher-key.
Connection id 441865230.936318383 closed.
ExceptionErrorExceptionthrown:Trying to get property 'id' of non-object``
please share how can i resolve it??
@faizan-glowlogix If you didn't declare an app because you're not using as a pusher replacement (hence App::findById('some_id') will not return anything) you can just do $connection->app = new \stdClass(); $connection->app->id = 'my_app'; to get rid of the error
Most helpful comment
Hello @shahabgohar, same issue here.
I fixed it by setting
$appand$socketIdmanually :