You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. var UIUtil = require("../util/UIUtil");
  2. var LargeVideo = require("./LargeVideo");
  3. function SmallVideo(){
  4. this.isMuted = false;
  5. }
  6. SmallVideo.prototype.showDisplayName = function(isShow) {
  7. var nameSpan = $('#' + this.videoSpanId + '>span.displayname').get(0);
  8. if (isShow) {
  9. if (nameSpan && nameSpan.innerHTML && nameSpan.innerHTML.length)
  10. nameSpan.setAttribute("style", "display:inline-block;");
  11. }
  12. else {
  13. if (nameSpan)
  14. nameSpan.setAttribute("style", "display:none;");
  15. }
  16. };
  17. SmallVideo.prototype.setDeviceAvailabilityIcons = function (devices) {
  18. if(!this.container)
  19. return;
  20. $("#" + this.videoSpanId + " > .noMic").remove();
  21. $("#" + this.videoSpanId + " > .noVideo").remove();
  22. if(!devices.audio)
  23. {
  24. this.container.appendChild(
  25. document.createElement("div")).setAttribute("class","noMic");
  26. }
  27. if(!devices.video)
  28. {
  29. this.container.appendChild(
  30. document.createElement("div")).setAttribute("class","noVideo");
  31. }
  32. if(!devices.audio && !devices.video)
  33. {
  34. $("#" + this.videoSpanId + " > .noMic").css("background-position", "75%");
  35. $("#" + this.videoSpanId + " > .noVideo").css("background-position", "25%");
  36. $("#" + this.videoSpanId + " > .noVideo").css("background-color", "transparent");
  37. }
  38. }
  39. /**
  40. * Shows the presence status message for the given video.
  41. */
  42. SmallVideo.prototype.setPresenceStatus = function (statusMsg) {
  43. if (!this.container) {
  44. // No container
  45. return;
  46. }
  47. var statusSpan = $('#' + this.videoSpanId + '>span.status');
  48. if (!statusSpan.length) {
  49. //Add status span
  50. statusSpan = document.createElement('span');
  51. statusSpan.className = 'status';
  52. statusSpan.id = this.videoSpanId + '_status';
  53. $('#' + this.videoSpanId)[0].appendChild(statusSpan);
  54. statusSpan = $('#' + this.videoSpanId + '>span.status');
  55. }
  56. // Display status
  57. if (statusMsg && statusMsg.length) {
  58. $('#' + this.videoSpanId + '_status').text(statusMsg);
  59. statusSpan.get(0).setAttribute("style", "display:inline-block;");
  60. }
  61. else {
  62. // Hide
  63. statusSpan.get(0).setAttribute("style", "display:none;");
  64. }
  65. };
  66. /**
  67. * Creates an audio or video stream element.
  68. */
  69. SmallVideo.createStreamElement = function (sid, stream) {
  70. var isVideo = stream.getVideoTracks().length > 0;
  71. var element = isVideo
  72. ? document.createElement('video')
  73. : document.createElement('audio');
  74. var id = (isVideo ? 'remoteVideo_' : 'remoteAudio_')
  75. + sid + '_' + APP.RTC.getStreamID(stream);
  76. element.id = id;
  77. element.autoplay = true;
  78. element.oncontextmenu = function () { return false; };
  79. return element;
  80. };
  81. /**
  82. * Updates the data for the indicator
  83. * @param id the id of the indicator
  84. * @param percent the percent for connection quality
  85. * @param object the data
  86. */
  87. SmallVideo.prototype.updateStatsIndicator = function (percent, object) {
  88. if(this.connectionIndicator)
  89. this.connectionIndicator.updateConnectionQuality(percent, object);
  90. }
  91. SmallVideo.prototype.hideIndicator = function () {
  92. if(this.connectionIndicator)
  93. this.connectionIndicator.hideIndicator();
  94. }
  95. /**
  96. * Shows audio muted indicator over small videos.
  97. * @param {string} isMuted
  98. */
  99. SmallVideo.prototype.showAudioIndicator = function(isMuted) {
  100. var audioMutedSpan = $('#' + this.videoSpanId + '>span.audioMuted');
  101. if (isMuted === 'false') {
  102. if (audioMutedSpan.length > 0) {
  103. audioMutedSpan.popover('hide');
  104. audioMutedSpan.remove();
  105. }
  106. }
  107. else {
  108. if(audioMutedSpan.length == 0 ) {
  109. audioMutedSpan = document.createElement('span');
  110. audioMutedSpan.className = 'audioMuted';
  111. UIUtil.setTooltip(audioMutedSpan,
  112. "videothumbnail.mute",
  113. "top");
  114. this.container.appendChild(audioMutedSpan);
  115. APP.translation.translateElement($('#' + this.videoSpanId + " > span"));
  116. var mutedIndicator = document.createElement('i');
  117. mutedIndicator.className = 'icon-mic-disabled';
  118. audioMutedSpan.appendChild(mutedIndicator);
  119. }
  120. this.updateIconPositions();
  121. }
  122. this.isMuted = isMuted;
  123. };
  124. /**
  125. * Shows video muted indicator over small videos.
  126. */
  127. SmallVideo.prototype.showVideoIndicator = function(isMuted) {
  128. var videoMutedSpan = $('#' + this.videoSpanId + '>span.videoMuted');
  129. if (isMuted === false) {
  130. if (videoMutedSpan.length > 0) {
  131. videoMutedSpan.remove();
  132. }
  133. }
  134. else {
  135. if(videoMutedSpan.length == 0) {
  136. videoMutedSpan = document.createElement('span');
  137. videoMutedSpan.className = 'videoMuted';
  138. this.container.appendChild(videoMutedSpan);
  139. var mutedIndicator = document.createElement('i');
  140. mutedIndicator.className = 'icon-camera-disabled';
  141. UIUtil.setTooltip(mutedIndicator,
  142. "videothumbnail.videomute",
  143. "top");
  144. videoMutedSpan.appendChild(mutedIndicator);
  145. //translate texts for muted indicator
  146. APP.translation.translateElement($('#' + this.videoSpanId + " > span > i"));
  147. }
  148. this.updateIconPositions();
  149. }
  150. };
  151. SmallVideo.prototype.enableDominantSpeaker = function (isEnable)
  152. {
  153. var displayName = this.resourceJid;
  154. var nameSpan = $('#' + this.videoSpanId + '>span.displayname');
  155. if (nameSpan.length > 0)
  156. displayName = nameSpan.html();
  157. console.log("UI enable dominant speaker",
  158. displayName,
  159. this.resourceJid,
  160. isEnable);
  161. if (!this.container) {
  162. return;
  163. }
  164. var video = $('#' + this.videoSpanId + '>video');
  165. if (video && video.length > 0) {
  166. if (isEnable) {
  167. this.showDisplayName(LargeVideo.isLargeVideoOnTop());
  168. if (!this.container.classList.contains("dominantspeaker"))
  169. this.container.classList.add("dominantspeaker");
  170. }
  171. else {
  172. this.showDisplayName(false);
  173. if (this.container.classList.contains("dominantspeaker"))
  174. this.container.classList.remove("dominantspeaker");
  175. }
  176. }
  177. };
  178. SmallVideo.prototype.updateIconPositions = function () {
  179. var audioMutedSpan = $('#' + this.videoSpanId + '>span.audioMuted');
  180. var connectionIndicator = $('#' + this.videoSpanId + '>div.connectionindicator');
  181. var videoMutedSpan = $('#' + this.videoSpanId + '>span.videoMuted');
  182. if(connectionIndicator.length > 0
  183. && connectionIndicator[0].style.display != "none") {
  184. audioMutedSpan.css({right: "23px"});
  185. videoMutedSpan.css({right: ((audioMutedSpan.length > 0? 23 : 0) + 30) + "px"});
  186. }
  187. else
  188. {
  189. audioMutedSpan.css({right: "0px"});
  190. videoMutedSpan.css({right: (audioMutedSpan.length > 0? 30 : 0) + "px"});
  191. }
  192. }
  193. /**
  194. * Creates the element indicating the moderator(owner) of the conference.
  195. *
  196. * @param parentElement the parent element where the owner indicator will
  197. * be added
  198. */
  199. SmallVideo.prototype.createModeratorIndicatorElement = function () {
  200. // Show moderator indicator
  201. var indicatorSpan = $('#' + this.videoSpanId + ' .focusindicator');
  202. if (!indicatorSpan || indicatorSpan.length === 0) {
  203. indicatorSpan = document.createElement('span');
  204. indicatorSpan.className = 'focusindicator';
  205. this.container.appendChild(indicatorSpan);
  206. indicatorSpan = $('#' + this.videoSpanId + ' .focusindicator');
  207. }
  208. if (indicatorSpan.children().length !== 0)
  209. return;
  210. var moderatorIndicator = document.createElement('i');
  211. moderatorIndicator.className = 'fa fa-star';
  212. indicatorSpan[0].appendChild(moderatorIndicator);
  213. UIUtil.setTooltip(indicatorSpan[0],
  214. "videothumbnail.moderator",
  215. "top");
  216. //translates text in focus indicators
  217. APP.translation.translateElement($('#' + this.videoSpanId + ' .focusindicator'));
  218. }
  219. SmallVideo.prototype.getSrc = function () {
  220. return APP.RTC.getVideoSrc($('#' + this.videoSpanId).find("video").get(0));
  221. }
  222. SmallVideo.prototype.focus = function(isFocused)
  223. {
  224. if(!isFocused) {
  225. this.container.classList.remove("videoContainerFocused");
  226. }
  227. else
  228. {
  229. this.container.classList.add("videoContainerFocused");
  230. }
  231. }
  232. SmallVideo.prototype.hasVideo = function () {
  233. return $("#" + this.videoSpanId).find("video").length !== 0;
  234. }
  235. module.exports = SmallVideo;