Skip to content

Commit 6a4678c

Browse files
committed
Operator/Visitor typing monitoring
1 parent dee8fdd commit 6a4678c

10 files changed

Lines changed: 256 additions & 7 deletions

nodejshelper/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
serversc/lhc/node_modules
33
serversc/lhc/node_modules
4-
settings/settings.ini.php
4+
settings/settings.ini.php
5+
package-lock.json
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
var channelList = [];
2+
3+
(function() {
4+
5+
var socketOptions = {
6+
hostname: lh.nodejsHelperOptions.hostname,
7+
path: lh.nodejsHelperOptions.path
8+
}
9+
10+
if (lh.nodejsHelperOptions.port != '') {
11+
socketOptions.port = parseInt(lh.nodejsHelperOptions.port);
12+
}
13+
14+
if (lh.nodejsHelperOptions.secure == 1) {
15+
socketOptions.secure = true;
16+
}
17+
18+
// Initiate the connection to the server
19+
var socket = socketCluster.connect(socketOptions);
20+
21+
socket.on('error', function (err) {
22+
console.error(err);
23+
});
24+
25+
function addChatToNodeJS(chat_id) {
26+
if (typeof channelList[chat_id] === 'undefined')
27+
{
28+
channelList[chat_id] = socket.subscribe('chat_' + chat_id);
29+
30+
channelList[chat_id].on('subscribeFail', function (err) {
31+
console.error('Failed to subscribe to the sample channel due to error: ' + err);
32+
});
33+
34+
var typingIndicator = $('#user-is-typing-'+chat_id);
35+
36+
channelList[chat_id].watch(function (op) {
37+
if (op.op == 'vt') { // Visitor typing text
38+
typingIndicator.html(op.msg).css('visibility','visible');
39+
} else if (op.op == 'vts') { // Visitor typing stopped
40+
typingIndicator.html(op.msg).css('visibility','hidden');
41+
}
42+
});
43+
}
44+
}
45+
46+
function operatorTypingListener(data) {
47+
data.ttx = lh.nodejsHelperOptions.typer;
48+
ee.emitEvent('nodeJsTypingOperator', [data]);
49+
socket.publish('chat_'+data.chat_id,{'op':'ot','data':data}); // Operator typing
50+
}
51+
52+
function removeSynchroChatListener(chat_id) {
53+
channelList[chat_id].destroy();
54+
delete channelList[chat_id];
55+
}
56+
57+
socket.on('close', function() {
58+
lhinst.nodeJsMode = false;
59+
channelList.forEach(function(channel){
60+
channel.destroy();
61+
});
62+
channelList = [];
63+
64+
ee.removeListener('chatTabLoaded', addChatToNodeJS);
65+
ee.removeListener('operatorTyping', operatorTypingListener);
66+
ee.removeListener('removeSynchroChat', removeSynchroChatListener);
67+
});
68+
69+
socket.on('connect', function () {
70+
71+
lhinst.nodeJsMode = true;
72+
73+
lhinst.chatsSynchronising.forEach(function (chat_id) {
74+
addChatToNodeJS(chat_id);
75+
});
76+
77+
ee.addListener('chatTabLoaded', addChatToNodeJS);
78+
ee.addListener('operatorTyping', operatorTypingListener);
79+
ee.addListener('removeSynchroChat', removeSynchroChatListener);
80+
});
81+
82+
})();
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
(function() {
2+
3+
var socketOptions = {
4+
hostname: lh.nodejsHelperOptions.hostname,
5+
path: lh.nodejsHelperOptions.path
6+
}
7+
8+
if (lh.nodejsHelperOptions.port != '') {
9+
socketOptions.port = parseInt(lh.nodejsHelperOptions.port);
10+
}
11+
12+
if (lh.nodejsHelperOptions.secure == 1) {
13+
socketOptions.secure = true;
14+
}
15+
16+
// Initiate the connection to the server
17+
var socket = socketCluster.connect(socketOptions);
18+
19+
var sampleChannel = null;
20+
21+
socket.on('error', function (err) {
22+
console.error(err);
23+
});
24+
25+
function visitorTypingListener(data)
26+
{
27+
socket.publish('chat_'+lhinst.chat_id,{'op':'vt','msg':data.msg});
28+
}
29+
30+
function visitorTypingStoppedListener()
31+
{
32+
socket.publish('chat_'+lhinst.chat_id,{'op':'vts'});
33+
}
34+
35+
socket.on('close', function(){
36+
LHCCallbacks.initTypingMonitoringUserInform = false;
37+
38+
if (sampleChannel !== null) {
39+
sampleChannel.destroy();
40+
}
41+
42+
ee.removeListener('visitorTyping', visitorTypingListener);
43+
ee.removeListener('visitorTypingStopped', visitorTypingStoppedListener);
44+
});
45+
46+
socket.on('connect', function () {
47+
48+
if (lhinst.chat_id > 0) {
49+
sampleChannel = socket.subscribe('chat_' + lhinst.chat_id);
50+
51+
sampleChannel.on('subscribeFail', function (err) {
52+
console.error('Failed to subscribe to the sample channel due to error: ' + err);
53+
});
54+
55+
sampleChannel.watch(function (op) {
56+
if (op.op == 'ot') { // Operator Typing Message
57+
var instStatus = $('#id-operator-typing');
58+
if (op.data.status == true) {
59+
instStatus.text(op.data.ttx);
60+
instStatus.css('visibility','visible');
61+
} else {
62+
instStatus.css('visibility','hidden');
63+
}
64+
}
65+
});
66+
67+
// Disable default method
68+
LHCCallbacks.initTypingMonitoringUserInform = true;
69+
70+
ee.addListener('visitorTyping', visitorTypingListener);
71+
ee.addListener('visitorTypingStopped', visitorTypingStoppedListener);
72+
};
73+
});
74+
75+
76+
77+
})();

nodejshelper/design/nodejshelpertheme/js/nodejshelper.admin.min.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejshelper/design/nodejshelpertheme/js/nodejshelper.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejshelper/design/nodejshelpertheme/js/nodejshelper.widget.min.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php if (
2+
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 10.0') === false &&
3+
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 9.0') === false &&
4+
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 8.0') === false &&
5+
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7.0') === false
6+
) : ?>
7+
8+
<script>
9+
lh.nodejsHelperOptions = {
10+
'hostname':'<?php echo erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionNodejshelper')->getSettingVariable('hostname')?>',
11+
'path':'<?php echo erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionNodejshelper')->getSettingVariable('path')?>',
12+
'port':'<?php echo erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionNodejshelper')->getSettingVariable('port')?>',
13+
'secure':'<?php echo erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionNodejshelper')->getSettingVariable('secure')?>'
14+
};
15+
16+
<?php if (erLhcoreClassSystem::instance()->SiteAccess == 'site_admin' && erLhcoreClassUser::instance()->isLogged()) :
17+
$currentUser = erLhcoreClassUser::instance();
18+
$userData = $currentUser->getUserData(true); ?>
19+
lh.nodejsHelperOptions.typer = typeof lh.nodejsHelperOptions.typer !== 'undefined' ? lh.nodejsHelperOptions.typer : '<?php echo htmlspecialchars($userData->name_support,ENT_QUOTES);?> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chat','is typing now...')?>';
20+
<?php endif;?>
21+
22+
</script>
23+
<script src="<?php echo erLhcoreClassDesign::designJS('js/nodejshelper.admin.min.js');?>"></script>
24+
<?php endif; ?>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php if (isset($Result['is_sync_required']) && $Result['is_sync_required'] === true) : ?>
2+
3+
<?php if (
4+
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 10.0') === false &&
5+
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 9.0') === false &&
6+
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 8.0') === false &&
7+
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7.0') === false
8+
) : ?>
9+
10+
<script>
11+
lh.nodejsHelperOptions = {
12+
'hostname':'<?php echo erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionNodejshelper')->getSettingVariable('hostname')?>',
13+
'path':'<?php echo erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionNodejshelper')->getSettingVariable('path')?>',
14+
'port':'<?php echo erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionNodejshelper')->getSettingVariable('port')?>',
15+
'secure':'<?php echo erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionNodejshelper')->getSettingVariable('secure')?>',
16+
};
17+
</script>
18+
<script src="<?php echo erLhcoreClassDesign::designJS('js/nodejshelper.widget.min.js');?>"></script>
19+
<?php endif; ?>
20+
<?php endif; ?>

nodejshelper/gulpfile.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ gulp.task('js-nodejshelper', function() {
1313
.pipe(gulp.dest('design/nodejshelpertheme/js'));
1414
});
1515

16-
gulp.task('default', ['js-nodejshelper'], function() {
17-
// Just execute all the tasks
18-
});
16+
gulp.task('js-nodejshelper-widget', function() {
17+
var stylePath = ['design/nodejshelpertheme/js/socketcluster.js',
18+
'design/nodejshelpertheme/js/customjs-widget.js'];
19+
return gulp.src(stylePath)
20+
.pipe(concat('nodejshelper.widget.min.js'))
21+
.pipe(uglify({preserveComments: 'some'}))
22+
.pipe(gulp.dest('design/nodejshelpertheme/js'));
23+
});
24+
25+
gulp.task('js-nodejshelper-admin', function() {
26+
var stylePath = ['design/nodejshelpertheme/js/socketcluster.js',
27+
'design/nodejshelpertheme/js/customjs-admin.js'];
28+
return gulp.src(stylePath)
29+
.pipe(concat('nodejshelper.admin.min.js'))
30+
.pipe(uglify({preserveComments: 'some'}))
31+
.pipe(gulp.dest('design/nodejshelpertheme/js'));
32+
});
33+
34+
gulp.task('default', gulp.series('js-nodejshelper','js-nodejshelper-widget','js-nodejshelper-admin', function() {
35+
// Just execute all the tasks
36+
}));

nodejshelper/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"devDependencies": {
3+
"gulp": "^4.0.0",
4+
"gulp-concat": "^2.6.1",
5+
"gulp-uglify": "^1.5.4",
6+
"gulp-util": "~3.0.3",
7+
"gulp-watch": "^4.3.11"
8+
},
9+
"scripts": {},
10+
"dependencies": {}
11+
}

0 commit comments

Comments
 (0)