選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

RemoteVideo.js 14KB

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