Download the PHP package ratacibernetica/yii2-node-socket without Composer
On this page you can find all versions of the php package ratacibernetica/yii2-node-socket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ratacibernetica/yii2-node-socket
More information about ratacibernetica/yii2-node-socket
Files in ratacibernetica/yii2-node-socket
Package yii2-node-socket
Short Description This is a fork of oncesk/yii-node-socket
License
Informations about the package yii2-node-socket
Disclaimer
This fork is under development to make it work with Yii2. As of now, i haven't checked the subscription feature, Many parts of code have been rewritten and tested only in a project, so i guess this doesn't work not out of the box .
Be warned.
Yii2 Node Socket
Connect php, javascript, nodejs in one Yii application.
Yii1
Hi, if you need work with yii1 you can do it from (https://github.com/oncesk/yii-node-socket/tree/2.0.0)
What you can do:
- send event(s) to all clients or in concrete room or in concrete channel
- now you can send events to single (concrete user) by user id!
- call some function or object method in window context
- you can change DOM model with jquery from php
- ability to set up data and get it in your javascript application
- send events from javascript for all clients or clients -in concrete room or channel-
Changes
- Updated for Yii 2.0
- Added Namespacing Updated for Yii 2.0
- Commposer settings updated to work with yii extension updates
Requirements
- linux/unix/windows
- git
- vps or dedicated server (for nodejs process)
- curl has to be installed or enabled
Installation
Install nodejs, if not installed see http://nodejs.org/
Install extension
-
Composer
- Using git clone
Now go to the folder where you install extension vendors/ratacibernetica/yii2-node-socket and execute
Yii2 configuration
-
Configure console command in (console/config/main.php). You can use config below:
- Register Yii component, need to add into frontend/config/main.php in your frontend application:
Notice: host should be a domain name like in you virtual host configuration or server ip address if you request page using ip address
- Configure aliases in the common config in (common/config/main.php).
- The first is for Yii to find the PHP Namespace and the second is to find the JS assets.
- You can use config below:
Notice: if you will be using behaviors or node-socket models, you need to add nodeSocket component in preload components list
Install nodejs components in application.ext.yii-node-socket.lib.js.server:
Congratulation, installation completed!
Notice: if the name of the component will not be nodeSocket, your need to use special key in console command --componentName=component_name
Notice: It's highly probable that the JS don't load by itself, so we must register the YiiSocketNode Assets in the view/layout.
Like so.
Console command actions (as administrative user)
Use (./yii node-socket/
Definitions
- Frame - data package for nodejs server wrapped into Class. Per one request to nodejs server you can send only 1 frame. For send several frames at a time use Multiple frame.
- room - one or more clients in concrete namespace: every client can create room, other clients can join into concrete room, any client in room can send event in this room.
About Yii2's User model
We need to follow these steps to send events to certain Users:
Register these Events
As Yii2 doesnt have those events anymore, we need to add them.
So i created a file named "AppBootstrap":
And add it, indeed, to frontend/config/main.php
So, we just subscribed the logged user to node's service (or something like that, not sure).
Events
Work in javascript
Use YiiNodeSocket
class
Start work
Catch Events
Now events can be created only on PHP side. All data transmitted in json format. Into callback function data was pasted as javascript native object (or string, integer, depends of your PHP Frame config)
Rooms
Channels
Channel is very similar to the room, but you can controll access to channel for clients
Emit events
You can emit event to:
- all clients
- clients in concrete room
Global events:
Room event:
Shared Public Data
You can set shared data only from PHP using PublicData Frame (see below into PHP section).
To access data you can use getPublicData(string key, callback fn)
method
PHP
Behaviors
- YiiNodeSocket\Behaviors\ArChannel - can be used for create new channel. Example: You can attach this behavior to User, in result any user will have own channel, and other user can subscribe to events of concrete user.
- YiiNodeSocket\Behaviors\ArSubscriber - should be attached to object which can subscribe to some channel. Example: model User at a time can be channel and subscriber.
Client authorization
For authorizing client you need send special Authentication frame, you can do it in your user component in afterLogin event
After that, this user can receive events only for him. See example below, send event only for single (concrete) $user
and your javascript
Client scripts registration
Event frame
Set up shared data
You can set expiration using setLifeTime(integer $lifetime) method of class PublicData
Room events
Only member of testRoom can catch this event
Invoke client function or method
In your PHP application you can invoke javascript function or method of object in window context.
Extends from Event frame => you can send it into specific room
DOM manipulations with jquery
Task: you need update price on client side after price update in each product
Send more than one frame per a time
Example 1:
Example 2:
PS
Sorry for my english :)