Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SmallVideo.js 11KB

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