Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

VideoLayout.js 33KB

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