-
Notifications
You must be signed in to change notification settings - Fork 0
/
share-wb-participants-companion.js
440 lines (390 loc) · 15.8 KB
/
share-wb-participants-companion.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
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/********************************************************
*
* Macro Author: Victor Vazquez
* Technical Solutions Architect
* vvazquez@cisco.com
* Cisco Systems
*
* Version: 1-0-0
* Released: 20/06/24
*
* This Webex Device macro allows users to share whiteboards
* via email simply by clicking on a button on the Navigator.
*
* This specific version of this macro has been designed for
* Companion mode use case. This macro should be installed and
* enabled on the main Room Device. The macro then lets a user
* share a Whiteboard which may be open on the Companion Board
* from the main Room Devices Navigator.
*
* The macro includes a new option allowing the user to send the
* Whiteboard to selected meeting participants
*
* Full Readme and source code and license details available here:
* https://github.com/wxsd-sales/share-whiteboard-macro
*
********************************************************/
import xapi from 'xapi';
/*********************************************************
* Configure the settings below
**********************************************************/
let emailConfig = {
destination: 'user@example.com', // Change this value to the email address you want the whiteboard to be sent to by default
body: 'Here you have your white board', // Email body text of your choice, this is an example
subject: 'New white board', // Email subject of your choice, this is an example
attachmentFilename: 'myfile-companion-mode.pdf' // File name of your choice, this is an example
};
const config = {
button: {
name: 'Share Whiteboard',
icon: 'Tv'
},
panelId: 'sharewb'
}
const remoteDeviceconfig = {
deviceIP: 'X.X.X.X', // Change this value to the Cisco Board IP adddress
userName: 'user', // Change this value to the Board user with Admin rights
password: 'password', // Board user witrh Admin rights password
};
const credentials = btoa(`${remoteDeviceconfig.userName}:${remoteDeviceconfig.password}`);
/*********************************************************
* Main functions and event subscriptions
**********************************************************/
createPanel();
// listening for first button click
xapi.Event.UserInterface.Extensions.Panel.Clicked.on(async event => {
if (event.PanelId != config.panelId) return
createPanel(); // Reset the previous inputs when the panel is opened
});
// listening for Text input for 'Send to Custom Email Address Option'
xapi.Event.UserInterface.Message.TextInput.Response.on(processInput)
// listening for clicks on main the page
xapi.Event.UserInterface.Extensions.Widget.Action.on(async event => {
if (!event.WidgetId.startsWith(config.panelId)) return
if (event.Type != 'pressed') return
const [_panelId, command] = event.WidgetId.split('-')
console.log('widget pressed:', command);
switch (command) {
case 'sendToDefaultEmail':
sendWhiteBoardUrl(emailConfig.destination);
break;
case 'sendToCustomEmail':
console.log('Getting the email address');
await xapi.Command.UserInterface.Message.TextInput.Display(
{
Duration: 300,
FeedbackId: 'text-input-box',
InputText: emailConfig.destination,
InputType: 'SingleLine',
KeyboardState: 'Open',
SubmitText: 'Send',
Text: 'Type the email address you want to share the whiteboard with',
Title: 'Sending Whiteboard'
})
/* wait for Customer answer in another function */
.catch(error => console.log('Error getting email address', error));
break;
case 'selectParticpants':
// Create the Participant Panel
const participants = await getParticipants();
createPanel(participants);
break;
case 'participant':
const uuid = event.WidgetId.replace(config.panelId + '-participant-', '')
toggleParticipantButton(uuid)
break;
case 'shareToParticipantsButton':
const selected = await getSelectedParticipants();
console.log('number of selected:', selected.length)
if (selected.length == 0) {
alert({ title: 'Warning', message: 'You need to select at least one participant' });
return
}
const data = await getParticipants();
const selectedPartipants = data.filter(participant => selected.includes(participant.SparkUserId))
console.log('selected participants', selectedPartipants)
const emails = await getParticipantsEmail(selectedPartipants)
console.log('Sharing Whiteboard to the following emails', emails)
// pending build emails
sendWhiteBoardUrl(emails)
break;
}
});
function processInput(event) {
if (event.FeedbackId !== 'text-input-box') return;
console.log('email address from customer input:', event.Text);
sendWhiteBoardUrl(event.Text); // Instruct Board to send URL
}
/*****************************************************************
* Returns Meeting participants inside the Org
*****************************************************************/
async function getParticipants() {
const results = await xapi.Command.Conference.ParticipantList.Search()
const self = results.Participant.find(participant => participant.ParticipantId == results.ParticipantSelf)
const peopleInMyOrg = results.Participant.filter(participant => participant.Type == 'User' && participant.OrgId == self.OrgId)
console.log('Number of people in my org found:', peopleInMyOrg.length);
console.log('People in my org found', peopleInMyOrg);
return peopleInMyOrg;
}
/*****************************************************************
* Returns selected participants
*****************************************************************/
async function getSelectedParticipants() {
const widgetIdStart = config.panelId + '-participant-';
const widgets = await xapi.Status.UserInterface.Extensions.Widget.get();
console.log(widgets)
const filtered = widgets.filter(widget => widget.WidgetId.startsWith(widgetIdStart) && widget.Value == 'active')
if (!filtered) return
return filtered.map(widget => widget.WidgetId.replace(widgetIdStart, ''))
}
/*****************************************************************
* Functions to get selected participants emails
*****************************************************************/
async function getParticipantsEmail(participants) {
let emails = [];
for (let i = 0; i < participants.length; i++) {
console.log('Searching for name:', participants[i].DisplayName, ' uuid:', participants[i].SparkUserId)
const result = await getParticipantEmail(participants[i].DisplayName, participants[i].SparkUserId)
emails.push(result)
}
console.log ('Number of emails:', emails.length)
if (emails.length > 20) {
console.log ('More than 20 emails');
return
}
return emails
}
async function getParticipantEmail(name, uuid) {
const result = await xapi.Command.Phonebook.Search({ PhonebookType: 'Corporate', SearchString: name });
const contacts = result?.Contact;
// console.log ('contacts', contacts);
if (!contacts) return
const person = contacts.find(contact => contact.ContactId == uuid)
console.log('person', person);
return person?.Email
}
/*****************************************************************
* Functions to handle participants selection
*****************************************************************/
async function toggleParticipantButton(uuid) {
const panelId = config.panelId;
const widgetId = panelId + '-participant-' + uuid;
const widgetState = await getWidgetState(widgetId)
if (widgetState != 'active') {
xapi.Command.UserInterface.Extensions.Widget.SetValue({ Value: 'active', WidgetId: widgetId });
} else {
xapi.Command.UserInterface.Extensions.Widget.UnsetValue({ WidgetId: widgetId });
}
}
async function getWidgetState(widgetId) {
const widgets = await xapi.Status.UserInterface.Extensions.Widget.get();
const widget = widgets.find(widget => widget.WidgetId == widgetId)
return widget.Value
}
/*****************************************************************
* Connects to the remote device to read the board URl
*****************************************************************/
async function getBoardUrl() {
let boardUrl = '';
alert({ message: 'Checking for visible whiteboards on Companion Board', duration: 5 });
// Get Board URL from the WB
await xapi.Command.HttpClient.Get({
AllowInsecureHTTPS: 'True',
Header: ['Authorization: Basic ' + credentials],
Url: `https://${remoteDeviceconfig.deviceIP}/getxml?location=/Status/Conference/Presentation/WhiteBoard`
})
.then(response => {
boardUrl = response.Body.split("<BoardUrl>")[1].split("</BoardUrl>")[0];
console.log('Board Url read in WB', boardUrl);
return (boardUrl);
})
.catch(error => {
console.log('Error getting Board URL;', error);
})
}
/*********************************************************
* Instructs the Companion Device to send the Whiteboard
* to configured email destination
**********************************************************/
async function sendWhiteBoardUrl(destination) {
let boardUrl = '';
alert({ message: 'Checking for visible whiteboards on Companion Board', duration: 5 });
// Get Board URL from the WB
await xapi.Command.HttpClient.Get({
AllowInsecureHTTPS: 'True',
Header: ['Authorization: Basic ' + credentials],
Url: `https://${remoteDeviceconfig.deviceIP}/getxml?location=/Status/Conference/Presentation/WhiteBoard`
})
.then(response => {
boardUrl = response.Body.split("<BoardUrl>")[1].split("</BoardUrl>")[0];
console.log('Board Url read in WB', boardUrl);
if (!boardUrl) {
alert({ title: 'Warning', message: 'You need to share a whiteboard before it can be sent' });
return
}
const xml = ` <Command>
<Whiteboard>
<Email>
<Send>
<Subject>${emailConfig.subject}</Subject>
<Body>${emailConfig.body}</Body>
<Recipients>${destination}</Recipients>
<BoardUrls>${boardUrl}</BoardUrls>
<AttachmentFilenames>${emailConfig.attachmentFilename}.pdf</AttachmentFilenames>
</Send>
</Email>
</Whiteboard>
</Command>`;
xapi.Command.HttpClient.Post({
AllowInsecureHTTPS: 'True',
Header: ['Authorization: Basic ' + credentials],
Url: `https://${remoteDeviceconfig.deviceIP}/putxml`
}, xml)
.catch(error => console.log('Error sending whiteboard', error))
.then(reponse => {
console.log('putxml response status code:', reponse.StatusCode);
alert({ message: `Whiteboard has been sent to ${destination}` });
})
})
.catch(error => {
console.log('Error getting Board URL;', error);
})
}
/*********************************************************
* Create the Share Whiteboard button
**********************************************************/
async function createPanel(people) {
console.log('Creating Panel')
const button = config.button;
const panelId = config.panelId;
const mainPage = (people) ? createParticipantsPage(people) : createMainPage();
const order = await panelOrder(panelId);
const panel = `
<Extensions>
<Panel>
<Location>CallControls</Location>
<Icon>${button.icon}</Icon>
<Color>${button.color}</Color>
<Name>${button.name}</Name>
${order}
<ActivityType>Custom</ActivityType>
${mainPage}
</Panel>
</Extensions> `;
await xapi.Command.UserInterface.Extensions.Panel.Save({ PanelId: panelId }, panel)
.catch(error => console.log(`Unable to save panel [${panelId}]- `, error.message))
}
/*********************************************************
* Create the main page
**********************************************************/
function createMainPage() {
const panelId = config.panelId;
return `
<Page>
<Name>Share Whiteboard</Name>
<Row>
<Name>Send to: Default@example.com</Name>
<Widget>
<WidgetId>${panelId}-sendToDefaultEmail</WidgetId>
<Name>Send to Default Email: ${emailConfig.destination}</Name>
<Type>Button</Type>
<Options>size=4</Options>
</Widget>
</Row>
<Row>
<Name>Send To: Meeting Participants</Name>
<Widget>
<WidgetId>${panelId}-sendToCustomEmail</WidgetId>
<Name>Send to Custom Email Address</Name>
<Type>Button</Type>
<Options>size=4</Options>
</Widget>
</Row>
<Row>
<Name>Row</Name>
<Widget>
<WidgetId>${panelId}-selectParticpants</WidgetId>
<Name>Send to Selected Participants</Name>
<Type>Button</Type>
<Options>size=4</Options>
</Widget>
</Row>
<Options>hideRowNames=1</Options>
</Page>`
}
/*********************************************************
* Create the list of participants Panel
**********************************************************/
function createParticipantsPage(people) {
const rows = people.map(person => {
return `<Row><Widget>
<WidgetId>${config.panelId}-participant-${person.SparkUserId}</WidgetId>
<Name>${replaceSpecialCharacters(person.DisplayName)}</Name>
<Type>Button</Type>
<Options>size=3</Options>
</Widget></Row>`
}).join('')
const sendRow =
`<Row>
<Widget>
<WidgetId>${config.panelId}-shareToParticipantsText</WidgetId>
<Name>Click to send to the selected participants:</Name>
<Type>Text</Type>
<Options>size=3;fontSize=small;align=center</Options>
</Widget>
<Widget>
<WidgetId>${config.panelId}-shareToParticipantsButton</WidgetId>
<Name>Send</Name>
<Type>Button</Type>
<Options>size=1</Options>
</Widget>
</Row>`
return `<Page><Name>Select Participant</Name>${rows}${sendRow}<Options>hideRowNames=1</Options></Page>`
}
/*********************************************************
* Gets the current Panel Order if exiting Macro panel is present
* to preserve the order in relation to other custom UI Extensions
**********************************************************/
async function panelOrder(panelId) {
const list = await xapi.Command.UserInterface.Extensions.List({ ActivityType: "Custom" });
const panels = list?.Extensions?.Panel
if (!panels) return ''
const existingPanel = panels.find(panel => panel.PanelId == panelId)
if (!existingPanel) return ''
return `<Order>${existingPanel.Order}</Order>`
}
function replaceSpecialCharacters(text) {
return text
.replaceAll(/&/g, "&")
.replaceAll(/</g, "<")
.replaceAll(/>/g, ">")
}
/**
* Alert Function for Logging & Displaying Notification on Device
* @property {object} args - Alert details
* @property {string} args.message - Message Text
* @property {string} args.title - Alert Title
* @property {number} args.duration - Alert Duration
*/
function alert(args) {
if (!args.hasOwnProperty('message')) {
console.error('message is required to display alert')
return
}
let duration = 5;
if (args.hasOwnProperty('duration')) {
duration = args.duration;
}
console.log('Displaying Alert:', args)
if (args.hasOwnProperty('title')) {
switch (args.title.toLowerCase()) {
case 'warning':
xapi.Command.UserInterface.Message.Alert.Display({ Duration: 10, Text: args.message, Title: args.title });
break;
default:
xapi.Command.UserInterface.Message.Prompt.Display({ Duration: duration, Text: args.message, Title: args.title });
}
} else {
xapi.Command.UserInterface.Message.Prompt.Display({ Duration: duration, Text: args.message, Title: 'Sharing Whiteboard Macro' })
}
}