[READ ONLY] Subtree split of the Netflex MessageChannel component (see netflex/framework)
This library lets you send real time messages to connected clients over WebSocket using the Netflex MessageChannel API.
Just add this package as a dependency to yout Netflex SDKv2 based project, and it should be ready to use, no additional setup is required.
composer require netflex/message-channel
<?php
use MessageChannel;
MessageChannel::broadcast(['status' => 'Hello World']);
This will send this message to the MessageChannel API server, which will then relay that message to its connected clients over WebSocket.
To handle incoming messages, you will have to register a handler.
This can be configured in your apps config config/message-channel.php
<?php
return [
'handler' => [
'endpoint' => 'https://my-endpoint-to-handle-incoming-messages',
'method' => 'post' // This is optional, 'post' is the default method
]
];
A client can register for a 'topic'. If you use e.g a users ID as the topic, you can then relay messages to this specific topic.
<?php
use MessageChannel;
// Only clients listening for the 'news' topic will receive this message
MessageChannel::broadcast(['status' => 'Hello World'], 'news');
This package also provides a driver that enables it to work with Laravels broadcast system.
Add the following to your applications config/broadcasting.php
<?php
return [
'default' => 'message-channel',
'connections' => [
'message-channel' => [
'driver' => 'netflex'
]
]
];