diff --git a/javascript/src/iframe/collaboraapi-iframe.js b/javascript/src/iframe/collaboraapi-iframe.js new file mode 100644 index 0000000000000000000000000000000000000000..6dde19dfdb308c4f1291e49b3bd0780d9d906127 --- /dev/null +++ b/javascript/src/iframe/collaboraapi-iframe.js @@ -0,0 +1,31 @@ +const axios = require('axios'); + +function CollaboraAPI() {} + +CollaboraAPI.prototype.discovery = function () { + const requestConfig = { + url: `${window.COLLABORA_URL}hosting/discovery`, + method: 'GET' + }; + + return axios(requestConfig).then(response => { + const apps = response.request.responseXML.querySelectorAll("net-zone[name='external-http'] app"); + + const results = []; + for (let i = 0; i < apps.length; i++) { + const app = apps[i]; + const action = app.querySelector('action'); + const mimeType = app.getAttribute('name'); + const ext = action.getAttribute('ext'); + const urlsrc = action.getAttribute('urlsrc'); + results.push({ + mimeType, + ext, + urlsrc + }); + } + return results + }); +}; + +module.exports = CollaboraAPI; diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 981fa97de178948ebd5174d6d4792b7de911955a..e89858ef7ff00eceabaaa383623e49d4c4a36d6e 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -10,6 +10,7 @@ const Penpal = require('penpal').default; const penpalMethods = require('../../temp/penpal-methods').default; const WopiAPI = require('./wopiapi-iframe'); +const CollaboraAPI = require('./collaboraapi-iframe'); const ViamAPI = require('../../temp/viamapi'); //********************************************************************************* @@ -1377,6 +1378,7 @@ function destroyIdentityFromLocalStorage(key) { window.loadedIdentities = {}; window.wopiAPI = new WopiAPI(); +window.collaboraApi = new CollaboraAPI(); window.viamApi = new ViamAPI(); window.viamAnonymousApi = new ViamAPI(); window.currentlyAuthenticatedIdentity = null; @@ -1589,9 +1591,25 @@ function getCertificateForPassport(passportUUID, internal) { const connection = Penpal.connectToParent({ // Methods child is exposing to parent methods: { - initialize: (apiUrl, wopiUrl) => { + 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 + "/"}getPassports`; + window.WOPI_URL = wopiUrl.charAt(wopiUrl.length - 1) === "/" ? wopiUrl : wopiUrl + "/"; + window.COLLABORA_URL = collaboraUrl.charAt(collaboraUrl.length - 1) === "/" ? collaboraUrl : collaboraUrl + "/"; }, createIdentity(pinCode) { return new Penpal.Promise(result => { @@ -2214,6 +2232,9 @@ const connection = Penpal.connectToParent({ result(res) }) }, + collaboraDiscovery() { + return collaboraApi.discovery().then(apps => apps); + }, ...penpalMethods } }); diff --git a/javascript/src/iframe/wopiapi-iframe.js b/javascript/src/iframe/wopiapi-iframe.js index 6fcbaac2c0120feab67a894a811f4ed4066706a6..8d5b72aaab4722fc51f4167f93859253fa2901d1 100644 --- a/javascript/src/iframe/wopiapi-iframe.js +++ b/javascript/src/iframe/wopiapi-iframe.js @@ -3,14 +3,15 @@ const axios = require('axios'); function WopiAPI() {} WopiAPI.prototype.getPassports = function (fileID) { + const { publicKey, uuid, token, deviceHash } = window.viamApi.getConfig().headers; const requestConfig = { - url: window.WOPI_URL, + url: `${window.WOPI_URL}getPassports`, method: 'POST', headers: { - publicKey: window.viamApi.getConfig().headers.publicKey, - uuid: window.viamApi.getConfig().headers.uuid, - token: window.viamApi.getConfig().headers.token, - deviceHash: window.viamApi.getConfig().headers.deviceHash, + publicKey, + uuid, + token, + deviceHash, fileID } }; diff --git a/javascript/src/viamapi-client.js b/javascript/src/viamapi-client.js index 7cea9b187c3b4c31fee36445255d35a66ea807bc..1fa645e73df4f0d1b9dd40e43050508df6b446a8 100644 --- a/javascript/src/viamapi-client.js +++ b/javascript/src/viamapi-client.js @@ -9,17 +9,7 @@ const Penpal = require('penpal').default; * @param wopiUrl - WOPI URL used to acces WopiAPI * @returns {*} */ -function setupViamAPI(divId, methods, iframeUrl, apiUrl, wopiUrl) { - 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 - } - +function setupViamAPI(divId, methods, iframeUrl, apiUrl, wopiUrl, collaboraUrl) { if (!iframeUrl) { iframeUrl = `${window.location.origin}/vcl/js/iframe`; console.warn(`Iframe URL not specified. Fall back to ${iframeUrl}`); // eslint-disable-line no-console @@ -35,7 +25,7 @@ function setupViamAPI(divId, methods, iframeUrl, apiUrl, wopiUrl) { }); return connection.promise - .then((child) => child.initialize(apiUrl, wopiUrl).then(() => child)); + .then((child) => child.initialize(apiUrl, wopiUrl, collaboraUrl).then(() => child)); } window.setupViamAPI = setupViamAPI;