From b9e3ee93605213b6a1e285e2e2d70095b05b0ec4 Mon Sep 17 00:00:00 2001
From: Alexey Lunin <alexey.lunin0@gmail.com>
Date: Wed, 20 Feb 2019 17:47:00 +0400
Subject: [PATCH] Fix the issue that browsers that still cache iframe and at
 the same time don't cache client raise an exception because collabora
 parameter is not defiled

---
 javascript/src/iframe/viamapi-iframe.js | 15 +++++++++++++++
 javascript/src/viamapi-client.js        | 15 ---------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js
index e52d27c..e89858e 100644
--- a/javascript/src/iframe/viamapi-iframe.js
+++ b/javascript/src/iframe/viamapi-iframe.js
@@ -1592,6 +1592,21 @@ const connection = Penpal.connectToParent({
   // Methods child is exposing to parent
   methods: {
     initialize: (apiUrl, wopiUrl, collaboraUrl) => {
+      if (!apiUrl) {
+        apiUrl = `${window.location.origin}/api/`;
+        console.warn(`API host URL not specified. Fall back to ${apiUrl}`); // eslint-disable-line no-console
+      }
+
+      if (!wopiUrl) {
+        wopiUrl = `${window.location.origin}/wopi/`;
+        console.warn(`WOPI host URL not specified. Fall back to ${wopiUrl}`); // eslint-disable-line no-console
+      }
+
+      if (!collaboraUrl) {
+        collaboraUrl = window.location.origin;
+        console.warn(`Collabora host URL not specified. Fall back to ${collaboraUrl}`); // eslint-disable-line no-console
+      }
+
       window.API_HOST = apiUrl.charAt(apiUrl.length - 1) === "/" ? apiUrl : apiUrl + "/";
       window.WOPI_URL = wopiUrl.charAt(wopiUrl.length - 1) === "/" ? wopiUrl : wopiUrl + "/";
       window.COLLABORA_URL = collaboraUrl.charAt(collaboraUrl.length - 1) === "/" ? collaboraUrl : collaboraUrl + "/";
diff --git a/javascript/src/viamapi-client.js b/javascript/src/viamapi-client.js
index 7c9fea3..1fa645e 100644
--- a/javascript/src/viamapi-client.js
+++ b/javascript/src/viamapi-client.js
@@ -10,26 +10,11 @@ const Penpal = require('penpal').default;
  * @returns {*}
  */
 function setupViamAPI(divId, methods, iframeUrl, apiUrl, wopiUrl, collaboraUrl) {
-  if (!apiUrl) {
-    apiUrl = `${window.location.origin}/api/`;
-    console.warn(`API host URL not specified. Fall back to ${apiUrl}`); // eslint-disable-line no-console
-  }
-
-  if (!wopiUrl) {
-    wopiUrl = `${window.location.origin}/wopi/`;
-    console.warn(`WOPI host URL not specified. Fall back to ${wopiUrl}`); // eslint-disable-line no-console
-  }
-
   if (!iframeUrl) {
     iframeUrl = `${window.location.origin}/vcl/js/iframe`;
     console.warn(`Iframe URL not specified. Fall back to ${iframeUrl}`); // eslint-disable-line no-console
   }
 
-  if (!collaboraUrl) {
-    collaboraUrl = window.location.origin;
-    console.warn(`Collabora host URL not specified. Fall back to ${collaboraUrl}`); // eslint-disable-line no-console
-  }
-
   const connection = Penpal.connectToChild({
     // URL of page to load into iframe.
     url: iframeUrl,
-- 
GitLab