This repository has been archived by the owner on Oct 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
How to define new event #23
Comments
Initiate what? It just allows data exchange. |
As I expect, I should be able to link this data exchange framework to Events of Laravel system. In other words, with binding EventListener to the message exchange system I should be able to exchange desired messages with my clients at desired times. Is it true? |
Yes. I'm using a queue, but it works on normal events too namespace App\Listeners;
use App\Events\OrderShipped;
use SocketClient;
class SendShipmentNotification
{
/**
* Handle the event.
*
* @param \App\Events\OrderShipped $event
* @return void
*/
public function handle(OrderShipped $event)
{
SocketClient::send('soket-route',[
'user_id' => $event->order->user_id,
'message' => 'Thank you for ordering from us.... bla bla bla...',
]);
}
} and namespace App\Facades;
use Ratchet\Client;
class SocketClient
{
/**
* Get the registered name of the component.
*
* @param string $route
* @param array $arg
*/
public static function send($route, array $arg)
{
$config = config('socket');
Client\connect('ws://' . $config['httpHost'] . ':' . $config['port'] . '/' . $route)->then(function ($conn) use (
$arg
) {
$conn->send(json_encode($arg));
$conn->close();
});
}
} This all works, but you need to determine for yourself how and to whom you will send |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
How to define new event BaseSocketListener subclass and trigger this event ?
The text was updated successfully, but these errors were encountered: