Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VideoLayout.js 36KB

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