Download the PHP package le0m/yii2-broadcasting without Composer
On this page you can find all versions of the php package le0m/yii2-broadcasting. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-broadcasting
Yii2-broadcasting
This component a continuation of MKiselev/yii2-broadcasting. It has been re-organized and udpated to work with Yii2 2.0.16.
You can use it to handle notifications through a websocket.
Requirements
- a working instance of laravel-echo-server, to handle the Socket.io server and channel authentication
- yiisoft/yii2-redis is installed by this package, for sharing messages with Socket.io server through Redis
- Laravel Echo and socket.io-client on the frontend, to open the websocket and listen for notifications
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json.
Configuration
Configure the component to use a broadcaster:
There are several broadcast tools available for your choice:
1) NullBroadcaster Doing nothing, just a stub 2) LogBroadcaster Broadcast events to application log 3) RedisBroadcaster Broadcast by Redis using Pub/Sub feature
Usage
Setup Laravel Echo Server
See docs.
Server side
Add the action to authorize users access to private and presence channels:
Define a new event to broadcast by extending le0m\broadcasting\BroadcastEvent
, the public properties you define will be sent as message payload:
And then broadcast it when needed:
The toOthers
flag is used to broadcast a message to all channel's users except the sender. The socket ID header is used to exclude the sender.
Client side
Import and initialize Echo
, then start listening for notifications:
Here we wait for the connect
event of Socket.io connector, to obtain a socket ID before attaching our callbacks.
Other
- Echo Server with Docker (bottom)
- references
- changelog