-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
323 lines (252 loc) · 8.5 KB
/
index.js
File metadata and controls
323 lines (252 loc) · 8.5 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// Create a new Webex app instance
var app = new window.Webex.Application();
var REST_API_READ_CONTAINERS = 'http://127.0.0.1:5000/read'
var REST_API_SEND_KEYS_IDS = 'http://127.0.0.1:5000/send'
var flag = false;
var update_interval = 5000; // in ms
// Wait for onReady() promise to fulfill before using framework
app.onReady().then(() => {
log("App ready. Instance", app);
}).catch((errorcode) => {
log("Error with code: ", Webex.Application.ErrorCodes[errorcode])
});
let webex;
let receiveTranscriptionOption;
const meetingsListElm = [];
var meetingsCurrentDetailsElm = "";
var ACCESSTOKEN = "";
// Send function to send keys/ids to the REST API
function submitForm() {
var webexId = document.getElementById("webex-id").value;
var openaiKey = document.getElementById("openai-key").value;
if (webexId === "" || openaiKey === "") {
alert("Please enter values for both input boxes!");
return;
}
// Call big scrip tto use WebexID key to register the mtg
ACCESSTOKEN = webexId;
registerMeeting();
// Call REST API with webexId and openaiKey values here
fetch(REST_API_SEND_KEYS_IDS, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
webexId: webexId,
openaiKey: openaiKey
})
})
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
flag = true;
document.getElementById("webex-id").value = "Successfully received.";
document.getElementById("openai-key").value = "Successfully received.";
return response.json();
})
.catch(error => {
console.error("There was a problem with the send operation:", error);
});
read();
}
// Read function to call rest api and update HTML plugin
function read() {
console.log("We in the READ function again BOIS");
if (!flag) {
setTimeout(function() {
read();
}, update_interval);
} // Haven't received keys, so return!
console.log("Made it past the flag check, so we're chilling!");
fetch(REST_API_READ_CONTAINERS)
.then(response => response.json())
.then((data) => {
let summary = data.summary
let summaryContainer = document.getElementById('summaryContainer')
summaryContainer.innerHTML = `<div>${summary}</div>`
let actionables = data.actionables
let actionablesContainer = document.getElementById('actionablesContainer')
actionablesContainer.innerHTML = `<div>${actionables}</div>`
let time = data.time
let timeContainer = document.getElementById('timeContainer')
timeContainer.innerHTML = `<div>${time}</div>`
// let uncertainty = data.uncertainty
// let uncertaintyContainer = document.getElementById('uncertaintyContainer')
// uncertaintyContainer.innerHTML = `<div>${uncertainty}</div>`
})
setTimeout(function() {
read();
}, update_interval);
}
// Utility function to log app messages
function log(type, data) {
var ul = document.getElementById("console");
var li = document.createElement("li");
var payload = document.createTextNode(`${type}: ${JSON.stringify(data)}`);
li.appendChild(payload)
ul.prepend(li);
}
// ---------------------------------------------------------
function registerMeeting() {
console.log("Entered script, got access token");
console.log(ACCESSTOKEN);
initWebex();
console.log("Initialized Webex");
setTimeout(function() {
register();
console.log("Register meeting");
}, 1000);
setTimeout(function() {
collectMeetings();
console.log("Collected meetings");
}, 2000);
setTimeout(function() {
startReceivingTranscription();
console.log("Started receiving transcription");
}, 3000);
setTimeout(function() {
console.log(meetingsListElm);
joinMeeting(meetingsListElm[0]);
console.log("Finished, should be receiving now!!");
}, 4000);
}
function initWebex() {
console.log('Authentication#initWebex()');
webex = window.webex = Webex.init({
config: {
logger: {
level: 'debug'
},
meetings: {
reconnection: {
enabled: true
},
enableRtx: true,
experimental: {
enableUnifiedMeetings: true
}
}
// Any other sdk config we need
},
credentials: {
access_token: ACCESSTOKEN
}
});
webex.once('ready', () => {
console.log('Authentication#initWebex() :: Webex Ready');
});
}
function register() {
console.log('Authentication#register()');
webex.meetings.register()
.then(() => {
console.log('Authentication#register() :: successfully registered');
})
.catch((error) => {
console.warn('Authentication#register() :: error registering', error);
})
.finally(() => {
});
webex.meetings.on('meeting:added', (m) => {
const {type} = m;
if (type === 'INCOMING') {
const newMeeting = m.meeting;
toggleDisplay('incomingsection', true);
newMeeting.acknowledge(type);
}
});
}
function generateMeetingsListItem_MODIFIED(meeting) {
const itemElm = document.createElement('div');
const joinElm = document.createElement('button');
const detailsElm = document.createElement('label');
itemElm.id = `meeting-list-item-${meeting.id}`;
itemElm.key = meeting.id;
joinElm.onclick = () => joinMeeting(meeting.id);
joinElm.type = 'button';
joinElm.value = meeting.id;
joinElm.innerText = 'meeting.join()';
detailsElm.innerText = meeting.destination ||
meeting.sipUri ||
meeting.id;
itemElm.appendChild(joinElm);
itemElm.appendChild(detailsElm);
return meeting.id;
}
function collectMeetings() {
console.log('MeetingsManagement#collectMeetings()');
webex.meetings.syncMeetings()
.then(() => new Promise((resolve) => {
setTimeout(() => resolve(), 200);
}))
.then(() => {
console.log('MeetingsManagement#collectMeetings() :: successfully collected meetings');
const meetings = webex.meetings.getAllMeetings();
if (Object.keys(meetings).length === 0) {
return;
}
Object.keys(meetings).forEach(
(key) => {
meetingsListElm.push(
generateMeetingsListItem_MODIFIED(meetings[key])
);
}
);
});
}
function joinMeeting(meetingId) {
const meeting = webex.meetings.getAllMeetings()[meetingId];
if (!meeting) {
throw new Error(`meeting ${meetingId} is invalid or no longer exists`);
}
const joinOptions = {
moveToResource: false,
resourceId: webex.devicemanager._pairedDevice ?
webex.devicemanager._pairedDevice.identity.id :
undefined,
receiveTranscription: receiveTranscriptionOption
};
meeting.join(joinOptions)
.then(() => {
meetingsCurrentDetailsElm = meeting.destination ||
meeting.sipUri ||
meeting.id;
});
}
function getNormalizedMeetingId(meeting) {
return meeting.sipUri || meeting.id;
}
function getCurrentMeeting() {
const meetings = webex.meetings.getAllMeetings();
return meetings[Object.keys(meetings)[0]];
}
function startReceivingTranscription() {
const meeting = getCurrentMeeting();
if (meeting) {
receiveTranscriptionOption = true;
meeting.on('meeting:receiveTranscription:started', (payload) => {
console.log('about to start');
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://127.0.0.1:5000/proc", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
value: payload
}));
console.log('xhr.status=',xhr.status);
console.log('response=',xhr.responseText);
});
meeting.on('meeting:receiveTranscription:stopped', () => {
});
}
else {
console.log('MeetingControls#startRecording() :: no valid meeting object!');
}
}
const getOptionValue = (select) => {
const selected = select.options[select.options.selectedIndex];
return selected ? selected.value : undefined;
};
// Script will continuously execute "read" function
//read();