[NEW] Provide new Livechat client as community feature (#13723)

pull/13730/head^2
Renato Becker 7 years ago committed by Diego Sampaio
parent 558911336e
commit 36e7e25904
  1. 1
      .gitignore
  2. 10
      app/livechat/client/views/app/livechatInstallation.html
  3. 19
      app/livechat/client/views/app/livechatInstallation.js
  4. 29
      app/livechat/lib/Assets.js
  5. 41
      app/livechat/server/livechat.js
  6. 1
      packages/rocketchat-i18n/i18n/en.i18n.json
  7. 3
      packages/rocketchat-i18n/i18n/pt-BR.i18n.json
  8. 1
      packages/rocketchat-livechat/package.js
  9. 25
      packages/rocketchat-livechat/plugin/build.sh

1
.gitignore vendored

@ -77,3 +77,4 @@ build.sh
packages/rocketchat-i18n/i18n/livechat.*
tests/end-to-end/temporary_staged_test
.screenshots
/private/livechat

@ -1,10 +1,18 @@
<template name="livechatInstallation">
{{#requiresPermission 'view-livechat-manager'}}
<p>{{{_ "To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site"}}}</p>
<p>{{{_ "To_install_the_new_version_of_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site"}}}</p>
<div class="livechat-code">
<textarea class="clipboard" data-clipboard-target=".livechat-code textarea">{{script}}</textarea>
<button class="button clipboard" data-clipboard-target=".livechat-code textarea"><i class="icon-docs"></i>{{_ "Copy_to_clipboard"}}</button>
</div>
<p>{{{_ "To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site"}}}</p>
<div class="livechat-code clipboard-old">
<textarea class="clipboard" data-clipboard-target=".clipboard-old textarea">{{oldScript}}</textarea>
<button class="button clipboard" data-clipboard-target=".clipboard-old textarea"><i class="icon-docs"></i>{{_ "Copy_to_clipboard"}}</button>
</div>
{{/requiresPermission}}
</template>

@ -2,10 +2,11 @@ import { Template } from 'meteor/templating';
import { settings } from '../../../../settings';
import s from 'underscore.string';
const latestVersion = '1.0.0';
Template.livechatInstallation.helpers({
script() {
oldScript() {
const siteUrl = s.rtrim(settings.get('Site_Url'), '/');
return `<!-- Start of Rocket.Chat Livechat Script -->
<script type="text/javascript">
(function(w, d, s, u) {
@ -15,6 +16,20 @@ Template.livechatInstallation.helpers({
h.parentNode.insertBefore(j, h);
})(window, document, 'script', '${ siteUrl }/livechat');
</script>
<!-- End of Rocket.Chat Livechat Script -->`;
},
script() {
const siteUrl = s.rtrim(settings.get('Site_Url'), '/');
return `<!-- Start of Rocket.Chat Livechat Script -->
<script type="text/javascript">
(function(w, d, s, u) {
w.RocketChat = function(c) { w.RocketChat._.push(c) }; w.RocketChat._ = []; w.RocketChat.url = u;
var h = d.getElementsByTagName(s)[0], j = d.createElement(s);
j.async = true; j.src = '${ siteUrl }/livechat/${ latestVersion }/rocketchat-livechat.min.js?_=201903270000';
h.parentNode.insertBefore(j, h);
})(window, document, 'script', '${ siteUrl }/livechat?version=${ latestVersion }');
</script>
<!-- End of Rocket.Chat Livechat Script -->`;
},
});

@ -0,0 +1,29 @@
import { Autoupdate } from 'meteor/autoupdate';
export const addServerUrlToIndex = (file) => file.replace('<body>', `<body><script> SERVER_URL = '${ __meteor_runtime_config__.ROOT_URL }'; </script>`);
export const addServerUrlToHead = (head) => {
let baseUrl;
if (__meteor_runtime_config__.ROOT_URL_PATH_PREFIX && __meteor_runtime_config__.ROOT_URL_PATH_PREFIX.trim() !== '') {
baseUrl = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX;
} else {
baseUrl = '/';
}
if (/\/$/.test(baseUrl) === false) {
baseUrl += '/';
}
return `<html>
<head>
<link rel="stylesheet" type="text/css" class="__meteor-css__" href="${ baseUrl }livechat/livechat.css?_dc=${ Autoupdate.autoupdateVersion }">
<script type="text/javascript">
__meteor_runtime_config__ = ${ JSON.stringify(__meteor_runtime_config__) };
</script>
<base href="${ baseUrl }">
${ head }
</head>
<body>
<script type="text/javascript" src="${ baseUrl }livechat/livechat.js?_dc=${ Autoupdate.autoupdateVersion }"></script>
</body>
</html>`;
};

@ -1,15 +1,24 @@
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
import { settings } from '../../settings';
import { Autoupdate } from 'meteor/autoupdate';
import { settings } from '/app/settings';
import { addServerUrlToIndex, addServerUrlToHead } from '../lib/Assets';
import _ from 'underscore';
import url from 'url';
const latestVersion = '1.0.0';
const indexHtmlWithServerURL = addServerUrlToIndex(Assets.getText('livechat/index.html'));
const headHtmlWithServerURL = addServerUrlToHead(Assets.getText('livechat/head.html'));
const isLatestVersion = (version) => version && version === latestVersion;
WebApp.connectHandlers.use('/livechat', Meteor.bindEnvironment((req, res, next) => {
const reqUrl = url.parse(req.url);
if (reqUrl.pathname !== '/') {
return next();
}
const { version } = req.query;
const html = isLatestVersion(version) ? indexHtmlWithServerURL : headHtmlWithServerURL;
res.setHeader('content-type', 'text/html; charset=utf-8');
let domainWhiteList = settings.get('Livechat_AllowedDomainsList');
@ -27,34 +36,6 @@ WebApp.connectHandlers.use('/livechat', Meteor.bindEnvironment((req, res, next)
res.setHeader('X-FRAME-OPTIONS', `ALLOW-FROM ${ referer.protocol }//${ referer.host }`);
}
const head = Assets.getText('public/head.html');
let baseUrl;
if (__meteor_runtime_config__.ROOT_URL_PATH_PREFIX && __meteor_runtime_config__.ROOT_URL_PATH_PREFIX.trim() !== '') {
baseUrl = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX;
} else {
baseUrl = '/';
}
if (/\/$/.test(baseUrl) === false) {
baseUrl += '/';
}
const html = `<html>
<head>
<link rel="stylesheet" type="text/css" class="__meteor-css__" href="${ baseUrl }livechat/livechat.css?_dc=${ Autoupdate.autoupdateVersion }">
<script type="text/javascript">
__meteor_runtime_config__ = ${ JSON.stringify(__meteor_runtime_config__) };
</script>
<base href="${ baseUrl }">
${ head }
</head>
<body>
<script type="text/javascript" src="${ baseUrl }livechat/livechat.js?_dc=${ Autoupdate.autoupdateVersion }"></script>
</body>
</html>`;
res.write(html);
res.end();
}));

@ -2828,6 +2828,7 @@
"Today": "Today",
"To_additional_emails": "To additional emails",
"To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "To install Rocket.Chat Livechat in your website, copy &amp; paste this code above the last <strong>&lt;/body&gt;</strong> tag on your site.",
"To_install_the_new_version_of_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "To install the <strong> new version</strong> of Rocket.Chat Livechat in your website, copy &amp; paste this code above the last <strong>&lt;/body&gt;</strong> tag on your site.",
"to_see_more_details_on_how_to_integrate": "to see more details on how to integrate.",
"To_users": "To Users",
"Toggle_original_translated": "Toggle original/translated",

@ -2777,6 +2777,7 @@
"Today": "Hoje",
"To_additional_emails": "Para e-mails adicionais",
"To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "Para instalar Rocket.Chat Livechat no seu website, copie e cole este código acima da última tag <strong>&lt;/ body&gt;</strong> em seu site.",
"To_install_the_new_version_of_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "Para instalar a <strong>nova versão</strong> do Rocket.Chat Livechat no seu website, copie e cole este código acima da última tag <strong>&lt;/ body&gt;</strong> em seu site.",
"to_see_more_details_on_how_to_integrate": "para ver mais detalhes sobre como integrar.",
"To_users": "Para Usuários",
"Toggle_original_translated": "Alternar original / traduzido",
@ -3121,4 +3122,4 @@
"Your_push_was_sent_to_s_devices": "Sua notificação foi enviada para %s dispositivos",
"Your_server_link": "O link do seu servidor",
"Your_workspace_is_ready": "O seu espaço de trabalho está pronto a usar 🎉"
}
}

@ -39,5 +39,4 @@ Package.onUse(function(api) {
// DEPRECATED
api.addAssets('assets/rocket-livechat.js', 'client'); // this file is still added to not break currently installed livechat widgets
api.addAssets('assets/rocketchat-livechat.min.js', 'client');
api.addAssets('public/head.html', 'server');
});

@ -2,6 +2,8 @@ export NODE_ENV="production"
export LIVECHAT_DIR="../../../public/livechat"
export BUILD_DIR="../build"
export BUNDLE_DIR="../build/bundle/programs/web.browser.legacy"
export LIVECHAT_ASSETS_DIR="../../../private/livechat"
export LATEST_LIVECHAT_VERSION="1.0.0"
cd packages/rocketchat-livechat/.app
meteor npm install --production
@ -12,8 +14,25 @@ mkdir -p $LIVECHAT_DIR
cp $BUNDLE_DIR/*.css $LIVECHAT_DIR/livechat.css
cp $BUNDLE_DIR/*.js $LIVECHAT_DIR/livechat.js
rm -rf ../public
mkdir -p ../public
cp $BUNDLE_DIR/head.html ../public/head.html
rm -rf $LIVECHAT_ASSETS_DIR
mkdir $LIVECHAT_ASSETS_DIR
cp $BUNDLE_DIR/head.html $LIVECHAT_ASSETS_DIR/head.html
rm -rf $BUILD_DIR
#NEW LIVECHAT#
echo "Installing new Livechat..."
cd $LIVECHAT_DIR
mkdir -p $LATEST_LIVECHAT_VERSION
cd $LATEST_LIVECHAT_VERSION
curl -sOL "https://github.com/RocketChat/Rocket.Chat.Livechat/releases/download/v${LATEST_LIVECHAT_VERSION}/build.tar.gz"
tar -xf build.tar.gz
rm build.tar.gz
# change to lowercase so all injected junk from rocket.chat is not sent: https://github.com/meteorhacks/meteor-inject-initial/blob/master/lib/inject-core.js#L10
# this is not harmful since doctype is case-insesitive: https://www.w3.org/TR/html5/syntax.html#the-doctype
ex -s -c '%s/<!DOCTYPE/<!doctype/g|x' index.html
cd $LIVECHAT_ASSETS_DIR
cp ../../public/livechat/$LATEST_LIVECHAT_VERSION/index.html .

Loading…
Cancel
Save