UNPKG

@rocket.chat/apps-engine

Version:

The engine code for the Rocket.Chat Apps which manages, runs, translates, coordinates and all of that.

1 lines 2.26 kB
!function(){return function e(n,t,i){function o(r,l){if(!t[r]){if(!n[r]){var c="function"==typeof require&&require;if(!l&&c)return c(r,!0);if(s)return s(r,!0);var a=new Error("Cannot find module '"+r+"'");throw a.code="MODULE_NOT_FOUND",a}var u=t[r]={exports:{}};n[r][0].call(u.exports,function(e){return o(n[r][1][e]||e)},u,u.exports,e,n,t,i)}return t[r].exports}for(var s="function"==typeof require&&require,r=0;r<i.length;r++)o(i[r]);return o}}()({1:[function(e,n,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AppsEngineUIClient=void 0;const i=e("./constants"),o=e("./definition/AppsEngineUIMethods"),s=e("./utils");t.AppsEngineUIClient=class{constructor(){this.listener=(()=>console.log("init")),this.callbacks=new Map}getUserInfo(){return this.call(o.AppsEngineUIMethods.GET_USER_INFO)}getRoomInfo(){return this.call(o.AppsEngineUIMethods.GET_ROOM_INFO)}init(){this.listener=(({data:e})=>{if(!(null==e?void 0:e.hasOwnProperty(i.MESSAGE_ID)))return;const{[i.MESSAGE_ID]:{id:n,payload:t}}=e;if(this.callbacks.has(n)){const e=this.callbacks.get(n);"function"==typeof e&&e(t),this.callbacks.delete(n)}}),window.addEventListener("message",this.listener)}call(e,n){return new Promise(t=>{const o=(0,s.randomString)(i.ACTION_ID_LENGTH);window.parent.postMessage({[i.MESSAGE_ID]:{action:e,payload:n,id:o}},"*"),this.callbacks.set(o,t)})}}},{"./constants":3,"./definition/AppsEngineUIMethods":4,"./utils":5}],2:[function(e,n,t){window.AppsEngineUIClient=e("./AppsEngineUIClient").AppsEngineUIClient},{"./AppsEngineUIClient":1}],3:[function(e,n,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MESSAGE_ID=t.ACTION_ID_LENGTH=void 0,t.ACTION_ID_LENGTH=80,t.MESSAGE_ID="rc-apps-engine-ui"},{}],4:[function(e,n,t){"use strict";var i;Object.defineProperty(t,"__esModule",{value:!0}),t.AppsEngineUIMethods=void 0,function(e){e.GET_USER_INFO="getUserInfo",e.GET_ROOM_INFO="getRoomInfo"}(i||(t.AppsEngineUIMethods=i={}))},{}],5:[function(e,n,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.randomString=function(e){const n=[],t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(let o=0;o<e;o++)n.push(t[(i=t.length,Math.floor(Math.random()*Math.floor(i)))]);var i;return n.join("")}},{}]},{},[2]);