Download the PHP package nikovonlas/yii2sockets without Composer
On this page you can find all versions of the php package nikovonlas/yii2sockets. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nikovonlas/yii2sockets
More information about nikovonlas/yii2sockets
Files in nikovonlas/yii2sockets
Package yii2sockets
Short Description Node.js web-sockets support for Yii2
License MIT
Informations about the package yii2sockets
Node.js server integration module (web-sockets)
Install with composer
Add console command controller to the config (controllerMap section):
Add session component to the 'components' section of main config:
It uses Redis DB connection to share session data with Node.js server. Of course you must use redis component to connect Redis DB. Add it in both configs (web and main).
And add component do those configs (https not implemented yet):
Parameter channelsByPermissions
is an array with channel names and permissions.
If Yii::$app->user->can('permission')
returns TRUE
than channel channel_name
will be added to user automatically.
It runs on component init.
When configs are ready use console command to build Node.js config files:
Node.js server
Server is in server
subdirectory. Before first run you must install all Node.js modules. Go to server
directory and install they with command
Now you can run server
You can use environment variables to overwrite config options. For example:
In that case it runs in production mode with disabled debug information.
Messages
There are 3 message classes (I call it Frames):
-
Basic (YiiNodeSocketFrameBasic) used for basic messages.
-
jQuery (YiiNodeSocketFrameJQuery) used for jQuery DOM manipulations.
-
Notify (YiiNodeSocketFrameGrowl) uses
kartik-v/yii2-widget-growl
to show messages for user. - Alert (YiiNodeSocketFrameAlert) plays audio alert to user.
Examples
Send message with array[] body to channel test_channel
. On front end will be used Javascript callback jsCallbackName
.
Send message to this socket (example is used on AJAX request).
Send jQuery frame to user with ID 1
. It will remove element with selector #element_selector
.
Send Alert frame to channel test_channel
to all browser windows (not active too):
Please notice, that you need to render block with <audio>
element in order to play it.
Also includes example YiiNodeSocketFrameChat frame type that sends message depending on its content:
- to
recipient_id
andauthor_id
if object contains both those properties; - to
channel
composed automatically otherwise. You can see frame source for details.
Javascript callback example: