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

VideoLayout.js 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. /* global config, APP, $, interfaceConfig, JitsiMeetJS */
  2. /* jshint -W101 */
  3. import AudioLevels from "../audio_levels/AudioLevels";
  4. import Avatar from "../avatar/Avatar";
  5. import BottomToolbar from "../toolbars/BottomToolbar";
  6. import UIEvents from "../../../service/UI/UIEvents";
  7. import UIUtil from "../util/UIUtil";
  8. import RemoteVideo from "./RemoteVideo";
  9. import LargeVideoManager, {VideoContainerType} from "./LargeVideo";
  10. import {PreziContainerType} from '../prezi/Prezi';
  11. import LocalVideo from "./LocalVideo";
  12. const RTCUIUtil = JitsiMeetJS.util.RTCUIHelper;
  13. var remoteVideos = {};
  14. var remoteVideoTypes = {};
  15. var localVideoThumbnail = null;
  16. var currentDominantSpeaker = null;
  17. var lastNCount = config.channelLastN;
  18. var localLastNCount = config.channelLastN;
  19. var localLastNSet = [];
  20. var lastNEndpointsCache = [];
  21. var lastNPickupId = null;
  22. var eventEmitter = null;
  23. /**
  24. * Currently focused video jid
  25. * @type {String}
  26. */
  27. var focusedVideoResourceJid = null;
  28. const thumbAspectRatio = 16.0 / 9.0;
  29. /**
  30. * On contact list item clicked.
  31. */
  32. function onContactClicked (id) {
  33. if (APP.conference.isLocalId(id)) {
  34. $("#localVideoContainer").click();
  35. return;
  36. }
  37. let remoteVideo = remoteVideos[id];
  38. if (remoteVideo && remoteVideo.hasVideo()) {
  39. // It is not always the case that a videoThumb exists (if there is
  40. // no actual video).
  41. if (remoteVideo.hasVideoStarted()) {
  42. // We have a video src, great! Let's update the large video
  43. // now.
  44. VideoLayout.handleVideoThumbClicked(false, id);
  45. } else {
  46. // If we don't have a video src for jid, there's absolutely
  47. // no point in calling handleVideoThumbClicked; Quite
  48. // simply, it won't work because it needs an src to attach
  49. // to the large video.
  50. //
  51. // Instead, we trigger the pinned endpoint changed event to
  52. // let the bridge adjust its lastN set for myjid and store
  53. // the pinned user in the lastNPickupId variable to be
  54. // picked up later by the lastN changed event handler.
  55. lastNPickupId = id;
  56. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, id);
  57. }
  58. }
  59. }
  60. /**
  61. * Returns the corresponding resource id to the given peer container
  62. * DOM element.
  63. *
  64. * @return the corresponding resource id to the given peer container
  65. * DOM element
  66. */
  67. function getPeerContainerResourceId (containerElement) {
  68. if (localVideoThumbnail.container === containerElement) {
  69. return localVideoThumbnail.id;
  70. }
  71. let i = containerElement.id.indexOf('participant_');
  72. if (i >= 0) {
  73. return containerElement.id.substring(i + 12);
  74. }
  75. }
  76. let largeVideo;
  77. var VideoLayout = {
  78. init (emitter) {
  79. eventEmitter = emitter;
  80. localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
  81. emitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
  82. },
  83. initLargeVideo (isSideBarVisible) {
  84. largeVideo = new LargeVideoManager();
  85. largeVideo.updateContainerSize(isSideBarVisible);
  86. AudioLevels.init();
  87. },
  88. setAudioLevel(id, lvl) {
  89. if (!largeVideo) {
  90. return;
  91. }
  92. AudioLevels.updateAudioLevel(
  93. id, lvl, largeVideo.id
  94. );
  95. },
  96. isInLastN (resource) {
  97. return lastNCount < 0 || // lastN is disabled
  98. // lastNEndpoints cache not built yet
  99. (lastNCount > 0 && !lastNEndpointsCache.length) ||
  100. (lastNEndpointsCache &&
  101. lastNEndpointsCache.indexOf(resource) !== -1);
  102. },
  103. changeLocalAudio (stream) {
  104. let localAudio = document.getElementById('localAudio');
  105. localAudio = stream.attach(localAudio);
  106. // Now when Temasys plugin is converting also <audio> elements to
  107. // plugin's <object>s, in current layout it will capture click events
  108. // before it reaches the local video object. We hide it here in order
  109. // to prevent that.
  110. //if (RTCBrowserType.isIExplorer()) {
  111. // The issue is not present on Safari. Also if we hide it in Safari
  112. // then the local audio track will have 'enabled' flag set to false
  113. // which will result in audio mute issues
  114. // $(localAudio).hide();
  115. localAudio.width = 1;
  116. localAudio.height = 1;
  117. //}
  118. },
  119. changeLocalVideo (stream) {
  120. // Set default display name.
  121. localVideoThumbnail.setDisplayName();
  122. localVideoThumbnail.createConnectionIndicator();
  123. let localId = APP.conference.localId;
  124. this.onVideoTypeChanged(localId, stream.videoType);
  125. let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
  126. AudioLevels.updateAudioLevelCanvas(
  127. null, thumbWidth, thumbHeight);
  128. if (!stream.isMuted()) {
  129. localVideoThumbnail.changeVideo(stream);
  130. }
  131. /* force update if we're currently being displayed */
  132. if (this.isCurrentlyOnLarge(localId)) {
  133. this.updateLargeVideo(localId, true);
  134. }
  135. },
  136. /**
  137. * Get's the localID of the conference and set it to the local video
  138. * (small one). This needs to be called as early as possible, when muc is
  139. * actually joined. Otherwise events can come with information like email
  140. * and setting them assume the id is already set.
  141. */
  142. mucJoined () {
  143. if (largeVideo && !largeVideo.id) {
  144. this.updateLargeVideo(APP.conference.localId, true);
  145. }
  146. },
  147. /**
  148. * Adds or removes icons for not available camera and microphone.
  149. * @param resourceJid the jid of user
  150. * @param devices available devices
  151. */
  152. setDeviceAvailabilityIcons (id, devices) {
  153. if (APP.conference.isLocalId(id)) {
  154. localVideoThumbnail.setDeviceAvailabilityIcons(devices);
  155. return;
  156. }
  157. let video = remoteVideos[id];
  158. if (!video) {
  159. return;
  160. }
  161. video.setDeviceAvailabilityIcons(devices);
  162. },
  163. /**
  164. * Checks if removed video is currently displayed and tries to display
  165. * another one instead.
  166. */
  167. updateRemovedVideo (id) {
  168. if (!this.isCurrentlyOnLarge(id)) {
  169. return;
  170. }
  171. let newId;
  172. // We'll show user's avatar if he is the dominant speaker or if
  173. // his video thumbnail is pinned
  174. if (remoteVideos[id] && (id === focusedVideoResourceJid
  175. || id === currentDominantSpeaker)) {
  176. newId = id;
  177. } else {
  178. // Otherwise select last visible video
  179. newId = this.electLastVisibleVideo();
  180. }
  181. this.updateLargeVideo(newId);
  182. },
  183. electLastVisibleVideo () {
  184. // pick the last visible video in the row
  185. // if nobody else is left, this picks the local video
  186. let thumbs = BottomToolbar.getThumbs(true).filter('[id!="mixedstream"]');
  187. let lastVisible = thumbs.filter(':visible:last');
  188. if (lastVisible.length) {
  189. let id = getPeerContainerResourceId(lastVisible[0]);
  190. if (remoteVideos[id]) {
  191. console.info("electLastVisibleVideo: " + id);
  192. return id;
  193. }
  194. // The RemoteVideo was removed (but the DOM elements may still
  195. // exist).
  196. }
  197. console.info("Last visible video no longer exists");
  198. thumbs = BottomToolbar.getThumbs();
  199. if (thumbs.length) {
  200. let id = getPeerContainerResourceId(thumbs[0]);
  201. if (remoteVideos[id]) {
  202. console.info("electLastVisibleVideo: " + id);
  203. return id;
  204. }
  205. // The RemoteVideo was removed (but the DOM elements may
  206. // still exist).
  207. }
  208. // Go with local video
  209. console.info("Fallback to local video...");
  210. let id = APP.conference.localId;
  211. console.info("electLastVisibleVideo: " + id);
  212. return id;
  213. },
  214. onRemoteStreamAdded (stream) {
  215. let id = stream.getParticipantId();
  216. remoteVideos[id].addRemoteStreamElement(stream);
  217. // if track is muted make sure we reflect that
  218. if(stream.isMuted())
  219. {
  220. if(stream.getType() === "audio")
  221. this.onAudioMute(stream.getParticipantId(), true);
  222. else
  223. this.onVideoMute(stream.getParticipantId(), true);
  224. }
  225. },
  226. onRemoteStreamRemoved (stream) {
  227. let id = stream.getParticipantId();
  228. remoteVideos[id].removeRemoteStreamElement(stream);
  229. },
  230. /**
  231. * Return the type of the remote video.
  232. * @param id the id for the remote video
  233. * @returns the video type video or screen.
  234. */
  235. getRemoteVideoType (id) {
  236. return remoteVideoTypes[id];
  237. },
  238. handleVideoThumbClicked (noPinnedEndpointChangedEvent,
  239. resourceJid) {
  240. if(focusedVideoResourceJid) {
  241. var oldSmallVideo
  242. = VideoLayout.getSmallVideo(focusedVideoResourceJid);
  243. if (oldSmallVideo && !interfaceConfig.filmStripOnly)
  244. oldSmallVideo.focus(false);
  245. }
  246. var smallVideo = VideoLayout.getSmallVideo(resourceJid);
  247. // Unlock current focused.
  248. if (focusedVideoResourceJid === resourceJid)
  249. {
  250. focusedVideoResourceJid = null;
  251. // Enable the currently set dominant speaker.
  252. if (currentDominantSpeaker) {
  253. if(smallVideo && smallVideo.hasVideo()) {
  254. this.updateLargeVideo(currentDominantSpeaker);
  255. }
  256. }
  257. if (!noPinnedEndpointChangedEvent) {
  258. eventEmitter.emit(UIEvents.PINNED_ENDPOINT);
  259. }
  260. return;
  261. }
  262. // Lock new video
  263. focusedVideoResourceJid = resourceJid;
  264. // Update focused/pinned interface.
  265. if (resourceJid) {
  266. if (smallVideo && !interfaceConfig.filmStripOnly)
  267. smallVideo.focus(true);
  268. if (!noPinnedEndpointChangedEvent) {
  269. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, resourceJid);
  270. }
  271. }
  272. this.updateLargeVideo(resourceJid);
  273. },
  274. /**
  275. * Checks if container for participant identified by given id exists
  276. * in the document and creates it eventually.
  277. *
  278. * @return Returns <tt>true</tt> if the peer container exists,
  279. * <tt>false</tt> - otherwise
  280. */
  281. addParticipantContainer (id) {
  282. let remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter);
  283. remoteVideos[id] = remoteVideo;
  284. let videoType = remoteVideoTypes[id];
  285. if (videoType) {
  286. remoteVideo.setVideoType(videoType);
  287. }
  288. // In case this is not currently in the last n we don't show it.
  289. if (localLastNCount && localLastNCount > 0 &&
  290. BottomToolbar.getThumbs().length >= localLastNCount + 2) {
  291. remoteVideo.showPeerContainer('hide');
  292. } else {
  293. VideoLayout.resizeThumbnails(false, true);
  294. }
  295. },
  296. videoactive (videoelem, resourceJid) {
  297. console.info(resourceJid + " video is now active", videoelem);
  298. $(videoelem).show();
  299. VideoLayout.resizeThumbnails();
  300. // Update the large video to the last added video only if there's no
  301. // current dominant, focused speaker or prezi playing or update it to
  302. // the current dominant speaker.
  303. if ((!focusedVideoResourceJid &&
  304. !currentDominantSpeaker &&
  305. !this.isLargeContainerTypeVisible(PreziContainerType)) ||
  306. focusedVideoResourceJid === resourceJid ||
  307. (resourceJid &&
  308. currentDominantSpeaker === resourceJid)) {
  309. this.updateLargeVideo(resourceJid, true);
  310. }
  311. },
  312. /**
  313. * Shows the presence status message for the given video.
  314. */
  315. setPresenceStatus (id, statusMsg) {
  316. remoteVideos[id].setPresenceStatus(statusMsg);
  317. },
  318. /**
  319. * Shows a visual indicator for the moderator of the conference.
  320. * On local or remote participants.
  321. */
  322. showModeratorIndicator () {
  323. let isModerator = APP.conference.isModerator;
  324. if (isModerator) {
  325. localVideoThumbnail.createModeratorIndicatorElement();
  326. }
  327. APP.conference.listMembers().forEach(function (member) {
  328. let id = member.getId();
  329. if (member.isModerator()) {
  330. remoteVideos[id].removeRemoteVideoMenu();
  331. remoteVideos[id].createModeratorIndicatorElement();
  332. } else if (isModerator) {
  333. // We are moderator, but user is not - add menu
  334. if ($(`#remote_popupmenu_${id}`).length <= 0) {
  335. remoteVideos[id].addRemoteVideoMenu();
  336. }
  337. }
  338. });
  339. },
  340. /*
  341. * Shows or hides the audio muted indicator over the local thumbnail video.
  342. * @param {boolean} isMuted
  343. */
  344. showLocalAudioIndicator (isMuted) {
  345. localVideoThumbnail.showAudioIndicator(isMuted);
  346. },
  347. /**
  348. * Resizes the large video container.
  349. */
  350. resizeLargeVideoContainer (isSideBarVisible, forceUpdate) {
  351. let animate = false;
  352. if (largeVideo) {
  353. largeVideo.updateContainerSize(isSideBarVisible);
  354. largeVideo.resize(animate);
  355. }
  356. this.resizeVideoSpace(animate, isSideBarVisible);
  357. this.resizeThumbnails(false, forceUpdate);
  358. },
  359. /**
  360. * Resizes thumbnails.
  361. */
  362. resizeThumbnails (animate = false, forceUpdate = false) {
  363. let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
  364. $('.userAvatar').css('left', (thumbWidth - thumbHeight) / 2);
  365. BottomToolbar.resizeThumbnails(thumbWidth, thumbHeight,
  366. animate, forceUpdate)
  367. .then(function () {
  368. BottomToolbar.resizeToolbar(thumbWidth, thumbHeight);
  369. AudioLevels.updateCanvasSize(thumbWidth, thumbHeight);
  370. });
  371. },
  372. /**
  373. * Calculates the thumbnail size.
  374. *
  375. */
  376. calculateThumbnailSize () {
  377. let videoSpaceWidth = BottomToolbar.getFilmStripWidth();
  378. // Calculate the available height, which is the inner window height
  379. // minus 39px for the header minus 2px for the delimiter lines on the
  380. // top and bottom of the large video, minus the 36px space inside the
  381. // remoteVideos container used for highlighting shadow.
  382. let availableHeight = 100;
  383. let numvids = BottomToolbar.getThumbs().length;
  384. if (localLastNCount && localLastNCount > 0) {
  385. numvids = Math.min(localLastNCount + 1, numvids);
  386. }
  387. // Remove the 3px borders arround videos and border around the remote
  388. // videos area and the 4 pixels between the local video and the others
  389. //TODO: Find out where the 4 pixels come from and remove them
  390. let availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70 - 4;
  391. let availableWidth = availableWinWidth / numvids;
  392. let maxHeight = Math.min(160, availableHeight);
  393. availableHeight
  394. = Math.min( maxHeight,
  395. availableWidth / thumbAspectRatio,
  396. window.innerHeight - 18);
  397. if (availableHeight < availableWidth / thumbAspectRatio) {
  398. availableWidth = Math.floor(availableHeight * thumbAspectRatio);
  399. }
  400. return {
  401. thumbWidth: availableWidth,
  402. thumbHeight: availableHeight
  403. };
  404. },
  405. /**
  406. * On audio muted event.
  407. */
  408. onAudioMute (id, isMuted) {
  409. if (APP.conference.isLocalId(id)) {
  410. localVideoThumbnail.showAudioIndicator(isMuted);
  411. } else {
  412. remoteVideos[id].showAudioIndicator(isMuted);
  413. if (APP.conference.isModerator) {
  414. remoteVideos[id].updateRemoteVideoMenu(isMuted);
  415. }
  416. }
  417. },
  418. /**
  419. * On video muted event.
  420. */
  421. onVideoMute (id, value) {
  422. if (APP.conference.isLocalId(id)) {
  423. localVideoThumbnail.setMutedView(value);
  424. } else {
  425. var remoteVideo = remoteVideos[id];
  426. remoteVideo.setMutedView(value);
  427. }
  428. if (this.isCurrentlyOnLarge(id)) {
  429. // large video will show avatar instead of muted stream
  430. this.updateLargeVideo(id, true);
  431. }
  432. },
  433. /**
  434. * Display name changed.
  435. */
  436. onDisplayNameChanged (id, displayName, status) {
  437. if (id === 'localVideoContainer' ||
  438. APP.conference.isLocalId(id)) {
  439. localVideoThumbnail.setDisplayName(displayName);
  440. } else {
  441. remoteVideos[id].setDisplayName(displayName, status);
  442. }
  443. },
  444. /**
  445. * On dominant speaker changed event.
  446. */
  447. onDominantSpeakerChanged (id) {
  448. if (id === currentDominantSpeaker) {
  449. return;
  450. }
  451. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  452. // We ignore local user events, but just unmark remote user as dominant
  453. // while we are talking
  454. if (APP.conference.isLocalId(id)) {
  455. if(oldSpeakerRemoteVideo)
  456. {
  457. oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
  458. localVideoThumbnail.updateDominantSpeakerIndicator(true);
  459. currentDominantSpeaker = null;
  460. }
  461. return;
  462. }
  463. let remoteVideo = remoteVideos[id];
  464. if (!remoteVideo) {
  465. return;
  466. }
  467. // Update the current dominant speaker.
  468. remoteVideo.updateDominantSpeakerIndicator(true);
  469. localVideoThumbnail.updateDominantSpeakerIndicator(false);
  470. // let's remove the indications from the remote video if any
  471. if (oldSpeakerRemoteVideo) {
  472. oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
  473. }
  474. currentDominantSpeaker = id;
  475. // Local video will not have container found, but that's ok
  476. // since we don't want to switch to local video.
  477. // Update the large video if the video source is already available,
  478. // otherwise wait for the "videoactive.jingle" event.
  479. if (!focusedVideoResourceJid && remoteVideo.hasVideoStarted()) {
  480. this.updateLargeVideo(id);
  481. }
  482. },
  483. /**
  484. * On last N change event.
  485. *
  486. * @param lastNEndpoints the list of last N endpoints
  487. * @param endpointsEnteringLastN the list currently entering last N
  488. * endpoints
  489. */
  490. onLastNEndpointsChanged (lastNEndpoints, endpointsEnteringLastN) {
  491. if (lastNCount !== lastNEndpoints.length)
  492. lastNCount = lastNEndpoints.length;
  493. lastNEndpointsCache = lastNEndpoints;
  494. // Say A, B, C, D, E, and F are in a conference and LastN = 3.
  495. //
  496. // If LastN drops to, say, 2, because of adaptivity, then E should see
  497. // thumbnails for A, B and C. A and B are in E's server side LastN set,
  498. // so E sees them. C is only in E's local LastN set.
  499. //
  500. // If F starts talking and LastN = 3, then E should see thumbnails for
  501. // F, A, B. B gets "ejected" from E's server side LastN set, but it
  502. // enters E's local LastN ejecting C.
  503. // Increase the local LastN set size, if necessary.
  504. if (lastNCount > localLastNCount) {
  505. localLastNCount = lastNCount;
  506. }
  507. // Update the local LastN set preserving the order in which the
  508. // endpoints appeared in the LastN/local LastN set.
  509. var nextLocalLastNSet = lastNEndpoints.slice(0);
  510. for (var i = 0; i < localLastNSet.length; i++) {
  511. if (nextLocalLastNSet.length >= localLastNCount) {
  512. break;
  513. }
  514. var resourceJid = localLastNSet[i];
  515. if (nextLocalLastNSet.indexOf(resourceJid) === -1) {
  516. nextLocalLastNSet.push(resourceJid);
  517. }
  518. }
  519. localLastNSet = nextLocalLastNSet;
  520. var updateLargeVideo = false;
  521. // Handle LastN/local LastN changes.
  522. BottomToolbar.getThumbs().each(( index, element ) => {
  523. var resourceJid = getPeerContainerResourceId(element);
  524. var smallVideo = remoteVideos[resourceJid];
  525. // We do not want to process any logic for our own(local) video
  526. // because the local participant is never in the lastN set.
  527. // The code of this function might detect that the local participant
  528. // has been dropped out of the lastN set and will update the large
  529. // video
  530. // Detected from avatar tests, where lastN event override
  531. // local video pinning
  532. if(APP.conference.isLocalId(resourceJid))
  533. return;
  534. var isReceived = true;
  535. if (resourceJid &&
  536. lastNEndpoints.indexOf(resourceJid) < 0 &&
  537. localLastNSet.indexOf(resourceJid) < 0) {
  538. console.log("Remove from last N", resourceJid);
  539. if (smallVideo)
  540. smallVideo.showPeerContainer('hide');
  541. else if (!APP.conference.isLocalId(resourceJid))
  542. console.error("No remote video for: " + resourceJid);
  543. isReceived = false;
  544. } else if (resourceJid &&
  545. smallVideo.isVisible() &&
  546. lastNEndpoints.indexOf(resourceJid) < 0 &&
  547. localLastNSet.indexOf(resourceJid) >= 0) {
  548. if (smallVideo)
  549. smallVideo.showPeerContainer('avatar');
  550. else if (!APP.conference.isLocalId(resourceJid))
  551. console.error("No remote video for: " + resourceJid);
  552. isReceived = false;
  553. }
  554. if (!isReceived) {
  555. // resourceJid has dropped out of the server side lastN set, so
  556. // it is no longer being received. If resourceJid was being
  557. // displayed in the large video we have to switch to another
  558. // user.
  559. if (!updateLargeVideo &&
  560. this.isCurrentlyOnLarge(resourceJid)) {
  561. updateLargeVideo = true;
  562. }
  563. }
  564. });
  565. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  566. endpointsEnteringLastN = lastNEndpoints;
  567. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  568. endpointsEnteringLastN.forEach(function (resourceJid) {
  569. var remoteVideo = remoteVideos[resourceJid];
  570. remoteVideo.showPeerContainer('show');
  571. if (!remoteVideo.isVisible()) {
  572. console.log("Add to last N", resourceJid);
  573. remoteVideo.addRemoteStreamElement(remoteVideo.videoStream);
  574. if (lastNPickupId == resourceJid) {
  575. // Clean up the lastN pickup id.
  576. lastNPickupId = null;
  577. // Don't fire the events again, they've already
  578. // been fired in the contact list click handler.
  579. VideoLayout.handleVideoThumbClicked(
  580. false,
  581. resourceJid);
  582. updateLargeVideo = false;
  583. }
  584. remoteVideo.waitForPlayback(
  585. remoteVideo.selectVideoElement()[0],
  586. remoteVideo.videoStream);
  587. }
  588. });
  589. }
  590. // The endpoint that was being shown in the large video has dropped out
  591. // of the lastN set and there was no lastN pickup jid. We need to update
  592. // the large video now.
  593. if (updateLargeVideo) {
  594. var resource;
  595. // Find out which endpoint to show in the large video.
  596. for (i = 0; i < lastNEndpoints.length; i++) {
  597. resource = lastNEndpoints[i];
  598. if (!resource || APP.conference.isLocalId(resource))
  599. continue;
  600. // videoSrcToSsrc needs to be update for this call to succeed.
  601. this.updateLargeVideo(resource);
  602. break;
  603. }
  604. }
  605. },
  606. /**
  607. * Updates local stats
  608. * @param percent
  609. * @param object
  610. */
  611. updateLocalConnectionStats (percent, object) {
  612. let resolutions = object.resolution;
  613. object.resolution = resolutions[APP.conference.localId];
  614. localVideoThumbnail.updateStatsIndicator(percent, object);
  615. Object.keys(resolutions).forEach(function (id) {
  616. if (APP.conference.isLocalId(id)) {
  617. return;
  618. }
  619. let resolution = resolutions[id];
  620. let remoteVideo = remoteVideos[id];
  621. if (resolution && remoteVideo) {
  622. remoteVideo.updateResolution(resolution);
  623. }
  624. });
  625. },
  626. /**
  627. * Updates remote stats.
  628. * @param id the id associated with the stats
  629. * @param percent the connection quality percent
  630. * @param object the stats data
  631. */
  632. updateConnectionStats (id, percent, object) {
  633. if (remoteVideos[id]) {
  634. remoteVideos[id].updateStatsIndicator(percent, object);
  635. }
  636. },
  637. /**
  638. * Hides the connection indicator
  639. * @param id
  640. */
  641. hideConnectionIndicator (id) {
  642. remoteVideos[id].hideConnectionIndicator();
  643. },
  644. /**
  645. * Hides all the indicators
  646. */
  647. hideStats () {
  648. for(var video in remoteVideos) {
  649. remoteVideos[video].hideIndicator();
  650. }
  651. localVideoThumbnail.hideIndicator();
  652. },
  653. removeParticipantContainer (id) {
  654. // Unlock large video
  655. if (focusedVideoResourceJid === id) {
  656. console.info("Focused video owner has left the conference");
  657. focusedVideoResourceJid = null;
  658. }
  659. if (currentDominantSpeaker === id) {
  660. console.info("Dominant speaker has left the conference");
  661. currentDominantSpeaker = null;
  662. }
  663. var remoteVideo = remoteVideos[id];
  664. if (remoteVideo) {
  665. // Remove remote video
  666. console.info("Removing remote video: " + id);
  667. delete remoteVideos[id];
  668. remoteVideo.remove();
  669. } else {
  670. console.warn("No remote video for " + id);
  671. }
  672. VideoLayout.resizeThumbnails();
  673. },
  674. onVideoTypeChanged (id, newVideoType) {
  675. if (remoteVideoTypes[id] === newVideoType) {
  676. return;
  677. }
  678. console.info("Peer video type changed: ", id, newVideoType);
  679. remoteVideoTypes[id] = newVideoType;
  680. var smallVideo;
  681. if (APP.conference.isLocalId(id)) {
  682. if (!localVideoThumbnail) {
  683. console.warn("Local video not ready yet");
  684. return;
  685. }
  686. smallVideo = localVideoThumbnail;
  687. } else if (remoteVideos[id]) {
  688. smallVideo = remoteVideos[id];
  689. } else {
  690. return;
  691. }
  692. smallVideo.setVideoType(newVideoType);
  693. if (this.isCurrentlyOnLarge(id)) {
  694. this.updateLargeVideo(id, true);
  695. }
  696. },
  697. showMore (id) {
  698. if (id === 'local') {
  699. localVideoThumbnail.connectionIndicator.showMore();
  700. } else {
  701. let remoteVideo = remoteVideos[id];
  702. if (remoteVideo) {
  703. remoteVideo.connectionIndicator.showMore();
  704. } else {
  705. console.info("Error - no remote video for id: " + id);
  706. }
  707. }
  708. },
  709. addRemoteVideoContainer (id) {
  710. return RemoteVideo.createContainer(id);
  711. },
  712. /**
  713. * Resizes the video area.
  714. *
  715. * @param isSideBarVisible indicates if the side bar is currently visible
  716. * @param callback a function to be called when the video space is
  717. * resized.
  718. */
  719. resizeVideoArea (isSideBarVisible, callback) {
  720. let animate = true;
  721. if (largeVideo) {
  722. largeVideo.updateContainerSize(isSideBarVisible);
  723. largeVideo.resize(animate);
  724. this.resizeVideoSpace(animate, isSideBarVisible, callback);
  725. }
  726. VideoLayout.resizeThumbnails(animate);
  727. },
  728. /**
  729. * Resizes the #videospace html element
  730. * @param animate boolean property that indicates whether the resize should
  731. * be animated or not.
  732. * @param isChatVisible boolean property that indicates whether the chat
  733. * area is displayed or not.
  734. * If that parameter is null the method will check the chat panel
  735. * visibility.
  736. * @param completeFunction a function to be called when the video space
  737. * is resized.
  738. */
  739. resizeVideoSpace (animate, isChatVisible, completeFunction) {
  740. let availableHeight = window.innerHeight;
  741. let availableWidth = UIUtil.getAvailableVideoWidth(isChatVisible);
  742. if (availableWidth < 0 || availableHeight < 0) {
  743. return;
  744. }
  745. $('#videospace').animate({
  746. right: window.innerWidth - availableWidth,
  747. width: availableWidth,
  748. height: availableHeight
  749. }, {
  750. queue: false,
  751. duration: animate ? 500 : 1,
  752. complete: completeFunction
  753. });
  754. },
  755. getSmallVideo (id) {
  756. if (APP.conference.isLocalId(id)) {
  757. return localVideoThumbnail;
  758. } else {
  759. return remoteVideos[id];
  760. }
  761. },
  762. changeUserAvatar (id, avatarUrl) {
  763. var smallVideo = VideoLayout.getSmallVideo(id);
  764. if (smallVideo) {
  765. smallVideo.avatarChanged(avatarUrl);
  766. } else {
  767. console.warn(
  768. "Missed avatar update - no small video yet for " + id
  769. );
  770. }
  771. if (this.isCurrentlyOnLarge(id)) {
  772. largeVideo.updateAvatar(avatarUrl);
  773. }
  774. },
  775. /**
  776. * Indicates that the video has been interrupted.
  777. */
  778. onVideoInterrupted () {
  779. this.enableVideoProblemFilter(true);
  780. let reconnectingKey = "connection.RECONNECTING";
  781. $('#videoConnectionMessage')
  782. .attr("data-i18n", reconnectingKey)
  783. .text(APP.translation.translateString(reconnectingKey))
  784. .css({display: "block"});
  785. },
  786. /**
  787. * Indicates that the video has been restored.
  788. */
  789. onVideoRestored () {
  790. this.enableVideoProblemFilter(false);
  791. $('#videoConnectionMessage').css({display: "none"});
  792. },
  793. enableVideoProblemFilter (enable) {
  794. if (!largeVideo) {
  795. return;
  796. }
  797. largeVideo.enableVideoProblemFilter(enable);
  798. },
  799. isLargeVideoVisible () {
  800. return this.isLargeContainerTypeVisible(VideoContainerType);
  801. },
  802. isCurrentlyOnLarge (id) {
  803. return largeVideo && largeVideo.id === id;
  804. },
  805. updateLargeVideo (id, forceUpdate) {
  806. if (!largeVideo) {
  807. return;
  808. }
  809. let isOnLarge = this.isCurrentlyOnLarge(id);
  810. let currentId = largeVideo.id;
  811. if (!isOnLarge || forceUpdate) {
  812. if (id !== currentId) {
  813. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  814. }
  815. if (currentId) {
  816. var oldSmallVideo = this.getSmallVideo(currentId);
  817. }
  818. let smallVideo = this.getSmallVideo(id);
  819. let videoType = this.getRemoteVideoType(id);
  820. largeVideo.updateLargeVideo(
  821. id,
  822. smallVideo.videoStream,
  823. videoType
  824. ).then(function() {
  825. // update current small video and the old one
  826. smallVideo.updateView();
  827. oldSmallVideo && oldSmallVideo.updateView();
  828. }, function () {
  829. // use clicked other video during update, nothing to do.
  830. });
  831. } else if (currentId) {
  832. let currentSmallVideo = this.getSmallVideo(currentId);
  833. currentSmallVideo.updateView();
  834. }
  835. },
  836. addLargeVideoContainer (type, container) {
  837. largeVideo && largeVideo.addContainer(type, container);
  838. },
  839. removeLargeVideoContainer (type) {
  840. largeVideo && largeVideo.removeContainer(type);
  841. },
  842. /**
  843. * @returns Promise
  844. */
  845. showLargeVideoContainer (type, show) {
  846. if (!largeVideo) {
  847. return Promise.reject();
  848. }
  849. let isVisible = this.isLargeContainerTypeVisible(type);
  850. if (isVisible === show) {
  851. return Promise.resolve();
  852. }
  853. // if !show then use default type - large video
  854. return largeVideo.showContainer(show ? type : VideoContainerType);
  855. },
  856. isLargeContainerTypeVisible (type) {
  857. return largeVideo && largeVideo.state === type;
  858. },
  859. /**
  860. * Returns the id of the current video shown on large.
  861. * Currently used by tests (troture).
  862. */
  863. getLargeVideoID () {
  864. return largeVideo.id;
  865. }
  866. };
  867. export default VideoLayout;