Skip to content

Commit 00ede3a

Browse files
committed
NodeJS Helper refactoring
1 parent aa7aaa6 commit 00ede3a

316 files changed

Lines changed: 14060 additions & 29545 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

nodejshelper/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
serversc/lhc/node_modules
Lines changed: 67 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,78 @@
11
<?php
22

33
class erLhcoreClassExtensionNodejshelper {
4+
45
public function __construct() {
56

67
}
7-
8-
private $settings = array();
9-
8+
109
public function run() {
11-
include 'extension/nodejshelper/design/nodejshelpertheme/tpl/pagelayouts/parts/nodejshelper_config.tpl.php';
12-
$this->settings = $nodeJsHelperSettings;
13-
14-
if ($this->settings['use_publish_notifications'] == true) {
15-
include_once 'extension/nodejshelper/vendor/predis-1.0.0/autoload.php';
16-
$dispatcher = erLhcoreClassChatEventDispatcher::getInstance();
17-
18-
// On what events should NodeJS listening operators be notified
19-
$dispatcher->listen('chat.sync_back_office',array($this,'notifyBackOfficeOperators'));
20-
$dispatcher->listen('chat.chat_started',array($this,'notifyBackOfficeOperators'));
21-
$dispatcher->listen('chat.data_changed',array($this,'notifyBackOfficeOperators'));
22-
$dispatcher->listen('chat.unread_chat',array($this,'notifyBackOfficeOperatorsDelay'));
23-
$dispatcher->listen('chat.data_changed_auto_assign',array($this,'notifyBackOfficeOperators'));
24-
$dispatcher->listen('chat.data_changed_assigned_department',array($this,'notifyBackOfficeOperators'));
25-
$dispatcher->listen('chat.close',array($this,'notifyBackOfficeOperators'));
26-
$dispatcher->listen('chat.delete',array($this,'notifyBackOfficeOperators'));
27-
$dispatcher->listen('chat.user_reopened',array($this,'notifyBackOfficeOperators'));
28-
$dispatcher->listen('chat.chat_transfer_accepted',array($this,'notifyBackOfficeOperators'));
29-
$dispatcher->listen('chat.chat_transfered',array($this,'notifyBackOfficeOperators'));
30-
$dispatcher->listen('chat.chat_transfered_force',array($this,'notifyBackOfficeOperators'));
31-
$dispatcher->listen('chat.sync_back_office',array($this,'notifyBackOfficeOperators'));
32-
$dispatcher->listen('survey.back_to_chat',array($this,'notifyBackOfficeOperators'));
33-
34-
// Listen to chat sub status changes
35-
$dispatcher->listen('chat.set_sub_status',array($this,'notifyUserNewMessage'));
36-
37-
// Listed for desktop client events
38-
$dispatcher->listen('chat.desktop_client_admin_msg',array($this,'notifyUserNewMessage'));
39-
$dispatcher->listen('chat.desktop_client_closed',array($this,'notifyUserNewMessage'));
40-
$dispatcher->listen('chat.desktop_client_deleted',array($this,'notifyUserNewMessage'));
41-
$dispatcher->listen('chat.messages_added_passive',array($this,'notifyUserNewMessage'));
42-
$dispatcher->listen('chat.data_changed_chat',array($this,'dataChangedChat'));
43-
$dispatcher->listen('chat.nodjshelper_notify_delay',array($this,'notifyBackOfficeOperatorsDelay'));
44-
}
45-
}
46-
47-
public function notifyBackOfficeOperators($params)
48-
{
49-
try {
50-
$client = new Predis\Client($this->settings['redis']);
51-
$client->publish('admin_room_'.$this->settings['instance_id'],'snow');
52-
} catch (Exception $e) {
53-
echo $e->getMessage();
54-
}
55-
}
56-
57-
public function notifyBackOfficeOperatorsDelay($params)
58-
{
59-
try {
60-
$client = new Predis\Client($this->settings['redis']);
61-
$client->publish('admin_room_'.$this->settings['instance_id'],'sdelay');
62-
} catch (Exception $e) {
63-
echo $e->getMessage();
64-
}
65-
}
66-
67-
public function dataChangedChat($params)
68-
{
69-
try {
70-
$client = new Predis\Client($this->settings['redis']);
71-
$client->publish('chat_room_'.$this->settings['instance_id'].'_'.$params['chat_id'],$params['chat_id']);
72-
} catch (Exception $e) {
73-
echo $e->getMessage();
74-
}
75-
}
76-
77-
public function notifyUserNewMessage($params)
78-
{
79-
try {
80-
$client = new Predis\Client($this->settings['redis']);
81-
$client->publish('chat_room_'.$this->settings['instance_id'].'_'.$params['chat']->id,$params['chat']->id);
82-
} catch (Exception $e) {
83-
echo $e->getMessage();
84-
}
10+
11+
$this->registerAutoload();
12+
13+
$dispatcher = erLhcoreClassChatEventDispatcher::getInstance();
14+
$dispatcher->listen('onlineuser.proactive_send_invitation',array($this,'proactiveInvitationSend'));
8515
}
16+
17+
public function __get($var)
18+
{
19+
switch ($var) {
20+
21+
case 'settings':
22+
$this->settings = include ('extension/nodejshelper/settings/settings.ini.php');
23+
return $this->settings;
24+
break;
25+
26+
default:
27+
;
28+
break;
29+
}
30+
}
31+
32+
public function getSettingVariable($var) {
33+
34+
switch ($var) {
35+
36+
case 'hostname':
37+
return $this->settings['public_settings']['hostname'];
38+
break;
39+
40+
case 'path':
41+
return $this->settings['public_settings']['path'];
42+
break;
43+
44+
default:
45+
return null;
46+
;
47+
break;
48+
}
49+
50+
}
51+
52+
public function registerAutoload()
53+
{
54+
spl_autoload_register(array(
55+
$this,
56+
'autoload'
57+
), true, false);
58+
}
59+
60+
public function autoload($className)
61+
{
62+
$classesArray = array(
63+
'erLhcoreClassNodeJSRedis' => 'extension/nodejshelper/classes/lhpredis.php'
64+
);
65+
66+
if (key_exists($className, $classesArray)) {
67+
include_once $classesArray[$className];
68+
}
69+
}
70+
71+
public function proactiveInvitationSend($params)
72+
{
73+
erLhcoreClassNodeJSRedis::instance()->publish('uo_' . $params['ou']->vid,'o:' . json_encode(array('op' => 'check_message')));
74+
//erLhcoreClassNodeJSRedis::instance()->publish('sample','o:' . json_encode(array('op' => 'check_message')));
75+
}
8676
}
8777

8878

nodejshelper/classes/lhpredis.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
class erLhcoreClassNodeJSRedis extends Credis_Client{
4+
5+
private static $instance = null;
6+
7+
public function __construct() {
8+
9+
$settings = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionNodejshelper')->settings;
10+
11+
$hostParts = explode(':', $settings['connect_db']);
12+
$port = isset($hostParts[1]) ? $hostParts[1] : 6379;
13+
14+
parent::__construct($hostParts[0],$port,null,'',$settings['connect_db_id']);
15+
}
16+
17+
public static function instance() {
18+
if (is_null(self::$instance)) {
19+
self::$instance = new self();
20+
}
21+
return self::$instance;
22+
}
23+
}
24+
25+
?>

0 commit comments

Comments
 (0)