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.

SmallVideo.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /* global $, APP, require */
  2. var Avatar = require("../avatar/Avatar");
  3. var UIUtil = require("../util/UIUtil");
  4. var LargeVideo = require("./LargeVideo");
  5. var RTCBrowserType = require("../../RTC/RTCBrowserType");
  6. function SmallVideo() {
  7. this.isMuted = false;
  8. this.hasAvatar = false;
  9. }
  10. function setVisibility(selector, show) {
  11. if (selector && selector.length > 0) {
  12. selector.css("visibility", show ? "visible" : "hidden");
  13. }
  14. }
  15. SmallVideo.prototype.showDisplayName = function(isShow) {
  16. var nameSpan = $('#' + this.videoSpanId + '>span.displayname').get(0);
  17. if (isShow) {
  18. if (nameSpan && nameSpan.innerHTML && nameSpan.innerHTML.length)
  19. nameSpan.setAttribute("style", "display:inline-block;");
  20. }
  21. else {
  22. if (nameSpan)
  23. nameSpan.setAttribute("style", "display:none;");
  24. }
  25. };
  26. SmallVideo.prototype.setDeviceAvailabilityIcons = function (devices) {
  27. if(!this.container)
  28. return;
  29. var noMic = $("#" + this.videoSpanId + " > .noMic");
  30. var noVideo = $("#" + this.videoSpanId + " > .noVideo");
  31. noMic.remove();
  32. noVideo.remove();
  33. if (!devices.audio) {
  34. this.container.appendChild(
  35. document.createElement("div")).setAttribute("class", "noMic");
  36. }
  37. if (!devices.video) {
  38. this.container.appendChild(
  39. document.createElement("div")).setAttribute("class", "noVideo");
  40. }
  41. if (!devices.audio && !devices.video) {
  42. noMic.css("background-position", "75%");
  43. noVideo.css("background-position", "25%");
  44. noVideo.css("background-color", "transparent");
  45. }
  46. };
  47. /**
  48. * Shows the presence status message for the given video.
  49. */
  50. SmallVideo.prototype.setPresenceStatus = function (statusMsg) {
  51. if (!this.container) {
  52. // No container
  53. return;
  54. }
  55. var statusSpan = $('#' + this.videoSpanId + '>span.status');
  56. if (!statusSpan.length) {
  57. //Add status span
  58. statusSpan = document.createElement('span');
  59. statusSpan.className = 'status';
  60. statusSpan.id = this.videoSpanId + '_status';
  61. $('#' + this.videoSpanId)[0].appendChild(statusSpan);
  62. statusSpan = $('#' + this.videoSpanId + '>span.status');
  63. }
  64. // Display status
  65. if (statusMsg && statusMsg.length) {
  66. $('#' + this.videoSpanId + '_status').text(statusMsg);
  67. statusSpan.get(0).setAttribute("style", "display:inline-block;");
  68. }
  69. else {
  70. // Hide
  71. statusSpan.get(0).setAttribute("style", "display:none;");
  72. }
  73. };
  74. /**
  75. * Creates an audio or video stream element.
  76. */
  77. SmallVideo.createStreamElement = function (sid, stream) {
  78. var isVideo = stream.getVideoTracks().length > 0;
  79. var element = isVideo ? document.createElement('video')
  80. : document.createElement('audio');
  81. var id = (isVideo ? 'remoteVideo_' : 'remoteAudio_') + sid + '_' +
  82. APP.RTC.getStreamID(stream);
  83. element.id = id;
  84. if (!RTCBrowserType.isIExplorer()) {
  85. element.autoplay = true;
  86. }
  87. element.oncontextmenu = function () { return false; };
  88. return element;
  89. };
  90. /**
  91. * Updates the data for the indicator
  92. * @param id the id of the indicator
  93. * @param percent the percent for connection quality
  94. * @param object the data
  95. */
  96. SmallVideo.prototype.updateStatsIndicator = function (percent, object) {
  97. if(this.connectionIndicator)
  98. this.connectionIndicator.updateConnectionQuality(percent, object);
  99. };
  100. SmallVideo.prototype.hideIndicator = function () {
  101. if(this.connectionIndicator)
  102. this.connectionIndicator.hideIndicator();
  103. };
  104. /**
  105. * Shows audio muted indicator over small videos.
  106. * @param {string} isMuted
  107. */
  108. SmallVideo.prototype.showAudioIndicator = function(isMuted) {
  109. var audioMutedSpan = $('#' + this.videoSpanId + '>span.audioMuted');
  110. if (!isMuted) {
  111. if (audioMutedSpan.length > 0) {
  112. audioMutedSpan.popover('hide');
  113. audioMutedSpan.remove();
  114. }
  115. }
  116. else {
  117. if(audioMutedSpan.length == 0 ) {
  118. audioMutedSpan = document.createElement('span');
  119. audioMutedSpan.className = 'audioMuted';
  120. UIUtil.setTooltip(audioMutedSpan,
  121. "videothumbnail.mute",
  122. "top");
  123. this.container.appendChild(audioMutedSpan);
  124. APP.translation.translateElement($('#' + this.videoSpanId + " > span"));
  125. var mutedIndicator = document.createElement('i');
  126. mutedIndicator.className = 'icon-mic-disabled';
  127. audioMutedSpan.appendChild(mutedIndicator);
  128. }
  129. this.updateIconPositions();
  130. }
  131. this.isMuted = isMuted;
  132. };
  133. /**
  134. * Shows video muted indicator over small videos.
  135. */
  136. SmallVideo.prototype.showVideoIndicator = function(isMuted) {
  137. this.showAvatar(isMuted);
  138. var videoMutedSpan = $('#' + this.videoSpanId + '>span.videoMuted');
  139. if (isMuted === false) {
  140. if (videoMutedSpan.length > 0) {
  141. videoMutedSpan.remove();
  142. }
  143. }
  144. else {
  145. if(videoMutedSpan.length == 0) {
  146. videoMutedSpan = document.createElement('span');
  147. videoMutedSpan.className = 'videoMuted';
  148. this.container.appendChild(videoMutedSpan);
  149. var mutedIndicator = document.createElement('i');
  150. mutedIndicator.className = 'icon-camera-disabled';
  151. UIUtil.setTooltip(mutedIndicator,
  152. "videothumbnail.videomute",
  153. "top");
  154. videoMutedSpan.appendChild(mutedIndicator);
  155. //translate texts for muted indicator
  156. APP.translation.translateElement($('#' + this.videoSpanId + " > span > i"));
  157. }
  158. this.updateIconPositions();
  159. }
  160. };
  161. SmallVideo.prototype.enableDominantSpeaker = function (isEnable) {
  162. var resourceJid = this.getResourceJid();
  163. var displayName = resourceJid;
  164. var nameSpan = $('#' + this.videoSpanId + '>span.displayname');
  165. if (nameSpan.length > 0)
  166. displayName = nameSpan.html();
  167. console.log("UI enable dominant speaker",
  168. displayName,
  169. resourceJid,
  170. isEnable);
  171. if (!this.container) {
  172. return;
  173. }
  174. if (isEnable) {
  175. this.showDisplayName(LargeVideo.getState() === "video");
  176. if (!this.container.classList.contains("dominantspeaker"))
  177. this.container.classList.add("dominantspeaker");
  178. }
  179. else {
  180. this.showDisplayName(false);
  181. if (this.container.classList.contains("dominantspeaker"))
  182. this.container.classList.remove("dominantspeaker");
  183. }
  184. this.showAvatar();
  185. };
  186. SmallVideo.prototype.updateIconPositions = function () {
  187. var audioMutedSpan = $('#' + this.videoSpanId + '>span.audioMuted');
  188. var connectionIndicator = $('#' + this.videoSpanId + '>div.connectionindicator');
  189. var videoMutedSpan = $('#' + this.videoSpanId + '>span.videoMuted');
  190. if(connectionIndicator.length > 0 &&
  191. connectionIndicator[0].style.display != "none") {
  192. audioMutedSpan.css({right: "23px"});
  193. videoMutedSpan.css({right: ((audioMutedSpan.length > 0? 23 : 0) + 30) + "px"});
  194. } else {
  195. audioMutedSpan.css({right: "0px"});
  196. videoMutedSpan.css({right: (audioMutedSpan.length > 0? 30 : 0) + "px"});
  197. }
  198. };
  199. /**
  200. * Creates the element indicating the moderator(owner) of the conference.
  201. *
  202. * @param parentElement the parent element where the owner indicator will
  203. * be added
  204. */
  205. SmallVideo.prototype.createModeratorIndicatorElement = function () {
  206. // Show moderator indicator
  207. var indicatorSpan = $('#' + this.videoSpanId + ' .focusindicator');
  208. if (!indicatorSpan || indicatorSpan.length === 0) {
  209. indicatorSpan = document.createElement('span');
  210. indicatorSpan.className = 'focusindicator';
  211. this.container.appendChild(indicatorSpan);
  212. indicatorSpan = $('#' + this.videoSpanId + ' .focusindicator');
  213. }
  214. if (indicatorSpan.children().length !== 0)
  215. return;
  216. var moderatorIndicator = document.createElement('i');
  217. moderatorIndicator.className = 'fa fa-star';
  218. indicatorSpan[0].appendChild(moderatorIndicator);
  219. UIUtil.setTooltip(indicatorSpan[0],
  220. "videothumbnail.moderator",
  221. "top");
  222. //translates text in focus indicators
  223. APP.translation.translateElement($('#' + this.videoSpanId + ' .focusindicator'));
  224. };
  225. SmallVideo.prototype.getSrc = function () {
  226. var videoElement = APP.RTC.getVideoElementName();
  227. return APP.RTC.getVideoSrc(
  228. $('#' + this.videoSpanId).find(videoElement).get(0));
  229. };
  230. SmallVideo.prototype.focus = function(isFocused) {
  231. if(!isFocused) {
  232. this.container.classList.remove("videoContainerFocused");
  233. } else {
  234. this.container.classList.add("videoContainerFocused");
  235. }
  236. };
  237. SmallVideo.prototype.hasVideo = function () {
  238. return $("#" + this.videoSpanId).find(
  239. APP.RTC.getVideoElementName()).length !== 0;
  240. };
  241. /**
  242. * Hides or shows the user's avatar
  243. * @param show whether we should show the avatar or not
  244. * video because there is no dominant speaker and no focused speaker
  245. */
  246. SmallVideo.prototype.showAvatar = function (show) {
  247. if (!this.hasAvatar) {
  248. if (this.peerJid) {
  249. // Init avatar
  250. this.avatarChanged(Avatar.getThumbUrl(this.peerJid));
  251. } else {
  252. console.error("Unable to init avatar - no peerjid", this);
  253. return;
  254. }
  255. }
  256. var resourceJid = this.getResourceJid();
  257. var videoElem = APP.RTC.getVideoElementName();
  258. var video = $('#' + this.videoSpanId).find(videoElem);
  259. var avatar = $('#avatar_' + resourceJid);
  260. if (show === undefined || show === null) {
  261. if (!this.isLocal &&
  262. !this.VideoLayout.isInLastN(resourceJid)) {
  263. show = true;
  264. } else {
  265. // We want to show the avatar when the video is muted or not exists
  266. // that is when 'true' or 'null' is returned
  267. show = APP.RTC.isVideoMuted(this.peerJid) !== false;
  268. }
  269. }
  270. if (LargeVideo.showAvatar(resourceJid, show)) {
  271. setVisibility(avatar, false);
  272. setVisibility(video, false);
  273. } else {
  274. if (video && video.length > 0) {
  275. setVisibility(video, !show);
  276. }
  277. setVisibility(avatar, show);
  278. }
  279. };
  280. SmallVideo.prototype.avatarChanged = function (thumbUrl) {
  281. var thumbnail = $('#' + this.videoSpanId);
  282. var resourceJid = this.getResourceJid();
  283. var avatar = $('#avatar_' + resourceJid);
  284. this.hasAvatar = true;
  285. // set the avatar in the thumbnail
  286. if (avatar && avatar.length > 0) {
  287. avatar[0].src = thumbUrl;
  288. } else {
  289. if (thumbnail && thumbnail.length > 0) {
  290. avatar = document.createElement('img');
  291. avatar.id = 'avatar_' + resourceJid;
  292. avatar.className = 'userAvatar';
  293. avatar.src = thumbUrl;
  294. thumbnail.append(avatar);
  295. }
  296. }
  297. };
  298. module.exports = SmallVideo;