12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- /* global $ */
- var RTCBrowserType = require("./RTCBrowserType");
- var RTC = require('./RTC');
-
- var RTCUIHelper = {
-
- /**
- * Returns the name of 'video' element depending on the browser that we're
- * currently using.
- * @returns {string} 'video' or 'object' string name of WebRTC video element
- */
- getVideoElementName: function () {
- return RTCBrowserType.isTemasysPluginUsed() ? 'object' : 'video';
- },
-
- /**
- * Finds video element inside of the given container.
- * @param containerElement HTML element node instance which is supposed to
- * contain the video element.
- * @returns {HTMLElement} video HTML element instance if found inside of the
- * container or undefined otherwise.
- */
- findVideoElement: function (containerElement) {
- var videoElemName = RTCUIHelper.getVideoElementName();
- if (!RTCBrowserType.isTemasysPluginUsed()) {
- return $(containerElement).find(videoElemName)[0];
- } else {
- var matching = $(containerElement).find(
- ' ' + videoElemName + '>param[value="video"]');
- if (matching.length < 2) {
- return matching.parent()[0];
- } else {
- // there are 2 video objects from FF
- // object with id which ends with '_default'
- // (like 'remoteVideo_default')
- // doesn't contain video, so we ignore it
- for (var i = 0; i < matching.length; i += 1) {
- var el = matching[i].parentNode;
-
- // check id suffix
- if (el.id.substr(-8) !== '_default') {
- return el;
- }
- }
- }
- }
- return undefined;
- },
- /**
- * Sets 'volume' property of given HTML element displaying RTC audio or
- * video stream.
- * @param streamElement HTML element to which the RTC stream is attached to.
- * @param volume the volume value to be set.
- */
- setVolume: function (streamElement, volume) {
- if (!RTCBrowserType.isIExplorer()) {
- streamElement.volume = volume;
- }
- },
- /**
- * Sets 'autoplay' property of given HTML element displaying RTC audio or
- * video stream.
- * @param streamElement HTML element to which the RTC stream is attached to.
- * @param autoPlay 'true' or 'false'
- */
- setAutoPlay: function (streamElement, autoPlay) {
- if (!RTCBrowserType.isIExplorer()) {
- streamElement.autoplay = true;
- }
- },
-
- /**
- * Extract video stream id from the video element.
- * @param {Element} element
- * @returns {string} video stream id or empty string
- */
- getVideoId: function (element) {
- var src = RTC.getVideoSrc(element);
- if (!src) {
- return "";
- }
-
- if (RTCBrowserType.isFirefox()) {
- return src.id;
- }
-
- return src;
- }
- };
-
- module.exports = RTCUIHelper;
|