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
1 change: 1 addition & 0 deletions app/livechat/server/api/lib/livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export async function settings(url) {
livechat_kill_switch_message: initSettings.Livechat_kill_switch_message,
livechat_friendly_chat: initSettings.Livechat_friendly_chat,
livechat_enable_avatar: initSettings.Livechat_enable_avatar,
Livechat_close_room_on_user_disconnect: initSettings.Livechat_close_room_on_user_disconnect,
livechat_enable_elastic_search_logs: initSettings.Livechat_enable_elastic_search_logs,
livechat_elastic_search_url: initSettings.Livechat_elastic_search_url,
livechat_elastic_search_index: initSettings.Livechat_elastic_search_index,
Expand Down
8 changes: 8 additions & 0 deletions app/livechat/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ Meteor.startup(function() {
i18nDescription: 'Livechat_enable_avatar_description',
});

this.add('Livechat_close_room_on_user_disconnect', true, {
type: 'boolean',
group: 'Omnichannel',
section: 'Livechat',
public: true,
i18nDescription: 'Livechat_close_room_on_user_disconnect_description',
});

this.add('Livechat_title', 'Rocket.Chat', {
type: 'string',
group: 'Omnichannel',
Expand Down
1 change: 1 addition & 0 deletions app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ export const Livechat = {
const rcSettings = {};

Settings.findNotHiddenPublic([
'Livechat_close_room_on_user_disconnect',
'Livechat_friendly_chat',
'Livechat_enable_avatar',
'Livechat_title',
Expand Down
1 change: 1 addition & 0 deletions app/livechat/server/methods/getInitialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Meteor.methods({
info.livechat_kill_switch_message = initSettings.Livechat_kill_switch_message;
info.livechat_friendly_chat = initSettings.Livechat_friendly_chat;
info.livechat_enable_avatar = initSettings.Livechat_enable_avatar;
info.Livechat_close_room_on_user_disconnect = initSettings.Livechat_close_room_on_user_disconnect;
info.livechat_enable_elastic_search_logs = initSettings.Livechat_enable_elastic_search_logs;
info.livechat_elastic_search_url = initSettings.Livechat_elastic_search_url;
info.livechat_elastic_search_index = initSettings.Livechat_elastic_search_index;
Expand Down
38 changes: 36 additions & 2 deletions app/livechat/server/methods/setUpConnection.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';

import { settings } from '../../../settings';
import { LivechatRooms, LivechatVisitors, LivechatDepartment } from '../../../models/server/index';
import { Livechat } from '../lib/Livechat';

const clients = {};

Meteor.methods({
'livechat:setUpConnection'(data) {
check(data, {
token: String,
isMobile: Boolean,
});

const { token } = data;
const { token, isMobile } = data;
clients[token] = clients[token] ? clients[token] + 1 : 1;

if (!this.connection.livechatToken) {
this.connection.livechatToken = token;
this.connection.isMobile = isMobile;
this.connection.onClose(() => {
Livechat.notifyGuestStatusChanged(token, 'offline');
clients[token] && (clients[token] -= 1);

const visitor = LivechatVisitors.getVisitorByToken(token);
const room = LivechatRooms.findOneOpenByVisitorToken(token);
const department = LivechatDepartment.findOneByIdOrName(room.departmentId);
const comment = TAPi18n.__('Closed_by_visitor', { lng: (visitor && visitor.language) || settings.get('Language') || 'en' });
const logOutput = {
rid: room._id,
currentBot: room.servedBy,
currentDepartment: {
id: department._id,
name: department.name,
email: department.email,
},
isHandedOverFromDialogFlow: !!room?.customFields?.isHandedOverFromDialogFlow,
agentAssigned: !!room?.customFields?.agentAssigned,
};
console.error('Browser closed by user :', JSON.stringify(logOutput));

if (this?.connection?.isMobile) {
return;
}
if (clients[token] === 0 && settings.get('Livechat_close_room_on_user_disconnect')) {
delete clients[token];
Livechat.notifyGuestStatusChanged(token, 'offline');
return Livechat.closeRoom({ visitor, room, comment });
}
});
}
},
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,8 @@
"Livechat": "Livechat",
"Livechat_friendly_chat": "Enable Friendly Chat",
"Livechat_friendly_chat_description": "Enables friendly chat UI in Livechat widget",
"Livechat_close_room_on_user_disconnect": "Close room when user disconnects",
"Livechat_close_room_on_user_disconnect_description": "Close room when user closes browser or is disconnected",
"Livechat_enable_avatar": "Show Avatar",
"Livechat_enable_avatar_description": "Show Avatars in Livechat widget",
"Livechat_enable_elastic_search_logs": "Enable sending logs to Elastic Search",
Expand Down