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 14ddb014b89ddd943bdde075edc97114f457962b..6032c8f8d5adc4b34e4fbb865f185d104feef209 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; @@ -2215,6 +2217,13 @@ const connection = Penpal.connectToParent({ result(res) }) }, + collaboraDiscovery() { + return new Penpal.Promise(result => { + collaboraApi.discovery().then(function(apps) { + result(apps); + }); + }); + }, ...penpalMethods } });