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

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