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

VideoLayout.js 33KB

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