From a0672ae150a8068d74a6aa83858aa6d313eb2810 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Wed, 24 Apr 2019 15:32:17 -0300 Subject: [PATCH] [NEW]Set up livechat connections created from new client (#14236) * Adds a new method to set up livechat connections. * Store livechatToken into connection. --- app/livechat/server/index.js | 1 + .../server/methods/setUpConnection.js | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 app/livechat/server/methods/setUpConnection.js diff --git a/app/livechat/server/index.js b/app/livechat/server/index.js index 70994cc2be10..3458109384d3 100644 --- a/app/livechat/server/index.js +++ b/app/livechat/server/index.js @@ -54,6 +54,7 @@ import './methods/startVideoCall'; import './methods/startFileUploadRoom'; import './methods/transfer'; import './methods/webhookTest'; +import './methods/setUpConnection'; import './methods/takeInquiry'; import './methods/returnAsInquiry'; import './methods/saveOfficeHours'; diff --git a/app/livechat/server/methods/setUpConnection.js b/app/livechat/server/methods/setUpConnection.js new file mode 100644 index 000000000000..bb040ff62131 --- /dev/null +++ b/app/livechat/server/methods/setUpConnection.js @@ -0,0 +1,21 @@ +import { Meteor } from 'meteor/meteor'; +import { check } from 'meteor/check'; +import { Livechat } from '../lib/Livechat'; + +Meteor.methods({ + 'livechat:setUpConnection'(data) { + + check(data, { + token: String, + }); + + const { token } = data; + + if (!this.connection.livechatToken) { + this.connection.livechatToken = token; + this.connection.onClose(() => { + Livechat.notifyGuestStatusChanged(token, 'offline'); + }); + } + }, +});