Skip to content
This repository was archived by the owner on Aug 25, 2022. It is now read-only.
This repository was archived by the owner on Aug 25, 2022. It is now read-only.

did someone tried to use it with socket.io version 4x ? #214

@filoucrackeur

Description

@filoucrackeur

Hello,

I tried no error but i no received message

class Version4X extends \ElephantIO\Engine\SocketIO\Version1X
{

    /** {@inheritDoc} */
    public function getName()
    {
        return 'SocketIO Version 4.X';
    }

    /** {@inheritDoc} */
    protected function getDefaultOptions()
    {
        $defaults = parent::getDefaultOptions();

        $defaults['version'] = 4;

        return $defaults;
    }
}


function sendToSocket()
{
    $client = (new Client(new Version4X('https://127.0.0.1:7777', [
        'debug' => true,
        'version' => 4,
        'query' => ['username' => 'toto', 'connectionType' => 'browser-client']
    ])))->initialize();
    // send message to connected clients
    $client->emit('broadcast', ['type' => 'notification', 'text' => 'Hello There!']);
    $client->close();
}
try {
    sendToSocket();
} catch (ServerConnectionFailureException $e) {
    dump($e->getErrorMessage());
} catch (\Exception $e) {
    dump($e);
}
echo "ok";

nodejs server side

server.listen(port, '0.0.0.0',() => {
    console.info(`ℹ local nodejs server started on https://${domain}:${port}`)
})

io.on("connection", socket => {
    socket.on('broadcast', function (message) {
        console.info('ElephantIO broadcast > ' + JSON.stringify(message));

        // send to all connected clients
        io.sockets.emit("broadcast", message);
    });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions