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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. /* global config, APP, $, interfaceConfig */
  2. import FilmStrip from "./FilmStrip";
  3. import UIEvents from "../../../service/UI/UIEvents";
  4. import UIUtil from "../util/UIUtil";
  5. import RemoteVideo from "./RemoteVideo";
  6. import LargeVideoManager from "./LargeVideoManager";
  7. import {VIDEO_CONTAINER_TYPE} from "./VideoContainer";
  8. import LocalVideo from "./LocalVideo";
  9. var remoteVideos = {};
  10. var localVideoThumbnail = null;
  11. var currentDominantSpeaker = null;
  12. var localLastNCount = config.channelLastN;
  13. var localLastNSet = [];
  14. var lastNEndpointsCache = [];
  15. var lastNPickupId = null;
  16. var eventEmitter = null;
  17. /**
  18. * Currently focused video jid
  19. * @type {String}
  20. */
  21. var pinnedId = null;
  22. /**
  23. * flipX state of the localVideo
  24. */
  25. let localFlipX = 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.hasVideo()) {
  36. // It is not always the case that a videoThumb exists (if there is
  37. // no actual video).
  38. if (remoteVideo.hasVideoStarted()) {
  39. // We have a video src, great! Let's update the large video
  40. // now.
  41. VideoLayout.handleVideoThumbClicked(id);
  42. } else {
  43. // If we don't have a video src for jid, there's absolutely
  44. // no point in calling handleVideoThumbClicked; Quite
  45. // simply, it won't work because it needs an src to attach
  46. // to the large video.
  47. //
  48. // Instead, we trigger the pinned endpoint changed event to
  49. // let the bridge adjust its lastN set for myjid and store
  50. // the pinned user in the lastNPickupId variable to be
  51. // picked up later by the lastN changed event handler.
  52. lastNPickupId = id;
  53. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, remoteVideo, true);
  54. }
  55. }
  56. }
  57. /**
  58. * Returns the corresponding resource id to the given peer container
  59. * DOM element.
  60. *
  61. * @return the corresponding resource id to the given peer container
  62. * DOM element
  63. */
  64. function getPeerContainerResourceId (containerElement) {
  65. if (localVideoThumbnail.container === containerElement) {
  66. return localVideoThumbnail.id;
  67. }
  68. let i = containerElement.id.indexOf('participant_');
  69. if (i >= 0) {
  70. return containerElement.id.substring(i + 12);
  71. }
  72. }
  73. let largeVideo;
  74. var VideoLayout = {
  75. init (emitter) {
  76. eventEmitter = emitter;
  77. eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED, function (val) {
  78. localFlipX = val;
  79. if(largeVideo)
  80. largeVideo.onLocalFlipXChange(val);
  81. });
  82. localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
  83. // sets default video type of local video
  84. // FIXME container type is totally different thing from the video type
  85. localVideoThumbnail.setVideoType(VIDEO_CONTAINER_TYPE);
  86. // if we do not resize the thumbs here, if there is no video device
  87. // the local video thumb maybe one pixel
  88. this.resizeThumbnails(false, true);
  89. emitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
  90. this.lastNCount = config.channelLastN;
  91. },
  92. initLargeVideo () {
  93. largeVideo = new LargeVideoManager(eventEmitter);
  94. if(localFlipX) {
  95. largeVideo.onLocalFlipXChange(localFlipX);
  96. }
  97. largeVideo.updateContainerSize();
  98. },
  99. /**
  100. * Sets the audio level of the video elements associated to the given id.
  101. *
  102. * @param id the video identifier in the form it comes from the library
  103. * @param lvl the new audio level to update to
  104. */
  105. setAudioLevel(id, lvl) {
  106. let smallVideo = this.getSmallVideo(id);
  107. if (smallVideo)
  108. smallVideo.updateAudioLevelIndicator(lvl);
  109. if (largeVideo && id === largeVideo.id)
  110. largeVideo.updateLargeVideoAudioLevel(lvl);
  111. },
  112. isInLastN (resource) {
  113. return this.lastNCount < 0 || // lastN is disabled
  114. // lastNEndpoints cache not built yet
  115. (this.lastNCount > 0 && !lastNEndpointsCache.length) ||
  116. (lastNEndpointsCache &&
  117. lastNEndpointsCache.indexOf(resource) !== -1);
  118. },
  119. changeLocalAudio (stream) {
  120. let localAudio = document.getElementById('localAudio');
  121. localAudio = stream.attach(localAudio);
  122. // Now when Temasys plugin is converting also <audio> elements to
  123. // plugin's <object>s, in current layout it will capture click events
  124. // before it reaches the local video object. We hide it here in order
  125. // to prevent that.
  126. //if (RTCBrowserType.isIExplorer()) {
  127. // The issue is not present on Safari. Also if we hide it in Safari
  128. // then the local audio track will have 'enabled' flag set to false
  129. // which will result in audio mute issues
  130. // $(localAudio).hide();
  131. localAudio.width = 1;
  132. localAudio.height = 1;
  133. //}
  134. },
  135. changeLocalVideo (stream) {
  136. let localId = APP.conference.getMyUserId();
  137. this.onVideoTypeChanged(localId, stream.videoType);
  138. if (!stream.isMuted()) {
  139. localVideoThumbnail.changeVideo(stream);
  140. }
  141. /* force update if we're currently being displayed */
  142. if (this.isCurrentlyOnLarge(localId)) {
  143. this.updateLargeVideo(localId, true);
  144. }
  145. },
  146. /**
  147. * Get's the localID of the conference and set it to the local video
  148. * (small one). This needs to be called as early as possible, when muc is
  149. * actually joined. Otherwise events can come with information like email
  150. * and setting them assume the id is already set.
  151. */
  152. mucJoined () {
  153. if (largeVideo && !largeVideo.id) {
  154. this.updateLargeVideo(APP.conference.getMyUserId(), true);
  155. }
  156. },
  157. /**
  158. * Adds or removes icons for not available camera and microphone.
  159. * @param resourceJid the jid of user
  160. * @param devices available devices
  161. */
  162. setDeviceAvailabilityIcons (id, devices) {
  163. if (APP.conference.isLocalId(id)) {
  164. localVideoThumbnail.setDeviceAvailabilityIcons(devices);
  165. return;
  166. }
  167. let video = remoteVideos[id];
  168. if (!video) {
  169. return;
  170. }
  171. video.setDeviceAvailabilityIcons(devices);
  172. },
  173. /**
  174. * Enables/disables device availability icons for the given participant id.
  175. * The default value is {true}.
  176. * @param id the identifier of the participant
  177. * @param enable {true} to enable device availability icons
  178. */
  179. enableDeviceAvailabilityIcons (id, enable) {
  180. let video;
  181. if (APP.conference.isLocalId(id)) {
  182. video = localVideoThumbnail;
  183. }
  184. else {
  185. video = remoteVideos[id];
  186. }
  187. if (video)
  188. video.enableDeviceAvailabilityIcons(enable);
  189. },
  190. /**
  191. * Shows/hides local video.
  192. * @param {boolean} true to make the local video visible, false - otherwise
  193. */
  194. setLocalVideoVisible(visible) {
  195. localVideoThumbnail.setVisible(visible);
  196. },
  197. /**
  198. * Checks if removed video is currently displayed and tries to display
  199. * another one instead.
  200. * Uses focusedID if any or dominantSpeakerID if any,
  201. * otherwise elects new video, in this order.
  202. */
  203. updateAfterThumbRemoved (id) {
  204. if (!this.isCurrentlyOnLarge(id)) {
  205. return;
  206. }
  207. let newId;
  208. if (pinnedId)
  209. newId = pinnedId;
  210. else if (currentDominantSpeaker)
  211. newId = currentDominantSpeaker;
  212. else // Otherwise select last visible video
  213. newId = this.electLastVisibleVideo();
  214. this.updateLargeVideo(newId);
  215. },
  216. electLastVisibleVideo () {
  217. // pick the last visible video in the row
  218. // if nobody else is left, this picks the local video
  219. let remoteThumbs = FilmStrip.getThumbs(true).remoteThumbs;
  220. let thumbs = remoteThumbs.filter('[id!="mixedstream"]');
  221. let lastVisible = thumbs.filter(':visible:last');
  222. if (lastVisible.length) {
  223. let id = getPeerContainerResourceId(lastVisible[0]);
  224. if (remoteVideos[id]) {
  225. console.info("electLastVisibleVideo: " + id);
  226. return id;
  227. }
  228. // The RemoteVideo was removed (but the DOM elements may still
  229. // exist).
  230. }
  231. console.info("Last visible video no longer exists");
  232. thumbs = FilmStrip.getThumbs().remoteThumbs;
  233. if (thumbs.length) {
  234. let id = getPeerContainerResourceId(thumbs[0]);
  235. if (remoteVideos[id]) {
  236. console.info("electLastVisibleVideo: " + id);
  237. return id;
  238. }
  239. // The RemoteVideo was removed (but the DOM elements may
  240. // still exist).
  241. }
  242. // Go with local video
  243. console.info("Fallback to local video...");
  244. let id = APP.conference.getMyUserId();
  245. console.info("electLastVisibleVideo: " + id);
  246. return id;
  247. },
  248. onRemoteStreamAdded (stream) {
  249. let id = stream.getParticipantId();
  250. let remoteVideo = remoteVideos[id];
  251. if (!remoteVideo)
  252. return;
  253. remoteVideo.addRemoteStreamElement(stream);
  254. // if track is muted make sure we reflect that
  255. if(stream.isMuted())
  256. {
  257. if(stream.getType() === "audio")
  258. this.onAudioMute(stream.getParticipantId(), true);
  259. else
  260. this.onVideoMute(stream.getParticipantId(), true);
  261. }
  262. },
  263. onRemoteStreamRemoved (stream) {
  264. let id = stream.getParticipantId();
  265. let remoteVideo = remoteVideos[id];
  266. // Remote stream may be removed after participant left the conference.
  267. if (remoteVideo) {
  268. remoteVideo.removeRemoteStreamElement(stream);
  269. }
  270. },
  271. /**
  272. * Return the type of the remote video.
  273. * @param id the id for the remote video
  274. * @returns {String} the video type video or screen.
  275. */
  276. getRemoteVideoType (id) {
  277. let smallVideo = VideoLayout.getSmallVideo(id);
  278. return smallVideo ? smallVideo.getVideoType() : null;
  279. },
  280. isPinned (id) {
  281. return (pinnedId) ? (id === pinnedId) : false;
  282. },
  283. getPinnedId () {
  284. return pinnedId;
  285. },
  286. /**
  287. * Handles the click on a video thumbnail.
  288. *
  289. * @param id the identifier of the video thumbnail
  290. */
  291. handleVideoThumbClicked (id) {
  292. var smallVideo = VideoLayout.getSmallVideo(id);
  293. if(pinnedId) {
  294. var oldSmallVideo = VideoLayout.getSmallVideo(pinnedId);
  295. if (oldSmallVideo && !interfaceConfig.filmStripOnly) {
  296. oldSmallVideo.focus(false);
  297. // as no pinned event will be sent for local video
  298. // and we will unpin old one, lets signal it
  299. // otherwise we will just send the new pinned one
  300. if (smallVideo.isLocal)
  301. eventEmitter.emit(
  302. UIEvents.PINNED_ENDPOINT, oldSmallVideo, false);
  303. }
  304. }
  305. // Unpin if currently pinned.
  306. if (pinnedId === id)
  307. {
  308. pinnedId = null;
  309. // Enable the currently set dominant speaker.
  310. if (currentDominantSpeaker) {
  311. if(smallVideo && smallVideo.hasVideo()) {
  312. this.updateLargeVideo(currentDominantSpeaker);
  313. }
  314. } else {
  315. // if there is no currentDominantSpeaker, it can also be
  316. // that local participant is the dominant speaker
  317. // we should act as a participant has left and was on large
  318. // and we should choose somebody (electLastVisibleVideo)
  319. this.updateLargeVideo(this.electLastVisibleVideo());
  320. }
  321. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, smallVideo, false);
  322. return;
  323. }
  324. // Lock new video
  325. pinnedId = id;
  326. // Update focused/pinned interface.
  327. if (id) {
  328. if (smallVideo && !interfaceConfig.filmStripOnly)
  329. smallVideo.focus(true);
  330. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, smallVideo, true);
  331. }
  332. this.updateLargeVideo(id);
  333. },
  334. /**
  335. * Creates or adds a participant container for the given id and smallVideo.
  336. *
  337. * @param {JitsiParticipant} user the participant to add
  338. * @param {SmallVideo} smallVideo optional small video instance to add as a
  339. * remote video, if undefined <tt>RemoteVideo</tt> will be created
  340. */
  341. addParticipantContainer (user, smallVideo) {
  342. let id = user.getId();
  343. let remoteVideo;
  344. if(smallVideo)
  345. remoteVideo = smallVideo;
  346. else
  347. remoteVideo = new RemoteVideo(user, VideoLayout, eventEmitter);
  348. this.addRemoteVideoContainer(id, remoteVideo);
  349. },
  350. /**
  351. * Adds remote video container for the given id and <tt>SmallVideo</tt>.
  352. *
  353. * @param {string} the id of the video to add
  354. * @param {SmallVideo} smallVideo the small video instance to add as a
  355. * remote video
  356. */
  357. addRemoteVideoContainer (id, remoteVideo) {
  358. remoteVideos[id] = remoteVideo;
  359. if (!remoteVideo.getVideoType()) {
  360. // make video type the default one (camera)
  361. // FIXME container type is not a video type
  362. remoteVideo.setVideoType(VIDEO_CONTAINER_TYPE);
  363. }
  364. // In case this is not currently in the last n we don't show it.
  365. if (localLastNCount && localLastNCount > 0 &&
  366. FilmStrip.getThumbs().remoteThumbs.length >= localLastNCount + 2) {
  367. remoteVideo.showPeerContainer('hide');
  368. } else {
  369. VideoLayout.resizeThumbnails(false, true);
  370. }
  371. // Initialize the view
  372. remoteVideo.updateView();
  373. },
  374. // FIXME: what does this do???
  375. remoteVideoActive(videoElement, resourceJid) {
  376. console.info(resourceJid + " video is now active", videoElement);
  377. VideoLayout.resizeThumbnails(
  378. false, false, function() {$(videoElement).show();});
  379. // Update the large video to the last added video only if there's no
  380. // current dominant, focused speaker or update it to
  381. // the current dominant speaker.
  382. if ((!pinnedId &&
  383. !currentDominantSpeaker &&
  384. this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE)) ||
  385. pinnedId === resourceJid ||
  386. (!pinnedId && resourceJid &&
  387. currentDominantSpeaker === resourceJid) ||
  388. /* Playback started while we're on the stage - may need to update
  389. video source with the new stream */
  390. this.isCurrentlyOnLarge(resourceJid)) {
  391. this.updateLargeVideo(resourceJid, true);
  392. }
  393. },
  394. /**
  395. * Shows a visual indicator for the moderator of the conference.
  396. * On local or remote participants.
  397. */
  398. showModeratorIndicator () {
  399. let isModerator = APP.conference.isModerator;
  400. if (isModerator) {
  401. localVideoThumbnail.addModeratorIndicator();
  402. } else {
  403. localVideoThumbnail.removeModeratorIndicator();
  404. }
  405. APP.conference.listMembers().forEach(function (member) {
  406. let id = member.getId();
  407. let remoteVideo = remoteVideos[id];
  408. if (!remoteVideo)
  409. return;
  410. if (member.isModerator()) {
  411. remoteVideo.addModeratorIndicator();
  412. }
  413. if (isModerator) {
  414. // We are moderator, but user is not - add menu
  415. if(!remoteVideo.hasRemoteVideoMenu) {
  416. remoteVideo.addRemoteVideoMenu();
  417. }
  418. }
  419. });
  420. },
  421. /*
  422. * Shows or hides the audio muted indicator over the local thumbnail video.
  423. * @param {boolean} isMuted
  424. */
  425. showLocalAudioIndicator (isMuted) {
  426. localVideoThumbnail.showAudioIndicator(isMuted);
  427. },
  428. /**
  429. * Shows/hides the indication about local connection being interrupted.
  430. *
  431. * @param {boolean} isInterrupted <tt>true</tt> if local connection is
  432. * currently in the interrupted state or <tt>false</tt> if the connection
  433. * is fine.
  434. */
  435. showLocalConnectionInterrupted (isInterrupted) {
  436. localVideoThumbnail.connectionIndicator
  437. .updateConnectionStatusIndicator(!isInterrupted);
  438. },
  439. /**
  440. * Resizes thumbnails.
  441. */
  442. resizeThumbnails ( animate = false,
  443. forceUpdate = false,
  444. onComplete = null) {
  445. const { localVideo, remoteVideo }
  446. = FilmStrip.calculateThumbnailSize();
  447. FilmStrip.resizeThumbnails(localVideo, remoteVideo,
  448. animate, forceUpdate)
  449. .then(function () {
  450. if (onComplete && typeof onComplete === "function")
  451. onComplete();
  452. });
  453. return { localVideo, remoteVideo };
  454. },
  455. /**
  456. * On audio muted event.
  457. */
  458. onAudioMute (id, isMuted) {
  459. if (APP.conference.isLocalId(id)) {
  460. localVideoThumbnail.showAudioIndicator(isMuted);
  461. } else {
  462. let remoteVideo = remoteVideos[id];
  463. if (!remoteVideo)
  464. return;
  465. remoteVideo.showAudioIndicator(isMuted);
  466. if (APP.conference.isModerator) {
  467. remoteVideo.updateRemoteVideoMenu(isMuted);
  468. }
  469. }
  470. },
  471. /**
  472. * On video muted event.
  473. */
  474. onVideoMute (id, value) {
  475. if (APP.conference.isLocalId(id)) {
  476. localVideoThumbnail.setVideoMutedView(value);
  477. } else {
  478. let remoteVideo = remoteVideos[id];
  479. if (remoteVideo)
  480. remoteVideo.setVideoMutedView(value);
  481. }
  482. if (this.isCurrentlyOnLarge(id)) {
  483. // large video will show avatar instead of muted stream
  484. this.updateLargeVideo(id, true);
  485. }
  486. },
  487. /**
  488. * Display name changed.
  489. */
  490. onDisplayNameChanged (id, displayName, status) {
  491. if (id === 'localVideoContainer' ||
  492. APP.conference.isLocalId(id)) {
  493. localVideoThumbnail.setDisplayName(displayName);
  494. } else {
  495. let remoteVideo = remoteVideos[id];
  496. if (remoteVideo)
  497. remoteVideo.setDisplayName(displayName, status);
  498. }
  499. },
  500. /**
  501. * Sets the "raised hand" status for a participant identified by 'id'.
  502. */
  503. setRaisedHandStatus(id, raisedHandStatus) {
  504. var video
  505. = APP.conference.isLocalId(id)
  506. ? localVideoThumbnail : remoteVideos[id];
  507. if (video) {
  508. video.showRaisedHandIndicator(raisedHandStatus);
  509. if (raisedHandStatus) {
  510. video.showDominantSpeakerIndicator(false);
  511. }
  512. }
  513. },
  514. /**
  515. * On dominant speaker changed event.
  516. */
  517. onDominantSpeakerChanged (id) {
  518. if (id === currentDominantSpeaker) {
  519. return;
  520. }
  521. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  522. // We ignore local user events, but just unmark remote user as dominant
  523. // while we are talking
  524. if (APP.conference.isLocalId(id)) {
  525. if(oldSpeakerRemoteVideo)
  526. {
  527. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  528. currentDominantSpeaker = null;
  529. }
  530. localVideoThumbnail.showDominantSpeakerIndicator(true);
  531. return;
  532. }
  533. let remoteVideo = remoteVideos[id];
  534. if (!remoteVideo) {
  535. return;
  536. }
  537. // Update the current dominant speaker.
  538. remoteVideo.showDominantSpeakerIndicator(true);
  539. localVideoThumbnail.showDominantSpeakerIndicator(false);
  540. // let's remove the indications from the remote video if any
  541. if (oldSpeakerRemoteVideo) {
  542. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  543. }
  544. currentDominantSpeaker = id;
  545. // Local video will not have container found, but that's ok
  546. // since we don't want to switch to local video.
  547. // Update the large video if the video source is already available,
  548. // otherwise wait for the "videoactive.jingle" event.
  549. // FIXME: there is no "videoactive.jingle" event.
  550. if (!pinnedId
  551. && remoteVideo.hasVideoStarted()
  552. && !this.getCurrentlyOnLargeContainer().stayOnStage()) {
  553. this.updateLargeVideo(id);
  554. }
  555. },
  556. /**
  557. * Shows/hides warning about remote user's connectivity issues.
  558. *
  559. * @param {string} id the ID of the remote participant(MUC nickname)
  560. * @param {boolean} isActive true if the connection is ok or false when
  561. * the user is having connectivity issues.
  562. */
  563. // eslint-disable-next-line no-unused-vars
  564. onParticipantConnectionStatusChanged (id, isActive) {
  565. // Show/hide warning on the large video
  566. if (this.isCurrentlyOnLarge(id)) {
  567. if (largeVideo) {
  568. // We have to trigger full large video update to transition from
  569. // avatar to video on connectivity restored.
  570. this.updateLargeVideo(id, true /* force update */);
  571. }
  572. }
  573. // Show/hide warning on the thumbnail
  574. let remoteVideo = remoteVideos[id];
  575. if (remoteVideo) {
  576. // Updating only connection status indicator is not enough, because
  577. // when we the connection is restored while the avatar was displayed
  578. // (due to 'muted while disconnected' condition) we may want to show
  579. // the video stream again and in order to do that the display mode
  580. // must be updated.
  581. //remoteVideo.updateConnectionStatusIndicator(isActive);
  582. remoteVideo.updateView();
  583. }
  584. },
  585. /**
  586. * On last N change event.
  587. *
  588. * @param lastNEndpoints the list of last N endpoints
  589. * @param endpointsEnteringLastN the list currently entering last N
  590. * endpoints
  591. */
  592. onLastNEndpointsChanged (lastNEndpoints, endpointsEnteringLastN) {
  593. if (this.lastNCount !== lastNEndpoints.length)
  594. this.lastNCount = lastNEndpoints.length;
  595. lastNEndpointsCache = lastNEndpoints;
  596. // Say A, B, C, D, E, and F are in a conference and LastN = 3.
  597. //
  598. // If LastN drops to, say, 2, because of adaptivity, then E should see
  599. // thumbnails for A, B and C. A and B are in E's server side LastN set,
  600. // so E sees them. C is only in E's local LastN set.
  601. //
  602. // If F starts talking and LastN = 3, then E should see thumbnails for
  603. // F, A, B. B gets "ejected" from E's server side LastN set, but it
  604. // enters E's local LastN ejecting C.
  605. // Increase the local LastN set size, if necessary.
  606. if (this.lastNCount > localLastNCount) {
  607. localLastNCount = this.lastNCount;
  608. }
  609. // Update the local LastN set preserving the order in which the
  610. // endpoints appeared in the LastN/local LastN set.
  611. var nextLocalLastNSet = lastNEndpoints.slice(0);
  612. for (var i = 0; i < localLastNSet.length; i++) {
  613. if (nextLocalLastNSet.length >= localLastNCount) {
  614. break;
  615. }
  616. var resourceJid = localLastNSet[i];
  617. if (nextLocalLastNSet.indexOf(resourceJid) === -1) {
  618. nextLocalLastNSet.push(resourceJid);
  619. }
  620. }
  621. localLastNSet = nextLocalLastNSet;
  622. var updateLargeVideo = false;
  623. // Handle LastN/local LastN changes.
  624. FilmStrip.getThumbs().remoteThumbs.each(( index, element ) => {
  625. var resourceJid = getPeerContainerResourceId(element);
  626. var smallVideo = remoteVideos[resourceJid];
  627. // We do not want to process any logic for our own(local) video
  628. // because the local participant is never in the lastN set.
  629. // The code of this function might detect that the local participant
  630. // has been dropped out of the lastN set and will update the large
  631. // video
  632. // Detected from avatar tests, where lastN event override
  633. // local video pinning
  634. if(APP.conference.isLocalId(resourceJid))
  635. return;
  636. var isReceived = true;
  637. if (resourceJid &&
  638. lastNEndpoints.indexOf(resourceJid) < 0 &&
  639. localLastNSet.indexOf(resourceJid) < 0) {
  640. console.log("Remove from last N", resourceJid);
  641. if (smallVideo)
  642. smallVideo.showPeerContainer('hide');
  643. else if (!APP.conference.isLocalId(resourceJid))
  644. console.error("No remote video for: " + resourceJid);
  645. isReceived = false;
  646. } else if (resourceJid &&
  647. //TOFIX: smallVideo may be undefined
  648. smallVideo.isVisible() &&
  649. lastNEndpoints.indexOf(resourceJid) < 0 &&
  650. localLastNSet.indexOf(resourceJid) >= 0) {
  651. // TOFIX: if we're here we already know that the smallVideo
  652. // exists. Look at the previous FIX above.
  653. if (smallVideo)
  654. smallVideo.showPeerContainer('avatar');
  655. else if (!APP.conference.isLocalId(resourceJid))
  656. console.error("No remote video for: " + resourceJid);
  657. isReceived = false;
  658. }
  659. if (!isReceived) {
  660. // resourceJid has dropped out of the server side lastN set, so
  661. // it is no longer being received. If resourceJid was being
  662. // displayed in the large video we have to switch to another
  663. // user.
  664. if (!updateLargeVideo &&
  665. this.isCurrentlyOnLarge(resourceJid)) {
  666. updateLargeVideo = true;
  667. }
  668. }
  669. });
  670. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  671. endpointsEnteringLastN = lastNEndpoints;
  672. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  673. endpointsEnteringLastN.forEach(function (resourceJid) {
  674. var remoteVideo = remoteVideos[resourceJid];
  675. if (remoteVideo)
  676. remoteVideo.showPeerContainer('show');
  677. if (!remoteVideo.isVisible()) {
  678. console.log("Add to last N", resourceJid);
  679. remoteVideo.addRemoteStreamElement(remoteVideo.videoStream);
  680. if (lastNPickupId == resourceJid) {
  681. // Clean up the lastN pickup id.
  682. lastNPickupId = null;
  683. VideoLayout.handleVideoThumbClicked(resourceJid);
  684. updateLargeVideo = false;
  685. }
  686. remoteVideo.waitForPlayback(
  687. remoteVideo.selectVideoElement()[0],
  688. remoteVideo.videoStream);
  689. }
  690. });
  691. }
  692. // The endpoint that was being shown in the large video has dropped out
  693. // of the lastN set and there was no lastN pickup jid. We need to update
  694. // the large video now.
  695. if (updateLargeVideo) {
  696. var resource;
  697. // Find out which endpoint to show in the large video.
  698. for (i = 0; i < lastNEndpoints.length; i++) {
  699. resource = lastNEndpoints[i];
  700. if (!resource || APP.conference.isLocalId(resource))
  701. continue;
  702. // videoSrcToSsrc needs to be update for this call to succeed.
  703. this.updateLargeVideo(resource);
  704. break;
  705. }
  706. }
  707. },
  708. /**
  709. * Updates local stats
  710. * @param percent
  711. * @param object
  712. */
  713. updateLocalConnectionStats (percent, object) {
  714. let resolutions = object.resolution;
  715. object.resolution = resolutions[APP.conference.getMyUserId()];
  716. localVideoThumbnail.updateStatsIndicator(percent, object);
  717. Object.keys(resolutions).forEach(function (id) {
  718. if (APP.conference.isLocalId(id)) {
  719. return;
  720. }
  721. let resolution = resolutions[id];
  722. let remoteVideo = remoteVideos[id];
  723. if (resolution && remoteVideo) {
  724. remoteVideo.updateResolution(resolution);
  725. }
  726. });
  727. },
  728. /**
  729. * Updates remote stats.
  730. * @param id the id associated with the stats
  731. * @param percent the connection quality percent
  732. * @param object the stats data
  733. */
  734. updateConnectionStats (id, percent, object) {
  735. let remoteVideo = remoteVideos[id];
  736. if (remoteVideo) {
  737. remoteVideo.updateStatsIndicator(percent, object);
  738. }
  739. },
  740. /**
  741. * Hides the connection indicator
  742. * @param id
  743. */
  744. hideConnectionIndicator (id) {
  745. let remoteVideo = remoteVideos[id];
  746. if (remoteVideo)
  747. remoteVideo.hideConnectionIndicator();
  748. },
  749. /**
  750. * Hides all the indicators
  751. */
  752. hideStats () {
  753. for (var video in remoteVideos) {
  754. let remoteVideo = remoteVideos[video];
  755. if (remoteVideo)
  756. remoteVideo.hideIndicator();
  757. }
  758. localVideoThumbnail.hideIndicator();
  759. },
  760. removeParticipantContainer (id) {
  761. // Unlock large video
  762. if (pinnedId === id) {
  763. console.info("Focused video owner has left the conference");
  764. pinnedId = null;
  765. }
  766. if (currentDominantSpeaker === id) {
  767. console.info("Dominant speaker has left the conference");
  768. currentDominantSpeaker = null;
  769. }
  770. var remoteVideo = remoteVideos[id];
  771. if (remoteVideo) {
  772. // Remove remote video
  773. console.info("Removing remote video: " + id);
  774. delete remoteVideos[id];
  775. remoteVideo.remove();
  776. } else {
  777. console.warn("No remote video for " + id);
  778. }
  779. VideoLayout.resizeThumbnails();
  780. },
  781. onVideoTypeChanged (id, newVideoType) {
  782. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  783. return;
  784. }
  785. console.info("Peer video type changed: ", id, newVideoType);
  786. var smallVideo;
  787. if (APP.conference.isLocalId(id)) {
  788. if (!localVideoThumbnail) {
  789. console.warn("Local video not ready yet");
  790. return;
  791. }
  792. smallVideo = localVideoThumbnail;
  793. } else if (remoteVideos[id]) {
  794. smallVideo = remoteVideos[id];
  795. } else {
  796. return;
  797. }
  798. smallVideo.setVideoType(newVideoType);
  799. if (this.isCurrentlyOnLarge(id)) {
  800. this.updateLargeVideo(id, true);
  801. }
  802. },
  803. showMore (id) {
  804. if (id === 'local') {
  805. localVideoThumbnail.connectionIndicator.showMore();
  806. } else {
  807. let remoteVideo = remoteVideos[id];
  808. if (remoteVideo) {
  809. remoteVideo.connectionIndicator.showMore();
  810. } else {
  811. console.info("Error - no remote video for id: " + id);
  812. }
  813. }
  814. },
  815. /**
  816. * Resizes the video area.
  817. *
  818. * @param forceUpdate indicates that hidden thumbnails will be shown
  819. * @param completeFunction a function to be called when the video area is
  820. * resized.
  821. */
  822. resizeVideoArea (forceUpdate = false,
  823. animate = false,
  824. completeFunction = null) {
  825. if (largeVideo) {
  826. largeVideo.updateContainerSize();
  827. largeVideo.resize(animate);
  828. }
  829. // Calculate available width and height.
  830. let availableHeight = window.innerHeight;
  831. let availableWidth = UIUtil.getAvailableVideoWidth();
  832. if (availableWidth < 0 || availableHeight < 0) {
  833. return;
  834. }
  835. // Resize the thumbnails first.
  836. this.resizeThumbnails(false, forceUpdate);
  837. // Resize the video area element.
  838. $('#videospace').animate({
  839. right: window.innerWidth - availableWidth,
  840. width: availableWidth,
  841. height: availableHeight
  842. }, {
  843. queue: false,
  844. duration: animate ? 500 : 1,
  845. complete: completeFunction
  846. });
  847. },
  848. getSmallVideo (id) {
  849. if (APP.conference.isLocalId(id)) {
  850. return localVideoThumbnail;
  851. } else {
  852. return remoteVideos[id];
  853. }
  854. },
  855. changeUserAvatar (id, avatarUrl) {
  856. var smallVideo = VideoLayout.getSmallVideo(id);
  857. if (smallVideo) {
  858. smallVideo.avatarChanged(avatarUrl);
  859. } else {
  860. console.warn(
  861. "Missed avatar update - no small video yet for " + id
  862. );
  863. }
  864. if (this.isCurrentlyOnLarge(id)) {
  865. largeVideo.updateAvatar(avatarUrl);
  866. }
  867. },
  868. /**
  869. * Indicates that the video has been interrupted.
  870. */
  871. onVideoInterrupted () {
  872. if (largeVideo) {
  873. largeVideo.onVideoInterrupted();
  874. }
  875. },
  876. /**
  877. * Indicates that the video has been restored.
  878. */
  879. onVideoRestored () {
  880. if (largeVideo) {
  881. largeVideo.onVideoRestored();
  882. }
  883. },
  884. isLargeVideoVisible () {
  885. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  886. },
  887. /**
  888. * @return {LargeContainer} the currently displayed container on large
  889. * video.
  890. */
  891. getCurrentlyOnLargeContainer () {
  892. return largeVideo.getContainer(largeVideo.state);
  893. },
  894. isCurrentlyOnLarge (id) {
  895. return largeVideo && largeVideo.id === id;
  896. },
  897. updateLargeVideo (id, forceUpdate) {
  898. if (!largeVideo) {
  899. return;
  900. }
  901. let isOnLarge = this.isCurrentlyOnLarge(id);
  902. let currentId = largeVideo.id;
  903. if (!isOnLarge || forceUpdate) {
  904. let videoType = this.getRemoteVideoType(id);
  905. // FIXME video type is not the same thing as container type
  906. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  907. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  908. }
  909. let smallVideo = this.getSmallVideo(id);
  910. let oldSmallVideo;
  911. if (currentId) {
  912. oldSmallVideo = this.getSmallVideo(currentId);
  913. }
  914. smallVideo.waitForResolutionChange();
  915. if (oldSmallVideo)
  916. oldSmallVideo.waitForResolutionChange();
  917. largeVideo.updateLargeVideo(
  918. id,
  919. smallVideo.videoStream,
  920. videoType
  921. ).then(function() {
  922. // update current small video and the old one
  923. smallVideo.updateView();
  924. oldSmallVideo && oldSmallVideo.updateView();
  925. }, function () {
  926. // use clicked other video during update, nothing to do.
  927. });
  928. } else if (currentId) {
  929. let currentSmallVideo = this.getSmallVideo(currentId);
  930. currentSmallVideo.updateView();
  931. }
  932. },
  933. addLargeVideoContainer (type, container) {
  934. largeVideo && largeVideo.addContainer(type, container);
  935. },
  936. removeLargeVideoContainer (type) {
  937. largeVideo && largeVideo.removeContainer(type);
  938. },
  939. /**
  940. * @returns Promise
  941. */
  942. showLargeVideoContainer (type, show) {
  943. if (!largeVideo) {
  944. return Promise.reject();
  945. }
  946. let isVisible = this.isLargeContainerTypeVisible(type);
  947. if (isVisible === show) {
  948. return Promise.resolve();
  949. }
  950. let currentId = largeVideo.id;
  951. if(currentId) {
  952. var oldSmallVideo = this.getSmallVideo(currentId);
  953. }
  954. let containerTypeToShow = type;
  955. // if we are hiding a container and there is focusedVideo
  956. // (pinned remote video) use its video type,
  957. // if not then use default type - large video
  958. if (!show) {
  959. if(pinnedId)
  960. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  961. else
  962. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  963. }
  964. return largeVideo.showContainer(containerTypeToShow)
  965. .then(() => {
  966. if(oldSmallVideo)
  967. oldSmallVideo && oldSmallVideo.updateView();
  968. });
  969. },
  970. isLargeContainerTypeVisible (type) {
  971. return largeVideo && largeVideo.state === type;
  972. },
  973. /**
  974. * Returns the id of the current video shown on large.
  975. * Currently used by tests (torture).
  976. */
  977. getLargeVideoID () {
  978. return largeVideo.id;
  979. },
  980. /**
  981. * Returns the the current video shown on large.
  982. * Currently used by tests (torture).
  983. */
  984. getLargeVideo () {
  985. return largeVideo;
  986. },
  987. /**
  988. * Updates the resolution label, indicating to the user that the large
  989. * video stream is currently HD.
  990. */
  991. updateResolutionLabel(isResolutionHD) {
  992. let id = 'videoResolutionLabel';
  993. if (isResolutionHD) {
  994. UIUtil.showElement(id);
  995. } else {
  996. UIUtil.hideElement(id);
  997. }
  998. },
  999. /**
  1000. * Sets the flipX state of the local video.
  1001. * @param {boolean} true for flipped otherwise false;
  1002. */
  1003. setLocalFlipX: function (val) {
  1004. this.localFlipX = val;
  1005. },
  1006. getEventEmitter: () => {return eventEmitter;}
  1007. };
  1008. export default VideoLayout;