Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.
This repository was 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

@undsoft

Description

@undsoft

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?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions