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 32KB

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