Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

RemoteVideo.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /* global $, APP, interfaceConfig */
  2. import ConnectionIndicator from './ConnectionIndicator';
  3. import SmallVideo from "./SmallVideo";
  4. import AudioLevels from "../audio_levels/AudioLevels";
  5. import UIUtils from "../util/UIUtil";
  6. import UIEvents from '../../../service/UI/UIEvents';
  7. var RTCBrowserType = require("../../RTC/RTCBrowserType");
  8. function RemoteVideo(id, VideoLayout, emitter) {
  9. this.id = id;
  10. this.emitter = emitter;
  11. this.videoSpanId = `participant_${id}`;
  12. this.VideoLayout = VideoLayout;
  13. this.addRemoteVideoContainer();
  14. this.connectionIndicator = new ConnectionIndicator(this, id);
  15. this.setDisplayName();
  16. var nickfield = document.createElement('span');
  17. nickfield.className = "nick";
  18. nickfield.appendChild(document.createTextNode(id));
  19. this.container.appendChild(nickfield);
  20. this.bindHoverHandler();
  21. this.flipX = false;
  22. this.isLocal = false;
  23. }
  24. RemoteVideo.prototype = Object.create(SmallVideo.prototype);
  25. RemoteVideo.prototype.constructor = RemoteVideo;
  26. RemoteVideo.prototype.addRemoteVideoContainer = function() {
  27. this.container = RemoteVideo.createContainer(this.videoSpanId);
  28. if (APP.conference.isModerator) {
  29. this.addRemoteVideoMenu();
  30. }
  31. AudioLevels.updateAudioLevelCanvas(this.id, this.VideoLayout);
  32. return this.container;
  33. };
  34. /**
  35. * Adds the remote video menu element for the given <tt>id</tt> in the
  36. * given <tt>parentElement</tt>.
  37. *
  38. * @param id the id indicating the video for which we're adding a menu.
  39. * @param parentElement the parent element where this menu will be added
  40. */
  41. if (!interfaceConfig.filmStripOnly) {
  42. RemoteVideo.prototype.addRemoteVideoMenu = function () {
  43. var spanElement = document.createElement('span');
  44. spanElement.className = 'remotevideomenu';
  45. this.container.appendChild(spanElement);
  46. var menuElement = document.createElement('i');
  47. menuElement.className = 'fa fa-angle-down';
  48. menuElement.title = 'Remote user controls';
  49. spanElement.appendChild(menuElement);
  50. var popupmenuElement = document.createElement('ul');
  51. popupmenuElement.className = 'popupmenu';
  52. popupmenuElement.id = `remote_popupmenu_${this.id}`;
  53. spanElement.appendChild(popupmenuElement);
  54. var muteMenuItem = document.createElement('li');
  55. var muteLinkItem = document.createElement('a');
  56. var mutedIndicator = "<i style='float:left;' " +
  57. "class='icon-mic-disabled'></i>";
  58. if (!this.isMuted) {
  59. muteLinkItem.innerHTML = mutedIndicator +
  60. " <div style='width: 90px;margin-left: 20px;' " +
  61. "data-i18n='videothumbnail.domute'></div>";
  62. muteLinkItem.className = 'mutelink';
  63. }
  64. else {
  65. muteLinkItem.innerHTML = mutedIndicator +
  66. " <div style='width: 90px;margin-left: 20px;' " +
  67. "data-i18n='videothumbnail.muted'></div>";
  68. muteLinkItem.className = 'mutelink disabled';
  69. }
  70. var self = this;
  71. muteLinkItem.onclick = function(){
  72. if ($(this).attr('disabled')) {
  73. event.preventDefault();
  74. }
  75. var isMute = !!self.isMuted;
  76. self.emitter.emit(UIEvents.AUDIO_MUTED, !isMute);
  77. popupmenuElement.setAttribute('style', 'display:none;');
  78. if (isMute) {
  79. this.innerHTML = mutedIndicator +
  80. " <div style='width: 90px;margin-left: 20px;' " +
  81. "data-i18n='videothumbnail.muted'></div>";
  82. this.className = 'mutelink disabled';
  83. }
  84. else {
  85. this.innerHTML = mutedIndicator +
  86. " <div style='width: 90px;margin-left: 20px;' " +
  87. "data-i18n='videothumbnail.domute'></div>";
  88. this.className = 'mutelink';
  89. }
  90. };
  91. muteMenuItem.appendChild(muteLinkItem);
  92. popupmenuElement.appendChild(muteMenuItem);
  93. var ejectIndicator = "<i style='float:left;' class='fa fa-eject'></i>";
  94. var ejectMenuItem = document.createElement('li');
  95. var ejectLinkItem = document.createElement('a');
  96. var ejectText = "<div style='width: 90px;margin-left: 20px;' " +
  97. "data-i18n='videothumbnail.kick'>&nbsp;</div>";
  98. ejectLinkItem.innerHTML = ejectIndicator + ' ' + ejectText;
  99. ejectLinkItem.onclick = function(){
  100. self.emitter.emit(UIEvents.USER_KICKED, self.id);
  101. popupmenuElement.setAttribute('style', 'display:none;');
  102. };
  103. ejectMenuItem.appendChild(ejectLinkItem);
  104. popupmenuElement.appendChild(ejectMenuItem);
  105. var paddingSpan = document.createElement('span');
  106. paddingSpan.className = 'popupmenuPadding';
  107. popupmenuElement.appendChild(paddingSpan);
  108. APP.translation.translateElement(
  109. $("#" + popupmenuElement.id + " > li > a > div"));
  110. };
  111. } else {
  112. RemoteVideo.prototype.addRemoteVideoMenu = function() {};
  113. }
  114. /**
  115. * Removes the remote stream element corresponding to the given stream and
  116. * parent container.
  117. *
  118. * @param stream the stream
  119. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  120. */
  121. RemoteVideo.prototype.removeRemoteStreamElement =
  122. function (stream, isVideo, id) {
  123. if (!this.container)
  124. return false;
  125. var select = null;
  126. if (isVideo) {
  127. select = $('#' + id);
  128. }
  129. else
  130. select = $('#' + this.videoSpanId + '>audio');
  131. select.remove();
  132. console.info((isVideo ? "Video" : "Audio") +
  133. " removed " + this.id, select);
  134. if (isVideo)
  135. this.VideoLayout.updateRemovedVideo(this.id);
  136. };
  137. /**
  138. * Removes RemoteVideo from the page.
  139. */
  140. RemoteVideo.prototype.remove = function () {
  141. console.log("Remove thumbnail", this.id);
  142. this.removeConnectionIndicator();
  143. // Make sure that the large video is updated if are removing its
  144. // corresponding small video.
  145. this.VideoLayout.updateRemovedVideo(this.id);
  146. // Remove whole container
  147. if (this.container.parentNode) {
  148. this.container.parentNode.removeChild(this.container);
  149. }
  150. };
  151. RemoteVideo.prototype.waitForPlayback = function (sel, stream) {
  152. var webRtcStream = stream.getOriginalStream();
  153. var isVideo = stream.isVideoTrack();
  154. if (!isVideo || webRtcStream.id === 'mixedmslabel') {
  155. return;
  156. }
  157. var self = this;
  158. // Register 'onplaying' listener to trigger 'videoactive' on VideoLayout
  159. // when video playback starts
  160. var onPlayingHandler = function () {
  161. // FIXME: why do i have to do this for FF?
  162. if (RTCBrowserType.isFirefox()) {
  163. APP.RTC.attachMediaStream(sel, webRtcStream);
  164. }
  165. if (RTCBrowserType.isTemasysPluginUsed()) {
  166. sel = self.selectVideoElement();
  167. }
  168. self.VideoLayout.videoactive(sel, self.id);
  169. sel[0].onplaying = null;
  170. if (RTCBrowserType.isTemasysPluginUsed()) {
  171. // 'currentTime' is used to check if the video has started
  172. // and the value is not set by the plugin, so we do it
  173. sel[0].currentTime = 1;
  174. }
  175. };
  176. sel[0].onplaying = onPlayingHandler;
  177. };
  178. RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
  179. if (!this.container) {
  180. return;
  181. }
  182. this.stream = stream;
  183. let isVideo = stream.isVideoTrack();
  184. let streamElement = SmallVideo.createStreamElement(stream);
  185. let newElementId = streamElement.id;
  186. // Put new stream element always in front
  187. UIUtils.prependChild(this.container, streamElement);
  188. let sel = $(`#${newElementId}`);
  189. sel.hide();
  190. // If the container is currently visible we attach the stream.
  191. if (!isVideo || (this.container.offsetParent !== null && isVideo)) {
  192. this.waitForPlayback(sel, stream);
  193. stream.attach(sel);
  194. }
  195. // Add click handler.
  196. let onClickHandler = (event) => {
  197. this.VideoLayout.handleVideoThumbClicked(false, this.id);
  198. // On IE we need to populate this handler on video <object>
  199. // and it does not give event instance as an argument,
  200. // so we check here for methods.
  201. if (event.stopPropagation && event.preventDefault) {
  202. event.stopPropagation();
  203. event.preventDefault();
  204. }
  205. return false;
  206. };
  207. this.container.onclick = onClickHandler;
  208. // reselect
  209. if (RTCBrowserType.isTemasysPluginUsed()) {
  210. sel = $(`#${newElementId}`);
  211. }
  212. sel.click(onClickHandler);
  213. },
  214. /**
  215. * Show/hide peer container for the given id.
  216. */
  217. RemoteVideo.prototype.showPeerContainer = function (state) {
  218. if (!this.container)
  219. return;
  220. var isHide = state === 'hide';
  221. var resizeThumbnails = false;
  222. if (!isHide) {
  223. if (!$(this.container).is(':visible')) {
  224. resizeThumbnails = true;
  225. $(this.container).show();
  226. }
  227. // Call showAvatar with undefined, so that we'll figure out if avatar
  228. // should be displayed based on video muted status and whether or not
  229. // it's in the lastN set
  230. this.showAvatar(undefined);
  231. }
  232. else if ($(this.container).is(':visible') && isHide)
  233. {
  234. resizeThumbnails = true;
  235. $(this.container).hide();
  236. if(this.connectionIndicator)
  237. this.connectionIndicator.hide();
  238. }
  239. if (resizeThumbnails) {
  240. this.VideoLayout.resizeThumbnails();
  241. }
  242. // We want to be able to pin a participant from the contact list, even
  243. // if he's not in the lastN set!
  244. // ContactList.setClickable(id, !isHide);
  245. };
  246. RemoteVideo.prototype.removeConnectionIndicator = function () {
  247. if (this.connectionIndicator)
  248. this.connectionIndicator.remove();
  249. };
  250. RemoteVideo.prototype.hideConnectionIndicator = function () {
  251. if (this.connectionIndicator)
  252. this.connectionIndicator.hide();
  253. };
  254. /**
  255. * Updates the remote video menu.
  256. *
  257. * @param id the id indicating the video for which we're adding a menu.
  258. * @param isMuted indicates the current mute state
  259. */
  260. RemoteVideo.prototype.updateRemoteVideoMenu = function (isMuted) {
  261. var muteMenuItem = $(`#remote_popupmenu_${this.id}>li>a.mutelink`);
  262. var mutedIndicator = "<i class='icon-mic-disabled'></i>";
  263. if (muteMenuItem.length) {
  264. var muteLink = muteMenuItem.get(0);
  265. if (isMuted) {
  266. muteLink.innerHTML = mutedIndicator + ' Muted';
  267. muteLink.className = 'mutelink disabled';
  268. }
  269. else {
  270. muteLink.innerHTML = mutedIndicator + ' Mute';
  271. muteLink.className = 'mutelink';
  272. }
  273. }
  274. };
  275. /**
  276. * Updates the Indicator for dominant speaker.
  277. *
  278. * @param isSpeaker indicates the current indicator state
  279. */
  280. RemoteVideo.prototype.updateDominantSpeakerIndicator = function (isSpeaker) {
  281. if (!this.container) {
  282. console.warn( "Unable to set dominant speaker indicator - "
  283. + this.videoSpanId + " does not exist");
  284. return;
  285. }
  286. var indicatorSpan
  287. = $('#' + this.videoSpanId + '>span.dominantspeakerindicator');
  288. // If we do not have an indicator for this video.
  289. if (indicatorSpan.length <= 0) {
  290. indicatorSpan = document.createElement('span');
  291. indicatorSpan.innerHTML
  292. = "<i id='speakerindicatoricon' class='fa fa-bullhorn'></i>";
  293. indicatorSpan.className = 'dominantspeakerindicator';
  294. $('#' + this.videoSpanId)[0].appendChild(indicatorSpan);
  295. // adds a tooltip
  296. UIUtils.setTooltip(indicatorSpan, "speaker", "left");
  297. APP.translation.translateElement($(indicatorSpan));
  298. }
  299. $(indicatorSpan).css("visibility", isSpeaker ? "visible" : "hidden");
  300. };
  301. /**
  302. * Sets the display name for the given video span id.
  303. */
  304. RemoteVideo.prototype.setDisplayName = function(displayName, key) {
  305. if (!this.container) {
  306. console.warn( "Unable to set displayName - " + this.videoSpanId +
  307. " does not exist");
  308. return;
  309. }
  310. var nameSpan = $('#' + this.videoSpanId + '>span.displayname');
  311. // If we already have a display name for this video.
  312. if (nameSpan.length > 0) {
  313. if (displayName && displayName.length > 0) {
  314. $('#' + this.videoSpanId + '_name').html(displayName);
  315. }
  316. else if (key && key.length > 0) {
  317. var nameHtml = APP.translation.generateTranslationHTML(key);
  318. $('#' + this.videoSpanId + '_name').html(nameHtml);
  319. }
  320. else
  321. $('#' + this.videoSpanId + '_name').text(
  322. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  323. } else {
  324. nameSpan = document.createElement('span');
  325. nameSpan.className = 'displayname';
  326. $('#' + this.videoSpanId)[0].appendChild(nameSpan);
  327. if (displayName && displayName.length > 0) {
  328. nameSpan.innerText = displayName;
  329. }
  330. else
  331. nameSpan.innerText = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  332. nameSpan.id = this.videoSpanId + '_name';
  333. }
  334. };
  335. /**
  336. * Removes remote video menu element from video element identified by
  337. * given <tt>videoElementId</tt>.
  338. *
  339. * @param videoElementId the id of local or remote video element.
  340. */
  341. RemoteVideo.prototype.removeRemoteVideoMenu = function() {
  342. var menuSpan = $('#' + this.videoSpanId + '>span.remotevideomenu');
  343. if (menuSpan.length) {
  344. menuSpan.remove();
  345. }
  346. };
  347. RemoteVideo.createContainer = function (spanId) {
  348. var container = document.createElement('span');
  349. container.id = spanId;
  350. container.className = 'videocontainer';
  351. var remotes = document.getElementById('remoteVideos');
  352. return remotes.appendChild(container);
  353. };
  354. export default RemoteVideo;