From e22490c0c8dc5f63ca5725dc16702a9da1be184a Mon Sep 17 00:00:00 2001 From: oncesk Date: Tue, 7 Jul 2015 12:49:07 +0300 Subject: [PATCH 01/16] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 207cfb5..6c7b1c9 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,6 @@ Yii configuration
```php 'nodeSocket' => [ 'class' => '\YiiNodeSocket\NodeSocket', - 'dbOptions' => '', 'host' => 'localhost', 'allowedServerAddresses' => [ "localhost", From fbfe04b879cd9e2cc15e34ce940e01bce2c44585 Mon Sep 17 00:00:00 2001 From: oncesk Date: Tue, 7 Jul 2015 12:52:06 +0300 Subject: [PATCH 02/16] Update composer version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c7b1c9..c5127a1 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Install extension ```javascript { "require" : { - "oncesk/yii-node-socket" : "2.0.3" + "oncesk/yii-node-socket" : "2.0.4" } } ``` From 7315a9b0c95a9705a41b4f6217ca2fcd2a2870a4 Mon Sep 17 00:00:00 2001 From: oncesk Date: Thu, 9 Jul 2015 10:17:04 +0300 Subject: [PATCH 03/16] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c5127a1..6b2efa4 100644 --- a/README.md +++ b/README.md @@ -118,10 +118,10 @@ Use (**./yiic node-socket**) ```bash $> ./yiic node-socket # show help -$> ./yiic node-socket start # start server -$> ./yiic node-socket stop # stop server -$> ./yiic node-socket restart # restart server -$> ./yiic node-socket getPid # show pid of nodejs process +$> ./yiic node-socket/start # start server +$> ./yiic node-socket/stop # stop server +$> ./yiic node-socket/restart # restart server +$> ./yiic node-socket/getPid # show pid of nodejs process ``` ##Definitions From 8028ab315df8643af750374d2486c2d6f5aa48c7 Mon Sep 17 00:00:00 2001 From: Damien Buttler Date: Mon, 13 Jul 2015 17:24:57 +1000 Subject: [PATCH 04/16] Added command helper feedback. --- lib/php/NodeSocketCommand.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/php/NodeSocketCommand.php b/lib/php/NodeSocketCommand.php index f2484ba..7bcd549 100644 --- a/lib/php/NodeSocketCommand.php +++ b/lib/php/NodeSocketCommand.php @@ -32,6 +32,17 @@ class NodeSocketCommand extends \yii\console\Controller { */ private $_console; + public function actionIndex() { + $this->stdout( + "node-socket usage: \n\n" + ."./yii node-socket # show help\n" + ."./yii node-socket/start # start server\n" + ."./yii node-socket/stop # stop server\n" + ."./yii node-socket/restart # restart server\n" + ."./yii node-socket/getPid # show pid of nodejs process\n\n" + ); + } + public function actionStart() { if (!$this->_start()) { $this->usageError("Cannot start server"); @@ -250,4 +261,4 @@ private function getConsole() { } return $this->_console; } -} \ No newline at end of file +} From 2819b6db25fd05a9df8bb8039893af423b76333a Mon Sep 17 00:00:00 2001 From: Damien Buttler Date: Mon, 13 Jul 2015 17:33:26 +1000 Subject: [PATCH 05/16] Fixed command example. --- lib/php/NodeSocketCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/php/NodeSocketCommand.php b/lib/php/NodeSocketCommand.php index 7bcd549..04c31cf 100644 --- a/lib/php/NodeSocketCommand.php +++ b/lib/php/NodeSocketCommand.php @@ -39,7 +39,7 @@ public function actionIndex() { ."./yii node-socket/start # start server\n" ."./yii node-socket/stop # stop server\n" ."./yii node-socket/restart # restart server\n" - ."./yii node-socket/getPid # show pid of nodejs process\n\n" + ."./yii node-socket/get-pid # show pid of nodejs process\n\n" ); } From 8cae598c16882f8543b81c24fc49198ade1efdb5 Mon Sep 17 00:00:00 2001 From: Damien Buttler Date: Mon, 13 Jul 2015 17:35:05 +1000 Subject: [PATCH 06/16] Fixed indentation. --- lib/php/NodeSocketCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/php/NodeSocketCommand.php b/lib/php/NodeSocketCommand.php index 04c31cf..938c639 100644 --- a/lib/php/NodeSocketCommand.php +++ b/lib/php/NodeSocketCommand.php @@ -39,7 +39,7 @@ public function actionIndex() { ."./yii node-socket/start # start server\n" ."./yii node-socket/stop # stop server\n" ."./yii node-socket/restart # restart server\n" - ."./yii node-socket/get-pid # show pid of nodejs process\n\n" + ."./yii node-socket/get-pid # show pid of nodejs process\n\n" ); } From e7059b68037c240df5b9ae4288a2a8e71a11a51f Mon Sep 17 00:00:00 2001 From: oncesk Date: Wed, 19 Aug 2015 20:29:01 +0300 Subject: [PATCH 07/16] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d71fd80..f580fcf 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "oncesk/elephant.io": "*" + "oncesk/elephant.io": "dev-master" }, "autoload": { "psr-4": { From aaf7389bf83d5524192d3016bb7d8a231920eca7 Mon Sep 17 00:00:00 2001 From: The Gitter Badger Date: Mon, 24 Aug 2015 13:47:39 +0000 Subject: [PATCH 08/16] Added Gitter badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6b2efa4..a4a924b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Yii Node Socket ================= +[![Join the chat at https://gitter.im/oncesk/yii-node-socket](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/oncesk/yii-node-socket?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + Connect php, javascript, nodejs in one Yii application. ####Yii1 From 16d1fc5c91ce6ab0fdb29c671d6d390acb583049 Mon Sep 17 00:00:00 2001 From: ratacibernetica Date: Fri, 11 Sep 2015 23:09:59 -0500 Subject: [PATCH 09/16] Update using Yii2 classes --- README.md | 13 ++++----- composer.json | 2 +- lib/php/Autoload.php | 3 +- lib/php/NodeSocket.php | 7 +++-- lib/php/NodeSocketCommand.php | 13 +-------- lib/php/behaviors/ArBehavior.php | 16 ++++++---- lib/php/behaviors/ArChannel.php | 13 +++++---- lib/php/components/ArEvent.php | 4 +-- lib/php/frames/FrameFactory.php | 21 +++++++------- lib/php/models/AModel.php | 50 ++++++++++++++++++-------------- lib/php/models/Channel.php | 22 +++++++------- 11 files changed, 84 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index a4a924b..207cfb5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ Yii Node Socket ================= -[![Join the chat at https://gitter.im/oncesk/yii-node-socket](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/oncesk/yii-node-socket?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - Connect php, javascript, nodejs in one Yii application. ####Yii1 @@ -40,7 +38,7 @@ Install extension ```javascript { "require" : { - "oncesk/yii-node-socket" : "2.0.4" + "oncesk/yii-node-socket" : "2.0.3" } } ``` @@ -71,6 +69,7 @@ Yii configuration
```php 'nodeSocket' => [ 'class' => '\YiiNodeSocket\NodeSocket', + 'dbOptions' => '', 'host' => 'localhost', 'allowedServerAddresses' => [ "localhost", @@ -120,10 +119,10 @@ Use (**./yiic node-socket**) ```bash $> ./yiic node-socket # show help -$> ./yiic node-socket/start # start server -$> ./yiic node-socket/stop # stop server -$> ./yiic node-socket/restart # restart server -$> ./yiic node-socket/getPid # show pid of nodejs process +$> ./yiic node-socket start # start server +$> ./yiic node-socket stop # stop server +$> ./yiic node-socket restart # restart server +$> ./yiic node-socket getPid # show pid of nodejs process ``` ##Definitions diff --git a/composer.json b/composer.json index f580fcf..d71fd80 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "oncesk/elephant.io": "dev-master" + "oncesk/elephant.io": "*" }, "autoload": { "psr-4": { diff --git a/lib/php/Autoload.php b/lib/php/Autoload.php index bb43dc3..0e3812e 100644 --- a/lib/php/Autoload.php +++ b/lib/php/Autoload.php @@ -5,7 +5,8 @@ class Autoload { public static function register($nodeSocketDirectory) { $loader = new Autoload($nodeSocketDirectory); - spl_autoload_register(array($loader, 'autoload')); + $res = spl_autoload_register(array($loader, 'autoload')); + $res; } private $_nodeSocketDirectory; diff --git a/lib/php/NodeSocket.php b/lib/php/NodeSocket.php index 1474216..34badd6 100644 --- a/lib/php/NodeSocket.php +++ b/lib/php/NodeSocket.php @@ -5,8 +5,9 @@ use yii\base\Component; use YiiNodeSocket\Assets\NodeSocketAssets; -require_once 'frames/IFrameFactory.php'; -require_once 'frames/FrameFactory.php'; +/** + * @method YiiNodeSocket\Frames\IFrameFactory createEventFrame() + */ class NodeSocket extends Component { @@ -123,7 +124,7 @@ public function init() { // spl_autoload_register(array('YiiBase','autoload')); if (function_exists('__autoload')) { // Be polite and ensure that userland autoload gets retained - spl_autoload_register('__autoload'); + $res =spl_autoload_register('__autoload'); } $this->_frameFactory = new \YiiNodeSocket\Frames\FrameFactory($this); $this->_db = new \YiiNodeSocket\Components\Db($this); diff --git a/lib/php/NodeSocketCommand.php b/lib/php/NodeSocketCommand.php index 938c639..f2484ba 100644 --- a/lib/php/NodeSocketCommand.php +++ b/lib/php/NodeSocketCommand.php @@ -32,17 +32,6 @@ class NodeSocketCommand extends \yii\console\Controller { */ private $_console; - public function actionIndex() { - $this->stdout( - "node-socket usage: \n\n" - ."./yii node-socket # show help\n" - ."./yii node-socket/start # start server\n" - ."./yii node-socket/stop # stop server\n" - ."./yii node-socket/restart # restart server\n" - ."./yii node-socket/get-pid # show pid of nodejs process\n\n" - ); - } - public function actionStart() { if (!$this->_start()) { $this->usageError("Cannot start server"); @@ -261,4 +250,4 @@ private function getConsole() { } return $this->_console; } -} +} \ No newline at end of file diff --git a/lib/php/behaviors/ArBehavior.php b/lib/php/behaviors/ArBehavior.php index fc30ee8..0bfef53 100644 --- a/lib/php/behaviors/ArBehavior.php +++ b/lib/php/behaviors/ArBehavior.php @@ -6,7 +6,7 @@ /** * Class ArBehavior * - * @method \CActiveRecord getOwner() + * * @package YiiNodeSocket\Behavior */ @@ -26,19 +26,23 @@ abstract class ArBehavior extends AttributeBehavior { * @throws \CException */ public function getNodeSocketComponent() { - if (!\Yii::app()->hasComponent($this->componentName)) { + if (!\Yii::$app->components($this->componentName)) { throw new \CException('Node socket component not found with the name `' . $this->componentName . "`"); } - return \Yii::app()->getComponent($this->componentName); + return \Yii::$app->getComponent($this->componentName); } + + public function getOwner(){ + return $this->owner; + } /** * @param ArEvent $event */ protected function triggerModelEvent(ArEvent $event) { $owner = $this->getOwner(); - if ($owner->hasEvent($event->name)) { - $owner->raiseEvent($event->name, $event); + if ($owner->hasEventHandlers($event->name)) { + $owner->trigger($event->name, $event); } } -} \ No newline at end of file +} diff --git a/lib/php/behaviors/ArChannel.php b/lib/php/behaviors/ArChannel.php index 117ba56..df8979f 100644 --- a/lib/php/behaviors/ArChannel.php +++ b/lib/php/behaviors/ArChannel.php @@ -91,7 +91,8 @@ public function createChannel() { $this->attributesToChannel($this->_channel); $this->_channel->name = $this->getChannelName(); - $event = new ArEvent($this); + $event = new ArEvent(); + $event->sender = $this; $event->name = 'onChannelSave'; $event->error = !$this->_channel->save(); $this->triggerModelEvent($event); @@ -101,7 +102,8 @@ public function updateChannel() { if ($channel = $this->getChannel()) { $this->attributesToChannel($channel); - $event = new ArEvent($this); + $event = new ArEvent(); + $event->sender = $this; $event->name = 'onChannelSave'; $event->error = !$channel->save(); $this->triggerModelEvent($event); @@ -124,9 +126,10 @@ public function getChannel() { if (isset($this->_channel)) { return $this->_channel; } - $this->_channel = Channel::model()->findByAttributes(array( + $channel = Channel::model()->findByAttributes(array( 'name' => $this->getChannelName() )); + $this->_channel = $channel; return $this->_channel; } @@ -180,8 +183,8 @@ protected function attributesToChannel(Channel $channel) { protected function getChannelName() { $pk = $this->getOwner()->getPrimaryKey(); if (is_array($pk)) { - $pk = md5(\CJSON::encode($pk)); + $pk = md5(\yii\helpers\Json::encode($pk)); } - return get_class($this->getOwner()) . ':' . $pk; + return $pk;//get_class($this->getOwner()) . ':' . $pk; } } \ No newline at end of file diff --git a/lib/php/components/ArEvent.php b/lib/php/components/ArEvent.php index 64758cf..df2df72 100644 --- a/lib/php/components/ArEvent.php +++ b/lib/php/components/ArEvent.php @@ -1,8 +1,8 @@ _nodeSocket); + $evt = new Event($this->_nodeSocket); + return $evt; } /** diff --git a/lib/php/models/AModel.php b/lib/php/models/AModel.php index 38b9e19..d55fbf6 100644 --- a/lib/php/models/AModel.php +++ b/lib/php/models/AModel.php @@ -7,7 +7,7 @@ * Class AModel * @package YiiNodeSocket\Models */ -abstract class AModel extends \CModel{ +abstract class AModel extends \yii\base\Model{ /** * @var string @@ -46,7 +46,9 @@ public function __construct($scenario = 'insert') { $this->_isNewRecord = ($scenario == 'insert'); $this->init(); - $this->afterConstruct(); + +// $this->afterConstruct(); + } /** @@ -70,13 +72,13 @@ final public function load(array $attributes) { } } - protected function init() {} + public function init() {} /** * @return \NodeSocket */ public function getNodeSocket() { - return \Yii::app()->nodeSocket; + return \Yii::$app->nodeSocket; } /** @@ -94,31 +96,31 @@ public function getIsNewRecord() { } /** - * @param \CModelEvent $event + * @param \yii\base\ModelEvent $event */ - public function onBeforeSave(\CModelEvent $event) { - $this->raiseEvent('onBeforeSave', $event); + public function onBeforeSave(\yii\base\ModelEvent $event) { + $this->trigger('onBeforeSave', $event); } /** - * @param \CModelEvent $event + * @param \yii\base\ModelEvent $event */ - public function onAfterSave(\CModelEvent $event) { - $this->raiseEvent('onAfterSave', $event); + public function onAfterSave(\yii\base\ModelEvent $event) { + $this->trigger('onAfterSave', $event); } /** - * @param \CModelEvent $event + * @param \yii\base\ModelEvent $event */ - public function onBeforeDelete(\CModelEvent $event) { - $this->raiseEvent('onBeforeDelete', $event); + public function onBeforeDelete(\yii\base\ModelEvent $event) { + $this->trigger('onBeforeDelete', $event); } /** - * @param \CModelEvent $event + * @param \yii\base\ModelEvent $event */ - public function onAfterDelete(\CModelEvent $event) { - $this->raiseEvent('onAfterDelete', $event); + public function onAfterDelete(\yii\base\ModelEvent $event) { + $this->trigger('onAfterDelete', $event); } /** @@ -126,7 +128,7 @@ public function onAfterDelete(\CModelEvent $event) { */ public function rules() { return array( - array('id', 'length', 'allowEmpty' => true), + array('id', 'string', 'skipOnEmpty' => true), array('id', 'safe') ); } @@ -217,13 +219,15 @@ public function attributeNames() { } protected function beforeSave() { - $event = new \CModelEvent($this); + $event = new \yii\base\ModelEvent(); + $event->sender = $this; $this->onBeforeSave($event); return $event->isValid; } protected function afterSave() { - $modelEvent = new \CModelEvent($this); + $modelEvent = new \yii\base\ModelEvent(); + $modelEvent->sender = $this; $this->onAfterSave($modelEvent); if ($modelEvent->isValid) { $event = $this->getNodeSocket()->getFrameFactory()->createChannelEventFrame(); @@ -235,13 +239,15 @@ protected function afterSave() { } protected function beforeDelete() { - $event = new \CModelEvent($this); + $event = new \yii\base\ModelEvent(); + $event->sender = $this; $this->onBeforeDelete($event); return $event->isValid; } protected function afterDelete() { - $modelEvent = new \CModelEvent($this); + $modelEvent = new \yii\base\ModelEvent(); + $modelEvent->sender = $this; $this->onAfterDelete($modelEvent); if ($modelEvent->isValid) { $event = $this->getNodeSocket()->getFrameFactory()->createChannelEventFrame(); @@ -257,4 +263,4 @@ protected function beforeLoad(array $attributes) { } protected function afterLoad() {} -} \ No newline at end of file +} diff --git a/lib/php/models/Channel.php b/lib/php/models/Channel.php index 6af8a26..e81c83b 100644 --- a/lib/php/models/Channel.php +++ b/lib/php/models/Channel.php @@ -61,19 +61,19 @@ public function getSourceList() { self::SOURCE_PHP_OR_JAVASCRIPT ); } - + /** * @return array */ public function rules() { return array_merge(parent::rules(), array( - array('name, is_authentication_required, subscriber_source, event_source', 'required'), + array(['name', 'is_authentication_required', 'subscriber_source', 'event_source'], 'required'), array('name', 'validateUniqueName'), - array('name', 'length', 'min' => 2), - array('properties', 'length', 'max' => 65000, 'allowEmpty' => true), - array('subscriber_source, event_source', 'numerical', 'integerOnly' => true), - array('subscriber_source, event_source', 'in', 'range' => $this->getSourceList()), - array('allowed_roles', 'length', 'min' => 1, 'allowEmpty' => true), + array('name', 'string', 'min' => 2), + array('properties', 'string', 'max' => 65000, 'skipOnEmpty' => true), + array(['subscriber_source', 'event_source'], 'integer'), + array(['subscriber_source', 'event_source'], 'in', 'range' => $this->getSourceList()), + array('allowed_roles', 'string', 'min' => 1, 'skipOnEmpty' => true), array('create_date', 'safe') )); } @@ -158,9 +158,9 @@ public function validateUniqueName() { /** * @return bool */ - protected function beforeValidate() { + public function beforeValidate() { if (is_array($this->properties) || is_object($this->properties)) { - $this->properties = \CJSON::encode($this->properties); + $this->properties = \yii\helpers\Json::encode($this->properties); } else if (!is_string($this->properties)) { $this->properties = ''; } @@ -184,7 +184,7 @@ protected function beforeSave() { protected function afterLoad() { if ($this->properties) { - $this->properties = \CJSON::decode($this->properties); + $this->properties = \yii\helpers\Json::decode($this->properties); } } -} \ No newline at end of file +} From a293c42f97b296c2327fc68457d3e9baee4548a3 Mon Sep 17 00:00:00 2001 From: ratacibernetica Date: Fri, 11 Sep 2015 23:24:43 -0500 Subject: [PATCH 10/16] Updated with more Yii2 notes. --- README.md | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 207cfb5..4e0f3c3 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Yii configuration
], ``` - * Register Yii component, need to add into **frontend/config/main.php in your frontend application**: + * Register Yii component, need to add into **frontend/config/main.php in your frontend application, it's also needed in console/config/main**: ```php 'nodeSocket' => [ @@ -81,7 +81,8 @@ Yii configuration
'socketLogFile' => '/var/log/node-socket.log', ], ``` -> Notice: ***host*** should be a domain name like in you virtual host configuration or server ip address if you request page using ip address +> Notice: ***host*** should be a domain name like in you virtual host configuration or server ip address if you request page using ip addres +> Also, you could see the logs at **console/runtime/socket-transport.server.log** * 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. @@ -113,18 +114,18 @@ 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 -###Console command actions +###Console command actions (Yii2) -Use (**./yiic node-socket**) +Use (**./yii node-socket**) ```bash -$> ./yiic node-socket # show help -$> ./yiic node-socket start # start server -$> ./yiic node-socket stop # stop server -$> ./yiic node-socket restart # restart server -$> ./yiic node-socket getPid # show pid of nodejs process +$> ./yii node-socket # show help <-- Not Working +$> ./yii node-socket start # start server +$> ./yii node-socket stop # stop server +$> ./yii node-socket restart # restart server +$> ./yii node-socket getPid # show pid of nodejs process ``` - +> Notice: in case comes an error about Class User not defined, move the User definition from common/config to frontend/config (or backend) ##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. @@ -140,6 +141,12 @@ public function actionIndex() { // No longer needed - Yii::app()->nodeSocket->registerClientScripts(); } ``` +> Notice: in order to load assets in Yii2, i needed to add this in the main layout: + +```php +\YiiNodeSocket\Assets\NodeSocketAssets::register($this); +AppAsset::register($this); +``` ###Events From 216a251f1dbea3bbb5784a03374ebf886e63798e Mon Sep 17 00:00:00 2001 From: ratacibernetica Date: Wed, 16 Sep 2015 21:50:52 -0500 Subject: [PATCH 11/16] Added jquery's get() and play() methods --- README.md | 27 ++++++++------------ lib/js/client/client.template.js | 4 +++ lib/php/components/frames/JQuerySelector.php | 18 +++++++++++++ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4e0f3c3..207cfb5 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Yii configuration
], ``` - * Register Yii component, need to add into **frontend/config/main.php in your frontend application, it's also needed in console/config/main**: + * Register Yii component, need to add into **frontend/config/main.php in your frontend application**: ```php 'nodeSocket' => [ @@ -81,8 +81,7 @@ Yii configuration
'socketLogFile' => '/var/log/node-socket.log', ], ``` -> Notice: ***host*** should be a domain name like in you virtual host configuration or server ip address if you request page using ip addres -> Also, you could see the logs at **console/runtime/socket-transport.server.log** +> 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. @@ -114,18 +113,18 @@ 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 -###Console command actions (Yii2) +###Console command actions -Use (**./yii node-socket**) +Use (**./yiic node-socket**) ```bash -$> ./yii node-socket # show help <-- Not Working -$> ./yii node-socket start # start server -$> ./yii node-socket stop # stop server -$> ./yii node-socket restart # restart server -$> ./yii node-socket getPid # show pid of nodejs process +$> ./yiic node-socket # show help +$> ./yiic node-socket start # start server +$> ./yiic node-socket stop # stop server +$> ./yiic node-socket restart # restart server +$> ./yiic node-socket getPid # show pid of nodejs process ``` -> Notice: in case comes an error about Class User not defined, move the User definition from common/config to frontend/config (or backend) + ##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. @@ -141,12 +140,6 @@ public function actionIndex() { // No longer needed - Yii::app()->nodeSocket->registerClientScripts(); } ``` -> Notice: in order to load assets in Yii2, i needed to add this in the main layout: - -```php -\YiiNodeSocket\Assets\NodeSocketAssets::register($this); -AppAsset::register($this); -``` ###Events diff --git a/lib/js/client/client.template.js b/lib/js/client/client.template.js index 6527420..c3931aa 100644 --- a/lib/js/client/client.template.js +++ b/lib/js/client/client.template.js @@ -321,6 +321,10 @@ $this.remove(); return; break; + case 'play': + $this[0].play(); + return; + break; case 'parents': case 'find': diff --git a/lib/php/components/frames/JQuerySelector.php b/lib/php/components/frames/JQuerySelector.php index 479a05c..edf6a8b 100644 --- a/lib/php/components/frames/JQuerySelector.php +++ b/lib/php/components/frames/JQuerySelector.php @@ -118,6 +118,16 @@ public function addClass($class) { } return $this; } + + /** + * @param string $class + * + * @return JQuerySelector + */ + public function play() { + $this->createAction('play'); + return $this; + } /** * @param string $class @@ -176,6 +186,14 @@ public function remove() { $this->createAction('remove'); return $this; } + + /** + * @return JQuerySelector + */ + public function get() { + $this->createAction('get'); + return $this; + } /** * @return JQuerySelector From 90c38a56a1546fae951ac6240d684f7437dd68e3 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 2 Oct 2015 10:18:28 -0500 Subject: [PATCH 12/16] Added Disclaimer in README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 207cfb5..b64bb6b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -Yii 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. From cab2cd78b5e70cd3a417f37afd03c6f08b7d932a Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 2 Oct 2015 10:30:57 -0500 Subject: [PATCH 13/16] composer updated for packagist --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index d71fd80..13a4915 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { - "name": "oncesk/yii-node-socket", - "description": "Реализует связь между php и client javascript по средству сокет соединения.", + "name": "ratacibernetica/yii2-node-socket", + "description": "This is a fork of oncesk/yii-node-socket", "minimum-stability": "stable", "authors": [ - { - "name": "Alexey Panasik", - "email": "unnfly@gmail.com" + { + "name": "Martin Roldan Araujo", + "email": "yo@ratacibernetica.com" } ], "require": { From c49c34842bac7c5c9aef57369f419d521069b27c Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 2 Oct 2015 10:46:11 -0500 Subject: [PATCH 14/16] Updated composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 13a4915..facc9f5 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ratacibernetica/yii2-node-socket", "description": "This is a fork of oncesk/yii-node-socket", - "minimum-stability": "stable", + "minimum-stability": "dev", "authors": [ { "name": "Martin Roldan Araujo", From 4dcc6a453c5739de825b1c8e97417879b24a17d5 Mon Sep 17 00:00:00 2001 From: ratacibernetica Date: Mon, 18 Jul 2016 10:41:11 -0500 Subject: [PATCH 15/16] Added ssl options --- lib/js/client/client.template.js | 2 +- lib/js/server/server.js | 17 +++++++++++++++-- lib/php/NodeSocket.php | 6 +++--- lib/php/assets/NodeSocketAssets.php | 2 +- lib/php/frames/AFrame.php | 5 +++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/js/client/client.template.js b/lib/js/client/client.template.js index c3931aa..96bb8b1 100644 --- a/lib/js/client/client.template.js +++ b/lib/js/client/client.template.js @@ -648,7 +648,7 @@ 'type' : 'global' }); - socket = io.connect('http://host;?>:port;?>/client'); + socket = io.connect('//host;?>:port;?>/client',{secure: true, rejectUnauthorized: false}); var systemEventsHandlerBinder = new SystemEventsHandlerBinder(this); diff --git a/lib/js/server/server.js b/lib/js/server/server.js index 2466196..15283f5 100644 --- a/lib/js/server/server.js +++ b/lib/js/server/server.js @@ -1,6 +1,16 @@ var express = require('express'); + +fs = require('fs'); + +var options = { + key: fs.readFileSync('/var/www/html/hola-trabajo-web/vendor/ratacibernetica/yii2-node-socket/lib/js/server/ssl/server.key'), + cert: fs.readFileSync('/var/www/html/hola-trabajo-web/vendor/ratacibernetica/yii2-node-socket/lib/js/server/ssl/server.crt'), + //ca: fs.readFileSync('ssl/ca.crt') +}; var app = express(); -var server = require('http').createServer(app) + + +var server = require('https').createServer(options,app); var io = require('socket.io').listen(server); var cookie = require('cookie'); var serverConfiguration = require('./server.config.js'); @@ -125,6 +135,8 @@ io.of('/server').authorization(function (data, accept) { data.sid = data.cookie.PHPSESSID; var found = false; for (var i in serverConfiguration.allowedServers) { + console.log(i); + console.log(serverConfiguration); if (serverConfiguration.allowedServers[i] == data.address.address) { found = true; break; @@ -178,6 +190,7 @@ io.of('/server').authorization(function (data, accept) { }); } else { accept('INVALID SERVER: server host ' + data.address.address + ' not allowed'); + console.log(serverConfiguration.allowedServers); } } else { accept('PHPSESSID is undefined', false); @@ -196,4 +209,4 @@ io.of('/server').authorization(function (data, accept) { eventManager.server.bind(socket); }); -componentManager.initCompleted(); \ No newline at end of file +componentManager.initCompleted(); diff --git a/lib/php/NodeSocket.php b/lib/php/NodeSocket.php index 34badd6..c7b659b 100644 --- a/lib/php/NodeSocket.php +++ b/lib/php/NodeSocket.php @@ -45,7 +45,7 @@ class NodeSocket extends Component { * * @var int */ - public $port = 3001; + public $port = 8443; /** * Can be string, every domain|ip separated by a comma @@ -78,7 +78,7 @@ class NodeSocket extends Component { * * @var bool */ - public $checkClientOrigin = true; + public $checkClientOrigin = false; /** * @var string @@ -88,7 +88,7 @@ class NodeSocket extends Component { /** * @var int timeout for handshaking in miliseconds */ - public $handshakeTimeout = 2000; + public $handshakeTimeout = 50000; /** * @var array diff --git a/lib/php/assets/NodeSocketAssets.php b/lib/php/assets/NodeSocketAssets.php index d4ebeda..df36119 100644 --- a/lib/php/assets/NodeSocketAssets.php +++ b/lib/php/assets/NodeSocketAssets.php @@ -32,7 +32,7 @@ class NodeSocketAssets extends AssetBundle public function init() { $this->js[] = sprintf( - "http://%s:%d%s", Yii::$app->nodeSocket->host, Yii::$app->nodeSocket->port, '/socket.io/socket.io.js' + "//%s:%d%s", Yii::$app->nodeSocket->host, Yii::$app->nodeSocket->port, '/socket.io/socket.io.js' ); $this->js[] = 'client/client.js'; } diff --git a/lib/php/frames/AFrame.php b/lib/php/frames/AFrame.php index 27da27e..87cd092 100644 --- a/lib/php/frames/AFrame.php +++ b/lib/php/frames/AFrame.php @@ -159,6 +159,7 @@ protected function emit() { $client = $this->createClient(); $client->origin = $this->_nodeSocket->getOrigin(); $client->sendCookie = true; +// $client->setSslCert('/var/www/html/hola-trabajo-web/vendor/ratacibernetica/yii2-node-socket/lib/js/server/ssl/server.crt'); $client->cookie = implode('; ', array( 'PHPSESSID=' . \Yii::$app->session->id, 'expires=' . (time() + $this->_nodeSocket->cookieLifeTime) @@ -179,7 +180,7 @@ protected function emit() { */ protected function createClient() { return new \ElephantIO\Client( - sprintf('http://%s:%s', $this->_nodeSocket->host, $this->_nodeSocket->port), + sprintf('https://%s:%s', $this->_nodeSocket->host, $this->_nodeSocket->port), 'socket.io', 1, false @@ -313,4 +314,4 @@ public function offsetSet($offset, $value) { public function offsetUnset($offset) { unset($this->_container['data'][$offset]); } -} \ No newline at end of file +} From 65e929ad7427c675e484f913a3a96e5ab87c754a Mon Sep 17 00:00:00 2001 From: ratacibernetica Date: Mon, 18 Jul 2016 10:45:19 -0500 Subject: [PATCH 16/16] Specified elephant.io version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index facc9f5..8a8c3b7 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "oncesk/elephant.io": "*" + "oncesk/elephant.io": "v2.0.2" }, "autoload": { "psr-4": {