Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Try to change the stream resource with an invalid one; given unknown type when trying to broadcastIf in on close. #100

Open
undsoft opened this issue Sep 13, 2017 · 2 comments

Comments

@undsoft
Copy link

undsoft commented Sep 13, 2017

Hi,

I have several JS clients connected to websocket server. They are organized into channels (I store Node objects).
Now one of the clients (client A) disconnects.
In PHP server, I'm listening to 'close' event and want to tell other clients in that room that A has disconnected.

Here's my code:

$this->websocket->on('close', function (Bucket $bucket) {
    // Get list of connected channel clients
    // Make sure to remove disconnected client (client A) from the list.
    $this->websocket->broadcastIf(function ($currentNode) use ($channelNodes) {
        $result = false;

        /** @var \Hoa\Websocket\Node $currentNode */
        /** @var \Hoa\Websocket\Node $node */
        foreach ($channelNodes as $node) {
            if ($currentNode->getId() === $node->getId()) {
                $result = true;
                break;
            }
        }

        return $result;
    }, Json::encode($data));
});

However, when I do this I get this message:

[2017-09-13 11:50:36.335700] Try to change the stream resource with an invalid one; given unknown type. at /Users/undsoft/htdocs/freelancer/vendor/hoa/stream/Stream.php. Line 412
#0 /Users/undsoft/htdocs/freelancer/vendor/hoa/socket/Connection/Handler.php(276): Hoa\Stream\Stream->_setStream(Resource id #170)
#1 /Users/undsoft/htdocs/freelancer/vendor/hoa/websocket/Connection.php(566): Hoa\Socket\Connection\Handler->Hoa\Socket\Connection\{closure}(1, true)
#2 [internal function]: Hoa\Websocket\Connection->send('{"type":"connec...', Object(Hoa\Websocket\Node))
#3 /Users/undsoft/htdocs/freelancer/vendor/hoa/socket/Connection/Handler.php(336): call_user_func_array(Array, Array)
#4 /Users/undsoft/htdocs/freelancer/websockets/classes/Handler.php(345): Hoa\Socket\Connection\Handler->broadcastIf(Object(Closure), '{"type":"connec...')

Any ideas?

@undsoft
Copy link
Author

undsoft commented Sep 14, 2017

I can work around it by marking client as disconnect in on close and then actually telling everybody about it in on message.
Still would be nice to fix this or at least document it.

@Hywan
Copy link
Member

Hywan commented Sep 14, 2017

Hello,

I am in the opposite side of the world right now and I can't work on this issue. Maybe @vonglasow or @Pierozi?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants