forked from webex/EmbeddedAppKitchenSink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebexEmbeddedAppEmulatorFramework.js
149 lines (131 loc) · 4.2 KB
/
WebexEmbeddedAppEmulatorFramework.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var eventListeners = {};
var getDataResolve;
var getDataTimeoutID;
function messageEventListener(event) {
// Only handle events from the parent
if (event.source !== window.parent) return; // Handle data being sent from mock
if (event.data.type === 'DATA') {
// do something with event.data.data
clearTimeout(getDataTimeoutID);
getDataResolve(event.data.data);
} // Handle simulated events
if (event.data.type === 'EVENT') {
if (eventListeners[event.data.event.eventName] && eventListeners[event.data.event.eventName] instanceof Function) {
eventListeners[event.data.event.eventName](event.data.event.eventPayload);
}
}
}
window.addEventListener('message', messageEventListener);
function getMockDataFromEmulator() {
// Tell the emulator to send us the latest data
window.parent.postMessage({
action: 'SEND_DATA'
}, "*");
return new Promise(function (resolve, reject) {
getDataTimeoutID = setTimeout(function () {
reject(new Error('Timed out waiting for data from "server"'));
}, 5000);
getDataResolve = resolve;
});
}
var Context = /*#__PURE__*/function () {
function Context() {
_classCallCheck(this, Context);
}
_createClass(Context, [{
key: "getUser",
value:
/**
* Gets the current Webex user
* @returns {Promise.<WebexUser>}
*/
function getUser() {
return getMockDataFromEmulator().then(function (data) {
return data.user;
});
}
}, {
key: "getMeeting",
value: function getMeeting() {
return getMockDataFromEmulator().then(function (data) {
return data.meeting;
});
}
}, {
key: "getSpace",
value: function getSpace() {
return getMockDataFromEmulator().then(function (data) {
return data.space;
});
}
}]);
return Context;
}();
var Application = /*#__PURE__*/function () {
function Application() {
_classCallCheck(this, Application);
this.ErrorCodes = {
"SUCCESS": 0,
"GENERIC_ERROR": 1,
"INVALID_ARGUMENT": 2,
"EVENT_ALREADY_REGISTERED": 3,
"EVENT_UNKNOWN": 4,
"BAD_CONTEXT": 5,
"NOT_SUPPORTED": 6
};
this.ApplicationTheme = {
"DARK": 0,
"LIGHT": 1
};
this.sdkVersion = '1';
this.about = 'Webex App, Version: 41.8.0.19299';
this.deviceType = 'DESKTOP';
this.isPrivateDataAvailable = false;
this.displayContext = 'MEETING_SIDEBAR';
this.language = 'en-US';
this.isShared = false;
this.capabilities = [];
this.context = new Context();
this.theme = this.ApplicationTheme.DARK;
}
_createClass(Application, [{
key: "onReady",
value: function onReady() {
return Promise.resolve();
}
}, {
key: "setShareUrl",
value: function setShareUrl(internalUrl, externalUrl, title, optional) {
// Post a message to the emulator to load the participant url
window.parent.postMessage({
action: 'SESSION_URL',
internalUrl: internalUrl,
externalUrl: externalUrl,
title: title,
optional: optional
}, "*");
}
}, {
key: "clearShareUrl",
value: function clearShareUrl() {
window.parent.postMessage({
action: 'CLEAR_SESSION_URL'
}, "*");
}
}, {
key: "listen",
value: function listen(eventName, callback) {
// Add listener to collection
eventListeners[eventName] = callback;
}
}]);
return Application;
}();
var WebexEmbeddedAppEmulatorFramework = {
Application: Application
};
window.Webex = WebexEmbeddedAppEmulatorFramework;