瀏覽代碼

Volume slider for remote participant audio elements

j8
Leonard Kim 8 年之前
父節點
當前提交
02b26a65bb
共有 2 個文件被更改,包括 93 次插入2 次删除
  1. 8
    2
      css/_popup_menu.scss
  2. 85
    0
      modules/UI/videolayout/RemoteVideo.js

+ 8
- 2
css/_popup_menu.scss 查看文件

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

+ 85
- 0
modules/UI/videolayout/RemoteVideo.js 查看文件

28
     this.emitter = emitter;
28
     this.emitter = emitter;
29
     this.videoSpanId = `participant_${this.id}`;
29
     this.videoSpanId = `participant_${this.id}`;
30
     SmallVideo.call(this, VideoLayout);
30
     SmallVideo.call(this, VideoLayout);
31
+    this._audioStreamElement = null;
31
     this.hasRemoteVideoMenu = false;
32
     this.hasRemoteVideoMenu = false;
32
     this._supportsRemoteControl = false;
33
     this._supportsRemoteControl = false;
33
     this.addRemoteVideoContainer();
34
     this.addRemoteVideoContainer();
200
         popupmenuElement.appendChild(menuItem);
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
     APP.translation.translateElement($(popupmenuElement));
216
     APP.translation.translateElement($(popupmenuElement));
204
 
217
 
205
     return popupmenuElement;
218
     return popupmenuElement;
343
     return menuItem;
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
  * Updates the remote video menu.
428
  * Updates the remote video menu.
348
  *
429
  *
613
     }
694
     }
614
 
695
 
615
     $(streamElement).click(onClickHandler);
696
     $(streamElement).click(onClickHandler);
697
+
698
+    if (!isVideo) {
699
+        this._audioStreamElement = streamElement;
700
+    }
616
 };
701
 };
617
 
702
 
618
 /**
703
 /**

Loading…
取消
儲存