Pārlūkot izejas kodu

Volume slider for remote participant audio elements

j8
Leonard Kim 8 gadus atpakaļ
vecāks
revīzija
02b26a65bb
2 mainītis faili ar 93 papildinājumiem un 2 dzēšanām
  1. 8
    2
      css/_popup_menu.scss
  2. 85
    0
      modules/UI/videolayout/RemoteVideo.js

+ 8
- 2
css/_popup_menu.scss Parādīt failu

@@ -23,7 +23,8 @@
23 23
     }
24 24
 
25 25
     // Link Appearance
26
-    &__link {
26
+    &__link,
27
+    &__contents {
27 28
         display: block;
28 29
         box-sizing: border-box;
29 30
         text-decoration: none;
@@ -40,11 +41,16 @@
40 41
         }
41 42
     }
42 43
 
43
-    &__text {
44
+    &__text,
45
+    &__slider {
44 46
         display: inline-block;
45 47
         vertical-align: middle;
46 48
     }
47 49
 
50
+    &__slider {
51
+        width: 50px;
52
+    }
53
+
48 54
     &__icon {
49 55
         vertical-align: middle;
50 56
         position: relative;

+ 85
- 0
modules/UI/videolayout/RemoteVideo.js Parādīt failu

@@ -28,6 +28,7 @@ function RemoteVideo(user, VideoLayout, emitter) {
28 28
     this.emitter = emitter;
29 29
     this.videoSpanId = `participant_${this.id}`;
30 30
     SmallVideo.call(this, VideoLayout);
31
+    this._audioStreamElement = null;
31 32
     this.hasRemoteVideoMenu = false;
32 33
     this._supportsRemoteControl = false;
33 34
     this.addRemoteVideoContainer();
@@ -200,6 +201,18 @@ RemoteVideo.prototype._generatePopupContent = function () {
200 201
         popupmenuElement.appendChild(menuItem);
201 202
     });
202 203
 
204
+    // feature check for volume setting as temasys objects cannot adjust volume
205
+    if (this._canSetAudioVolume()) {
206
+        const volumeScale = 100;
207
+        const volumeSlider = this._generatePopupMenuSliderItem({
208
+            handler: this._setAudioVolume.bind(this, volumeScale),
209
+            icon: 'icon-volume',
210
+            initialValue: this._getAudioElement().volume * volumeScale,
211
+            maxValue: volumeScale
212
+        });
213
+        popupmenuElement.appendChild(volumeSlider);
214
+    }
215
+
203 216
     APP.translation.translateElement($(popupmenuElement));
204 217
 
205 218
     return popupmenuElement;
@@ -343,6 +356,74 @@ RemoteVideo.prototype._generatePopupMenuItem = function (opts = {}) {
343 356
     return menuItem;
344 357
 };
345 358
 
359
+/**
360
+ * Create a div element with a slider.
361
+ *
362
+ * @param {object} options - Configuration for the div's display and slider.
363
+ * @param {string} options.icon - The classname for the icon to display.
364
+ * @param {int} options.maxValue - The maximum value on the slider. The default
365
+ * value is 100.
366
+ * @param {int} options.initialValue - The value the slider should start at.
367
+ * The default value is 0.
368
+ * @param {function} options.handler - The callback for slider value changes.
369
+ * @returns {Element} A div element with a slider.
370
+ */
371
+RemoteVideo.prototype._generatePopupMenuSliderItem = function (options) {
372
+    const template = `<div class='popupmenu__contents'>
373
+        <span class='popupmenu__icon'>
374
+            <i class=${options.icon}></i>
375
+        </span>
376
+        <input class='popupmenu__slider'
377
+            type='range'
378
+            min='0'
379
+            max=${options.maxValue || 100}
380
+            value=${options.initialValue || 0}>
381
+        </input>
382
+    </div>`;
383
+
384
+    const menuItem = document.createElement('li');
385
+    menuItem.className = 'popupmenu__item';
386
+    menuItem.innerHTML = template;
387
+
388
+    const slider = menuItem.getElementsByClassName('popupmenu__slider')[0];
389
+    slider.oninput = function () {
390
+        options.handler(Number(slider.value));
391
+    };
392
+
393
+    return menuItem;
394
+};
395
+
396
+/**
397
+ * Get the remote participant's audio element.
398
+ *
399
+ * @returns {Element} audio element
400
+ */
401
+RemoteVideo.prototype._getAudioElement = function () {
402
+    return this._audioStreamElement;
403
+};
404
+
405
+/**
406
+ * Check if the remote participant's audio can have its volume adjusted.
407
+ *
408
+ * @returns {boolean} true if the volume can be adjusted.
409
+ */
410
+RemoteVideo.prototype._canSetAudioVolume = function () {
411
+    const audioElement = this._getAudioElement();
412
+    return audioElement && audioElement.volume !== undefined;
413
+};
414
+
415
+/**
416
+ * Change the remote participant's volume level.
417
+ *
418
+ * @param {int} scale - The maximum value the slider can go to.
419
+ * @param {int} newVal - The value to set the slider to.
420
+ */
421
+RemoteVideo.prototype._setAudioVolume = function (scale, newVal) {
422
+    if (this._canSetAudioVolume()) {
423
+        this._getAudioElement().volume = newVal / scale;
424
+    }
425
+};
426
+
346 427
 /**
347 428
  * Updates the remote video menu.
348 429
  *
@@ -613,6 +694,10 @@ RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
613 694
     }
614 695
 
615 696
     $(streamElement).click(onClickHandler);
697
+
698
+    if (!isVideo) {
699
+        this._audioStreamElement = streamElement;
700
+    }
616 701
 };
617 702
 
618 703
 /**

Notiek ielāde…
Atcelt
Saglabāt