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

VideoLayout.js 36KB

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