@webex/plugin-device-manager 3.0.0-beta.3 → 3.0.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/sample/app.js CHANGED
@@ -14,7 +14,7 @@ let webex;
14
14
  // retype things everytime we reload the page.
15
15
 
16
16
  [
17
- 'access-token'
17
+ 'access-token',
18
18
  // 'invitee'
19
19
  ].forEach((id) => {
20
20
  const el = document.getElementById(id);
@@ -25,6 +25,93 @@ let webex;
25
25
  });
26
26
  });
27
27
 
28
+ function notify(message) {
29
+ document.getElementById('notifications').innerHTML = message;
30
+ setTimeout(() => {
31
+ document.getElementById('notifications').innerHTML = '';
32
+ }, 5000);
33
+ }
34
+
35
+ function populateDeviceDropdown(devices) {
36
+ const deviceListDropdown = document.getElementById('device-list-dropdown');
37
+
38
+ deviceListDropdown.length = 0;
39
+
40
+ const defaultOption = document.createElement('option');
41
+
42
+ defaultOption.text = 'Choose a Device';
43
+ deviceListDropdown.add(defaultOption);
44
+ deviceListDropdown.selectedIndex = 0;
45
+
46
+ let option;
47
+
48
+ devices.forEach((device) => {
49
+ option = document.createElement('option');
50
+ option.text = device.deviceInfo.description || device.deviceInfo.name;
51
+ option.value = device.id;
52
+ deviceListDropdown.add(option);
53
+ });
54
+ }
55
+
56
+ function toggleDisplay(elementId, status) {
57
+ const element = document.getElementById(elementId);
58
+
59
+ if (status) {
60
+ element.style.display = 'block';
61
+ } else {
62
+ element.style.display = 'none';
63
+ }
64
+ }
65
+
66
+ function populateDeviceAudioState(audioState) {
67
+ document.getElementById('getAudioStateContentsDiv').innerHTML = `<div>
68
+ <ul>
69
+ <li>Muted: ${audioState.microphones.muted}</li>
70
+ <li>volume current level: ${audioState.volume.level}</li>
71
+ <li>volume max level: ${audioState.volume.max}</li>
72
+ <li>volume min level: ${audioState.volume.min}</li>
73
+ <li>volume step level: ${audioState.volume.step}</li>
74
+ </ul>
75
+ <div id='hideAudioStateBtnDiv' style=muted"display:none;">
76
+ <button id="hideAudioState" title="hideAudioState" type="button">hideAudioState</button>
77
+ </div>
78
+ </div>`;
79
+ toggleDisplay('getAudioStateContentsDiv', true);
80
+ toggleDisplay('hideAudioStateBtnDiv', true);
81
+ // hideAudioState of the paired device
82
+ document.getElementById('hideAudioState').addEventListener('click', () => {
83
+ toggleDisplay('getAudioStateContentsDiv', false);
84
+ toggleDisplay('hideAudioStateBtnDiv', false);
85
+ });
86
+ }
87
+
88
+ function populateDeviceSearchResults(response) {
89
+ let devices = '';
90
+
91
+ response.forEach((device) => {
92
+ devices += `
93
+ <li style='list-style-type: none'>
94
+ <input type='radio' name='deviceRadio' onclick='requestPinChallenge("${device.id}")'/>
95
+ <label>${device.description || device.name}</label>
96
+ </li>`;
97
+ });
98
+ document.getElementById('getDeviceSearchResultsDiv').innerHTML = `<div>
99
+ <ul>
100
+ ${devices}
101
+ </ul>
102
+ <div id='hideDeviceSearchResultsBtnDiv' style=muted"display:none;">
103
+ <button id="hideDeviceSearchResults" title="hideDeviceSearchResults" type="button">hideDeviceSearchResults</button>
104
+ </div>
105
+ </div>`;
106
+ toggleDisplay('getDeviceSearchResultsDiv', true);
107
+ toggleDisplay('hideDeviceSearchResults', true);
108
+ // hideAudioState of the paired device
109
+ document.getElementById('hideDeviceSearchResults').addEventListener('click', () => {
110
+ toggleDisplay('getDeviceSearchResultsDiv', false);
111
+ toggleDisplay('hideDeviceSearchResults', false);
112
+ });
113
+ }
114
+
28
115
  function connect() {
29
116
  if (!webex) {
30
117
  webex = Webex.init({
@@ -32,8 +119,8 @@ function connect() {
32
119
  // Any other sdk config we need
33
120
  },
34
121
  credentials: {
35
- access_token: document.getElementById('access-token').value
36
- }
122
+ access_token: document.getElementById('access-token').value,
123
+ },
37
124
  });
38
125
  }
39
126
 
@@ -61,26 +148,23 @@ function connect() {
61
148
  }
62
149
 
63
150
  function requestPinChallenge(deviceId) {
64
- return webex.devicemanager.requestPin({id: deviceId})
65
- .then(() => {
66
- toggleDisplay('enterPinDiv', true);
67
- toggleDisplay('requestPairingBtnDiv', true);
68
- notify('Enter the PIN');
69
- });
151
+ return webex.devicemanager.requestPin({id: deviceId}).then(() => {
152
+ toggleDisplay('enterPinDiv', true);
153
+ toggleDisplay('requestPairingBtnDiv', true);
154
+ notify('Enter the PIN');
155
+ });
70
156
  }
71
157
 
72
-
73
158
  document.getElementById('deviceControls').refresh.addEventListener('click', () => {
74
159
  if (webex.devicemanager) {
75
160
  notify('Listing devices...');
76
161
 
77
- return webex.devicemanager.refresh()
78
- .then((devices) => {
79
- populateDeviceDropdown(devices);
80
- notify('');
81
- toggleDisplay('requestPinDiv', true);
82
- toggleDisplay('removeBtnDiv', true);
83
- });
162
+ return webex.devicemanager.refresh().then((devices) => {
163
+ populateDeviceDropdown(devices);
164
+ notify('');
165
+ toggleDisplay('requestPinDiv', true);
166
+ toggleDisplay('removeBtnDiv', true);
167
+ });
84
168
  }
85
169
 
86
170
  return false;
@@ -108,7 +192,8 @@ document.getElementById('requestPairing').addEventListener('click', () => {
108
192
  notify('Pairing...');
109
193
  const pin = document.getElementById('pin').value;
110
194
 
111
- return webex.devicemanager.pair({pin})
195
+ return webex.devicemanager
196
+ .pair({pin})
112
197
  .then(() => {
113
198
  notify('Paired');
114
199
  toggleDisplay('requestUnPairingBtnDiv', true);
@@ -139,23 +224,22 @@ document.getElementById('requestUnPairing').addEventListener('click', () => {
139
224
  if (webex.devicemanager) {
140
225
  notify('UnPairing...');
141
226
 
142
- return webex.devicemanager.unpair()
143
- .then(() => {
144
- notify('UnPaired');
145
- toggleDisplay('requestUnPairingBtnDiv', false);
146
- toggleDisplay('requestPairingBtnDiv', false);
147
- toggleDisplay('enterPinDiv', false);
148
- toggleDisplay('getAudioStateBtnDiv', false);
149
- toggleDisplay('hideAudioStateBtnDiv', false);
150
- toggleDisplay('getAudioStateContentsDiv', false);
151
- toggleDisplay('volumeUpBtnDiv', false);
152
- toggleDisplay('volumeDownBtnDiv', false);
153
- toggleDisplay('muteBtnDiv', false);
154
- toggleDisplay('unmuteBtnDiv', false);
155
- toggleDisplay('enterConvoIdDiv', false);
156
- toggleDisplay('bindSpaceBtnDiv', false);
157
- toggleDisplay('unbindSpaceBtnDiv', false);
158
- });
227
+ return webex.devicemanager.unpair().then(() => {
228
+ notify('UnPaired');
229
+ toggleDisplay('requestUnPairingBtnDiv', false);
230
+ toggleDisplay('requestPairingBtnDiv', false);
231
+ toggleDisplay('enterPinDiv', false);
232
+ toggleDisplay('getAudioStateBtnDiv', false);
233
+ toggleDisplay('hideAudioStateBtnDiv', false);
234
+ toggleDisplay('getAudioStateContentsDiv', false);
235
+ toggleDisplay('volumeUpBtnDiv', false);
236
+ toggleDisplay('volumeDownBtnDiv', false);
237
+ toggleDisplay('muteBtnDiv', false);
238
+ toggleDisplay('unmuteBtnDiv', false);
239
+ toggleDisplay('enterConvoIdDiv', false);
240
+ toggleDisplay('bindSpaceBtnDiv', false);
241
+ toggleDisplay('unbindSpaceBtnDiv', false);
242
+ });
159
243
  }
160
244
 
161
245
  return false;
@@ -166,11 +250,10 @@ document.getElementById('getAudioState').addEventListener('click', () => {
166
250
  if (webex.devicemanager) {
167
251
  notify('GettingAudioState...');
168
252
 
169
- return webex.devicemanager.getAudioState()
170
- .then((res) => {
171
- populateDeviceAudioState(res);
172
- notify('Audio State fetched');
173
- });
253
+ return webex.devicemanager.getAudioState().then((res) => {
254
+ populateDeviceAudioState(res);
255
+ notify('Audio State fetched');
256
+ });
174
257
  }
175
258
 
176
259
  return false;
@@ -181,7 +264,8 @@ document.getElementById('volumeUp').addEventListener('click', () => {
181
264
  if (webex.devicemanager) {
182
265
  notify('Increasing Volume...');
183
266
 
184
- return webex.devicemanager.increaseVolume()
267
+ return webex.devicemanager
268
+ .increaseVolume()
185
269
  .then(() => webex.devicemanager.getAudioState())
186
270
  .then((res) => {
187
271
  populateDeviceAudioState(res);
@@ -197,7 +281,8 @@ document.getElementById('volumeDown').addEventListener('click', () => {
197
281
  if (webex.devicemanager) {
198
282
  notify('Decreasing Volume...');
199
283
 
200
- return webex.devicemanager.decreaseVolume()
284
+ return webex.devicemanager
285
+ .decreaseVolume()
201
286
  .then(() => webex.devicemanager.getAudioState())
202
287
  .then((res) => {
203
288
  populateDeviceAudioState(res);
@@ -213,7 +298,8 @@ document.getElementById('mute').addEventListener('click', () => {
213
298
  if (webex.devicemanager) {
214
299
  notify('Muting...');
215
300
 
216
- return webex.devicemanager.mute()
301
+ return webex.devicemanager
302
+ .mute()
217
303
  .then(() => webex.devicemanager.getAudioState())
218
304
  .then((res) => {
219
305
  populateDeviceAudioState(res);
@@ -231,7 +317,8 @@ document.getElementById('unmute').addEventListener('click', () => {
231
317
  if (webex.devicemanager) {
232
318
  notify('UnMuting');
233
319
 
234
- return webex.devicemanager.unmute()
320
+ return webex.devicemanager
321
+ .unmute()
235
322
  .then(() => webex.devicemanager.getAudioState())
236
323
  .then((res) => {
237
324
  populateDeviceAudioState(res);
@@ -249,25 +336,32 @@ document.getElementById('bindSpace').addEventListener('click', () => {
249
336
  if (webex.devicemanager) {
250
337
  notify('Binding space...');
251
338
  const convoId = document.getElementById('convoId').value;
339
+
252
340
  let url;
253
341
 
254
- return webex.internal.services.waitForCatalog('postauth')
342
+ return webex.internal.services
343
+ .waitForCatalog('postauth')
255
344
  .then(() => {
256
345
  url = `${webex.internal.services.get('conversation')}/conversations/${convoId}`;
257
346
 
258
- return webex.internal.conversation.get({url}, {
259
- url,
260
- includeUxTimers: true,
261
- ackFilter: 'noack',
262
- includeParticipants: false,
263
- lastViewableActivityOnly: true,
264
- participantsLimit: 0
265
- });
347
+ return webex.internal.conversation.get(
348
+ {url},
349
+ {
350
+ url,
351
+ includeUxTimers: true,
352
+ ackFilter: 'noack',
353
+ includeParticipants: false,
354
+ lastViewableActivityOnly: true,
355
+ participantsLimit: 0,
356
+ }
357
+ );
266
358
  })
267
- .then((conversation) => webex.devicemanager.bindSpace({
268
- url,
269
- kmsResourceObjectUrl: conversation.kmsResourceObjectUrl
270
- }))
359
+ .then((conversation) =>
360
+ webex.devicemanager.bindSpace({
361
+ url,
362
+ kmsResourceObjectUrl: conversation.kmsResourceObjectUrl,
363
+ })
364
+ )
271
365
  .then(() => {
272
366
  notify('Space is bound');
273
367
  toggleDisplay('bindSpaceBtnDiv', false);
@@ -286,7 +380,8 @@ document.getElementById('unbindSpace').addEventListener('click', () => {
286
380
  if (webex.devicemanager) {
287
381
  notify('UnBinding space...');
288
382
 
289
- return webex.devicemanager.unbindSpace()
383
+ return webex.devicemanager
384
+ .unbindSpace()
290
385
  .then(() => {
291
386
  notify('Space is unbound');
292
387
  toggleDisplay('bindSpaceBtnDiv', true);
@@ -307,7 +402,8 @@ document.getElementById('remove').addEventListener('click', () => {
307
402
  const deviceId = dropdown.options[dropdown.selectedIndex].value;
308
403
 
309
404
  if (deviceId && deviceId !== 'Choose a Device') {
310
- return webex.devicemanager.remove(deviceId)
405
+ return webex.devicemanager
406
+ .remove(deviceId)
311
407
  .then(() => {
312
408
  notify('Device removed');
313
409
 
@@ -333,9 +429,10 @@ document.getElementById('search').addEventListener('click', () => {
333
429
  const searchQuery = document.getElementById('searchQuery').value;
334
430
 
335
431
  if (searchQuery && searchQuery.length >= 3) {
336
- return webex.devicemanager.search({
337
- searchQuery
338
- })
432
+ return webex.devicemanager
433
+ .search({
434
+ searchQuery,
435
+ })
339
436
  .then((res) => {
340
437
  populateDeviceSearchResults(res);
341
438
  })
@@ -349,94 +446,6 @@ document.getElementById('search').addEventListener('click', () => {
349
446
  return false;
350
447
  });
351
448
 
352
- function notify(message) {
353
- document.getElementById('notifications').innerHTML = message;
354
- setTimeout(() => {
355
- document.getElementById('notifications').innerHTML = '';
356
- }, 5000);
357
- }
358
-
359
- function populateDeviceDropdown(devices) {
360
- const deviceListDropdown = document.getElementById('device-list-dropdown');
361
-
362
- deviceListDropdown.length = 0;
363
-
364
- const defaultOption = document.createElement('option');
365
-
366
- defaultOption.text = 'Choose a Device';
367
- deviceListDropdown.add(defaultOption);
368
- deviceListDropdown.selectedIndex = 0;
369
-
370
- let option;
371
-
372
- devices.forEach((device) => {
373
- option = document.createElement('option');
374
- option.text = device.deviceInfo.description || device.deviceInfo.name;
375
- option.value = device.id;
376
- deviceListDropdown.add(option);
377
- });
378
- }
379
-
380
- function populateDeviceAudioState(audioState) {
381
- document.getElementById('getAudioStateContentsDiv').innerHTML = `<div>
382
- <ul>
383
- <li>Muted: ${audioState.microphones.muted}</li>
384
- <li>volume current level: ${audioState.volume.level}</li>
385
- <li>volume max level: ${audioState.volume.max}</li>
386
- <li>volume min level: ${audioState.volume.min}</li>
387
- <li>volume step level: ${audioState.volume.step}</li>
388
- </ul>
389
- <div id='hideAudioStateBtnDiv' style=muted"display:none;">
390
- <button id="hideAudioState" title="hideAudioState" type="button">hideAudioState</button>
391
- </div>
392
- </div>`;
393
- toggleDisplay('getAudioStateContentsDiv', true);
394
- toggleDisplay('hideAudioStateBtnDiv', true);
395
- // hideAudioState of the paired device
396
- document.getElementById('hideAudioState').addEventListener('click', () => {
397
- toggleDisplay('getAudioStateContentsDiv', false);
398
- toggleDisplay('hideAudioStateBtnDiv', false);
399
- });
400
- }
401
-
402
- function populateDeviceSearchResults(response) {
403
- let devices = '';
404
-
405
- response.forEach((device) => {
406
- devices += `
407
- <li style='list-style-type: none'>
408
- <input type='radio' name='deviceRadio' onclick='requestPinChallenge("${device.id}")'/>
409
- <label>${device.description || device.name}</label>
410
- </li>`;
411
- });
412
- document.getElementById('getDeviceSearchResultsDiv').innerHTML = `<div>
413
- <ul>
414
- ${devices}
415
- </ul>
416
- <div id='hideDeviceSearchResultsBtnDiv' style=muted"display:none;">
417
- <button id="hideDeviceSearchResults" title="hideDeviceSearchResults" type="button">hideDeviceSearchResults</button>
418
- </div>
419
- </div>`;
420
- toggleDisplay('getDeviceSearchResultsDiv', true);
421
- toggleDisplay('hideDeviceSearchResults', true);
422
- // hideAudioState of the paired device
423
- document.getElementById('hideDeviceSearchResults').addEventListener('click', () => {
424
- toggleDisplay('getDeviceSearchResultsDiv', false);
425
- toggleDisplay('hideDeviceSearchResults', false);
426
- });
427
- }
428
-
429
- function toggleDisplay(elementId, status) {
430
- const element = document.getElementById(elementId);
431
-
432
- if (status) {
433
- element.style.display = 'block';
434
- }
435
- else {
436
- element.style.display = 'none';
437
- }
438
- }
439
-
440
449
  document.getElementById('credentials').addEventListener('submit', (event) => {
441
450
  // let's make sure we don't reload the page when we submit the form
442
451
  event.preventDefault();
package/src/collection.js CHANGED
@@ -8,15 +8,14 @@ const DeviceCollection = {
8
8
  },
9
9
 
10
10
  set(device) {
11
- const deviceId = device.id || device.identity && device.identity.id;
11
+ const deviceId = device.id || (device.identity && device.identity.id);
12
12
  // check if the device is already existing, if so then merge else add
13
13
  const existingDevice = this.devices[deviceId];
14
14
 
15
15
  if (existingDevice) {
16
16
  // already existing, merge for any new binding information
17
17
  merge(existingDevice, device);
18
- }
19
- else {
18
+ } else {
20
19
  this.devices[deviceId] = device;
21
20
  }
22
21
  },
@@ -27,8 +26,7 @@ const DeviceCollection = {
27
26
 
28
27
  getAll() {
29
28
  return Object.values(this.devices);
30
- }
31
-
29
+ },
32
30
  };
33
31
 
34
32
  export default DeviceCollection;