Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SmallVideo.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. var UIUtil = require("../util/UIUtil");
  2. var LargeVideo = require("./LargeVideo");
  3. var RTCBrowserType = require("../../RTC/RTCBrowserType");
  4. function SmallVideo(){
  5. this.isMuted = false;
  6. this.hasAvatar = false;
  7. }
  8. function setVisibility(selector, show) {
  9. if (selector && selector.length > 0) {
  10. selector.css("visibility", show ? "visible" : "hidden");
  11. }
  12. }
  13. SmallVideo.prototype.showDisplayName = function(isShow) {
  14. var nameSpan = $('#' + this.videoSpanId + '>span.displayname').get(0);
  15. if (isShow) {
  16. if (nameSpan && nameSpan.innerHTML && nameSpan.innerHTML.length)
  17. nameSpan.setAttribute("style", "display:inline-block;");
  18. }
  19. else {
  20. if (nameSpan)
  21. nameSpan.setAttribute("style", "display:none;");
  22. }
  23. };
  24. SmallVideo.prototype.setDeviceAvailabilityIcons = function (devices) {
  25. if(!this.container)
  26. return;
  27. $("#" + this.videoSpanId + " > .noMic").remove();
  28. $("#" + this.videoSpanId + " > .noVideo").remove();
  29. if(!devices.audio)
  30. {
  31. this.container.appendChild(
  32. document.createElement("div")).setAttribute("class","noMic");
  33. }
  34. if(!devices.video)
  35. {
  36. this.container.appendChild(
  37. document.createElement("div")).setAttribute("class","noVideo");
  38. }
  39. if(!devices.audio && !devices.video)
  40. {
  41. $("#" + this.videoSpanId + " > .noMic").css("background-position", "75%");
  42. $("#" + this.videoSpanId + " > .noVideo").css("background-position", "25%");
  43. $("#" + this.videoSpanId + " > .noVideo").css("background-color", "transparent");
  44. }
  45. }
  46. /**
  47. * Shows the presence status message for the given video.
  48. */
  49. SmallVideo.prototype.setPresenceStatus = function (statusMsg) {
  50. if (!this.container) {
  51. // No container
  52. return;
  53. }
  54. var statusSpan = $('#' + this.videoSpanId + '>span.status');
  55. if (!statusSpan.length) {
  56. //Add status span
  57. statusSpan = document.createElement('span');
  58. statusSpan.className = 'status';
  59. statusSpan.id = this.videoSpanId + '_status';
  60. $('#' + this.videoSpanId)[0].appendChild(statusSpan);
  61. statusSpan = $('#' + this.videoSpanId + '>span.status');
  62. }
  63. // Display status
  64. if (statusMsg && statusMsg.length) {
  65. $('#' + this.videoSpanId + '_status').text(statusMsg);
  66. statusSpan.get(0).setAttribute("style", "display:inline-block;");
  67. }
  68. else {
  69. // Hide
  70. statusSpan.get(0).setAttribute("style", "display:none;");
  71. }
  72. };
  73. /**
  74. * Creates an audio or video stream element.
  75. */
  76. SmallVideo.createStreamElement = function (sid, stream) {
  77. var isVideo = stream.getVideoTracks().length > 0;
  78. var element = isVideo
  79. ? document.createElement('video')
  80. : document.createElement('audio');
  81. var id = (isVideo ? 'remoteVideo_' : 'remoteAudio_')
  82. + sid + '_' + 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. {
  163. var displayName = this.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. this.resourceJid,
  170. isEnable);
  171. if (!this.container) {
  172. return;
  173. }
  174. var video = $('#' + this.videoSpanId + '>' + APP.RTC.getVideoElementName());
  175. if (video && video.length > 0) {
  176. if (isEnable) {
  177. this.showDisplayName(LargeVideo.isLargeVideoOnTop());
  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. }
  187. this.showAvatar();
  188. };
  189. SmallVideo.prototype.updateIconPositions = function () {
  190. var audioMutedSpan = $('#' + this.videoSpanId + '>span.audioMuted');
  191. var connectionIndicator = $('#' + this.videoSpanId + '>div.connectionindicator');
  192. var videoMutedSpan = $('#' + this.videoSpanId + '>span.videoMuted');
  193. if(connectionIndicator.length > 0
  194. && connectionIndicator[0].style.display != "none") {
  195. audioMutedSpan.css({right: "23px"});
  196. videoMutedSpan.css({right: ((audioMutedSpan.length > 0? 23 : 0) + 30) + "px"});
  197. }
  198. else
  199. {
  200. audioMutedSpan.css({right: "0px"});
  201. videoMutedSpan.css({right: (audioMutedSpan.length > 0? 30 : 0) + "px"});
  202. }
  203. }
  204. /**
  205. * Creates the element indicating the moderator(owner) of the conference.
  206. *
  207. * @param parentElement the parent element where the owner indicator will
  208. * be added
  209. */
  210. SmallVideo.prototype.createModeratorIndicatorElement = function () {
  211. // Show moderator indicator
  212. var indicatorSpan = $('#' + this.videoSpanId + ' .focusindicator');
  213. if (!indicatorSpan || indicatorSpan.length === 0) {
  214. indicatorSpan = document.createElement('span');
  215. indicatorSpan.className = 'focusindicator';
  216. this.container.appendChild(indicatorSpan);
  217. indicatorSpan = $('#' + this.videoSpanId + ' .focusindicator');
  218. }
  219. if (indicatorSpan.children().length !== 0)
  220. return;
  221. var moderatorIndicator = document.createElement('i');
  222. moderatorIndicator.className = 'fa fa-star';
  223. indicatorSpan[0].appendChild(moderatorIndicator);
  224. UIUtil.setTooltip(indicatorSpan[0],
  225. "videothumbnail.moderator",
  226. "top");
  227. //translates text in focus indicators
  228. APP.translation.translateElement($('#' + this.videoSpanId + ' .focusindicator'));
  229. }
  230. SmallVideo.prototype.getSrc = function () {
  231. var videoElement = APP.RTC.getVideoElementName();
  232. return APP.RTC.getVideoSrc(
  233. $('#' + this.videoSpanId).find(videoElement).get(0));
  234. },
  235. SmallVideo.prototype.focus = function(isFocused)
  236. {
  237. if(!isFocused) {
  238. this.container.classList.remove("videoContainerFocused");
  239. }
  240. else
  241. {
  242. this.container.classList.add("videoContainerFocused");
  243. }
  244. }
  245. SmallVideo.prototype.hasVideo = function () {
  246. return $("#" + this.videoSpanId).find(
  247. APP.RTC.getVideoElementName()).length !== 0;
  248. }
  249. /**
  250. * Hides or shows the user's avatar
  251. * @param show whether we should show the avatar or not
  252. * video because there is no dominant speaker and no focused speaker
  253. */
  254. SmallVideo.prototype.showAvatar = function (show) {
  255. if (!this.hasAvatar)
  256. return;
  257. var videoElem = APP.RTC.getVideoElementName();
  258. var video = $('#' + this.videoSpanId).find(videoElem);
  259. var avatar = $('#avatar_' + this.resourceJid);
  260. if (show === undefined || show === null) {
  261. if (!this.isLocal &&
  262. !this.VideoLayout.isInLastN(this.resourceJid)) {
  263. show = true;
  264. }
  265. else
  266. {
  267. show = APP.RTC.isVideoMuted(this.peerJid);
  268. }
  269. }
  270. if (LargeVideo.showAvatar(this.resourceJid, show))
  271. {
  272. setVisibility(avatar, false);
  273. setVisibility(video, false);
  274. } else {
  275. if (video && video.length > 0) {
  276. setVisibility(video, !show);
  277. }
  278. setVisibility(avatar, show);
  279. }
  280. };
  281. SmallVideo.prototype.avatarChanged = function (thumbUrl) {
  282. var thumbnail = $('#' + this.videoSpanId);
  283. var avatar = $('#avatar_' + this.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_' + this.resourceJid;
  292. avatar.className = 'userAvatar';
  293. avatar.src = thumbUrl;
  294. thumbnail.append(avatar);
  295. }
  296. }
  297. }
  298. module.exports = SmallVideo;