您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RTCUIHelper.js 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* global $ */
  2. var RTCBrowserType = require("./RTCBrowserType");
  3. var RTC = require('./RTC');
  4. var RTCUIHelper = {
  5. /**
  6. * Returns the name of 'video' element depending on the browser that we're
  7. * currently using.
  8. * @returns {string} 'video' or 'object' string name of WebRTC video element
  9. */
  10. getVideoElementName: function () {
  11. return RTCBrowserType.isTemasysPluginUsed() ? 'object' : 'video';
  12. },
  13. /**
  14. * Finds video element inside of the given container.
  15. * @param containerElement HTML element node instance which is supposed to
  16. * contain the video element.
  17. * @returns {HTMLElement} video HTML element instance if found inside of the
  18. * container or undefined otherwise.
  19. */
  20. findVideoElement: function (containerElement) {
  21. var videoElemName = RTCUIHelper.getVideoElementName();
  22. if (!RTCBrowserType.isTemasysPluginUsed()) {
  23. return $(containerElement).find(videoElemName)[0];
  24. } else {
  25. var matching = $(containerElement).find(
  26. ' ' + videoElemName + '>param[value="video"]');
  27. if (matching.length < 2) {
  28. return matching.parent()[0];
  29. } else {
  30. // there are 2 video objects from FF
  31. // object with id which ends with '_default'
  32. // (like 'remoteVideo_default')
  33. // doesn't contain video, so we ignore it
  34. for (var i = 0; i < matching.length; i += 1) {
  35. var el = matching[i].parentNode;
  36. // check id suffix
  37. if (el.id.substr(-8) !== '_default') {
  38. return el;
  39. }
  40. }
  41. }
  42. }
  43. return undefined;
  44. },
  45. /**
  46. * Sets 'volume' property of given HTML element displaying RTC audio or
  47. * video stream.
  48. * @param streamElement HTML element to which the RTC stream is attached to.
  49. * @param volume the volume value to be set.
  50. */
  51. setVolume: function (streamElement, volume) {
  52. if (!RTCBrowserType.isIExplorer()) {
  53. streamElement.volume = volume;
  54. }
  55. },
  56. /**
  57. * Sets 'autoplay' property of given HTML element displaying RTC audio or
  58. * video stream.
  59. * @param streamElement HTML element to which the RTC stream is attached to.
  60. * @param autoPlay 'true' or 'false'
  61. */
  62. setAutoPlay: function (streamElement, autoPlay) {
  63. if (!RTCBrowserType.isIExplorer()) {
  64. streamElement.autoplay = true;
  65. }
  66. },
  67. /**
  68. * Extract video stream id from the video element.
  69. * @param {Element} element
  70. * @returns {string} video stream id or empty string
  71. */
  72. getVideoId: function (element) {
  73. var src = RTC.getVideoSrc(element);
  74. if (!src) {
  75. return "";
  76. }
  77. if (RTCBrowserType.isFirefox()) {
  78. return src.id;
  79. }
  80. return src;
  81. }
  82. };
  83. module.exports = RTCUIHelper;