Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "oncesk/yii-node-socket",
"description": "Реализует связь между php и client javascript по средству сокет соединения.",
"minimum-stability": "stable",
"name": "ratacibernetica/yii2-node-socket",
"description": "This is a fork of oncesk/yii-node-socket",
"minimum-stability": "dev",
"authors": [
{
"name": "Alexey Panasik",
"email": "unnfly@gmail.com"
{
"name": "Martin Roldan Araujo",
"email": "yo@ratacibernetica.com"
}
],
"require": {
"oncesk/elephant.io": "*"
"oncesk/elephant.io": "v2.0.2"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 5 additions & 1 deletion lib/js/client/client.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@
$this.remove();
return;
break;
case 'play':
$this[0].play();
return;
break;

case 'parents':
case 'find':
Expand Down Expand Up @@ -644,7 +648,7 @@
'type' : 'global'
});

socket = io.connect('http://<?php echo $nodeSocket->host;?>:<?php echo $nodeSocket->port;?>/client');
socket = io.connect('//<?php echo $nodeSocket->host;?>:<?php echo $nodeSocket->port;?>/client',{secure: true, rejectUnauthorized: false});

var systemEventsHandlerBinder = new SystemEventsHandlerBinder(this);

Expand Down
17 changes: 15 additions & 2 deletions lib/js/server/server.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -196,4 +209,4 @@ io.of('/server').authorization(function (data, accept) {
eventManager.server.bind(socket);
});

componentManager.initCompleted();
componentManager.initCompleted();
3 changes: 2 additions & 1 deletion lib/php/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions lib/php/NodeSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -44,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
Expand Down Expand Up @@ -77,7 +78,7 @@ class NodeSocket extends Component {
*
* @var bool
*/
public $checkClientOrigin = true;
public $checkClientOrigin = false;

/**
* @var string
Expand All @@ -87,7 +88,7 @@ class NodeSocket extends Component {
/**
* @var int timeout for handshaking in miliseconds
*/
public $handshakeTimeout = 2000;
public $handshakeTimeout = 50000;

/**
* @var array
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/php/assets/NodeSocketAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
16 changes: 10 additions & 6 deletions lib/php/behaviors/ArBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Class ArBehavior
*
* @method \CActiveRecord getOwner()

*
* @package YiiNodeSocket\Behavior
*/
Expand All @@ -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);
}
}
}
}
13 changes: 8 additions & 5 deletions lib/php/behaviors/ArChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions lib/php/components/ArEvent.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace YiiNodeSocket\Components;

class ArEvent extends \CModelEvent {
class ArEvent extends \yii\base\ModelEvent {

public $name;
public $name;
public $error = false;
}
18 changes: 18 additions & 0 deletions lib/php/components/frames/JQuerySelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -176,6 +186,14 @@ public function remove() {
$this->createAction('remove');
return $this;
}

/**
* @return JQuerySelector
*/
public function get() {
$this->createAction('get');
return $this;
}

/**
* @return JQuerySelector
Expand Down
5 changes: 3 additions & 2 deletions lib/php/frames/AFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -313,4 +314,4 @@ public function offsetSet($offset, $value) {
public function offsetUnset($offset) {
unset($this->_container['data'][$offset]);
}
}
}
21 changes: 11 additions & 10 deletions lib/php/frames/FrameFactory.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
namespace YiiNodeSocket\Frames;

require_once 'AFrame.php';
require_once 'Event.php';
require_once 'Authentication.php';
require_once 'UserEvent.php';
require_once 'ChannelEvent.php';
require_once 'Multiple.php';
require_once 'PublicData.php';
require_once 'Invoke.php';
require_once 'JQuery.php';
require_once __DIR__.'/AFrame.php';
require_once __DIR__.'/Event.php';
require_once __DIR__.'/Authentication.php';
require_once __DIR__.'/UserEvent.php';
require_once __DIR__.'/ChannelEvent.php';
require_once __DIR__.'/Multiple.php';
require_once __DIR__.'/PublicData.php';
require_once __DIR__.'/Invoke.php';
require_once __DIR__.'/JQuery.php';

class FrameFactory implements IFrameFactory {

Expand All @@ -29,7 +29,8 @@ public function __construct(\YiiNodeSocket\NodeSocket $transport) {
* @return Event
*/
public function createEventFrame() {
return new Event($this->_nodeSocket);
$evt = new Event($this->_nodeSocket);
return $evt;
}

/**
Expand Down
Loading