Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /* global APP */
  2. import {
  3. createTrackMutedEvent,
  4. sendAnalytics
  5. } from '../../analytics';
  6. import { NOTIFICATION_TIMEOUT_TYPE, showErrorNotification, showNotification } from '../../notifications';
  7. import { JitsiTrackErrors, JitsiTrackEvents, createLocalTrack } from '../lib-jitsi-meet';
  8. import {
  9. CAMERA_FACING_MODE,
  10. MEDIA_TYPE,
  11. setAudioMuted,
  12. setVideoMuted,
  13. VIDEO_MUTISM_AUTHORITY,
  14. VIDEO_TYPE
  15. } from '../media';
  16. import { getLocalParticipant } from '../participants';
  17. import { updateSettings } from '../settings';
  18. import {
  19. SET_NO_SRC_DATA_NOTIFICATION_UID,
  20. TOGGLE_SCREENSHARING,
  21. TRACK_ADDED,
  22. TRACK_CREATE_CANCELED,
  23. TRACK_CREATE_ERROR,
  24. TRACK_NO_DATA_FROM_SOURCE,
  25. TRACK_REMOVED,
  26. TRACK_STOPPED,
  27. TRACK_UPDATED,
  28. TRACK_UPDATE_LAST_VIDEO_MEDIA_EVENT,
  29. TRACK_WILL_CREATE
  30. } from './actionTypes';
  31. import {
  32. createLocalTracksF,
  33. getLocalTrack,
  34. getLocalTracks,
  35. getLocalVideoTrack,
  36. getTrackByJitsiTrack
  37. } from './functions';
  38. import logger from './logger';
  39. /**
  40. * Requests the creating of the desired media type tracks. Desire is expressed
  41. * by base/media unless the function caller specifies desired media types
  42. * explicitly and thus override base/media. Dispatches a
  43. * {@code createLocalTracksA} action for the desired media types for which there
  44. * are no existing tracks yet.
  45. *
  46. * @returns {Function}
  47. */
  48. export function createDesiredLocalTracks(...desiredTypes) {
  49. return (dispatch, getState) => {
  50. const state = getState();
  51. dispatch(destroyLocalDesktopTrackIfExists());
  52. if (desiredTypes.length === 0) {
  53. const { video } = state['features/base/media'];
  54. // XXX: Always create the audio track early, even if it will be muted.
  55. // This fixes a timing issue when adding the track to the conference which
  56. // manifests primarily on iOS 15.
  57. desiredTypes.push(MEDIA_TYPE.AUDIO);
  58. // XXX When the app is coming into the foreground from the
  59. // background in order to handle a URL, it may realize the new
  60. // background state soon after it has tried to create the local
  61. // tracks requested by the URL. Ignore
  62. // VIDEO_MUTISM_AUTHORITY.BACKGROUND and create the local video
  63. // track if no other VIDEO_MUTISM_AUTHORITY has muted it. The local
  64. // video track will be muted until the app realizes the new
  65. // background state.
  66. // eslint-disable-next-line no-bitwise
  67. (video.muted & ~VIDEO_MUTISM_AUTHORITY.BACKGROUND)
  68. || desiredTypes.push(MEDIA_TYPE.VIDEO);
  69. }
  70. const availableTypes
  71. = getLocalTracks(
  72. state['features/base/tracks'],
  73. /* includePending */ true)
  74. .map(t => t.mediaType);
  75. // We need to create the desired tracks which are not already available.
  76. const createTypes
  77. = desiredTypes.filter(type => availableTypes.indexOf(type) === -1);
  78. createTypes.length
  79. && dispatch(createLocalTracksA({ devices: createTypes }));
  80. };
  81. }
  82. /**
  83. * Request to start capturing local audio and/or video. By default, the user
  84. * facing camera will be selected.
  85. *
  86. * @param {Object} [options] - For info @see JitsiMeetJS.createLocalTracks.
  87. * @returns {Function}
  88. */
  89. export function createLocalTracksA(options = {}) {
  90. return (dispatch, getState) => {
  91. const devices
  92. = options.devices || [ MEDIA_TYPE.AUDIO, MEDIA_TYPE.VIDEO ];
  93. const store = {
  94. dispatch,
  95. getState
  96. };
  97. // The following executes on React Native only at the time of this
  98. // writing. The effort to port Web's createInitialLocalTracksAndConnect
  99. // is significant and that's where the function createLocalTracksF got
  100. // born. I started with the idea a porting so that we could inherit the
  101. // ability to getUserMedia for audio only or video only if getUserMedia
  102. // for audio and video fails. Eventually though, I realized that on
  103. // mobile we do not have combined permission prompts implemented anyway
  104. // (either because there are no such prompts or it does not make sense
  105. // to implement them) and the right thing to do is to ask for each
  106. // device separately.
  107. for (const device of devices) {
  108. if (getLocalTrack(
  109. getState()['features/base/tracks'],
  110. device,
  111. /* includePending */ true)) {
  112. throw new Error(`Local track for ${device} already exists`);
  113. }
  114. const gumProcess
  115. = createLocalTracksF(
  116. {
  117. cameraDeviceId: options.cameraDeviceId,
  118. devices: [ device ],
  119. facingMode:
  120. options.facingMode || CAMERA_FACING_MODE.USER,
  121. micDeviceId: options.micDeviceId
  122. },
  123. store)
  124. .then(
  125. localTracks => {
  126. // Because GUM is called for 1 device (which is actually
  127. // a media type 'audio', 'video', 'screen', etc.) we
  128. // should not get more than one JitsiTrack.
  129. if (localTracks.length !== 1) {
  130. throw new Error(
  131. `Expected exactly 1 track, but was given ${
  132. localTracks.length} tracks for device: ${
  133. device}.`);
  134. }
  135. if (gumProcess.canceled) {
  136. return _disposeTracks(localTracks)
  137. .then(() =>
  138. dispatch(_trackCreateCanceled(device)));
  139. }
  140. return dispatch(trackAdded(localTracks[0]));
  141. },
  142. reason =>
  143. dispatch(
  144. gumProcess.canceled
  145. ? _trackCreateCanceled(device)
  146. : _onCreateLocalTracksRejected(
  147. reason,
  148. device)));
  149. /**
  150. * Cancels the {@code getUserMedia} process represented by this
  151. * {@code Promise}.
  152. *
  153. * @returns {Promise} This {@code Promise} i.e. {@code gumProcess}.
  154. */
  155. gumProcess.cancel = () => {
  156. gumProcess.canceled = true;
  157. return gumProcess;
  158. };
  159. dispatch({
  160. type: TRACK_WILL_CREATE,
  161. track: {
  162. gumProcess,
  163. local: true,
  164. mediaType: device
  165. }
  166. });
  167. }
  168. };
  169. }
  170. /**
  171. * Calls JitsiLocalTrack#dispose() on the given track or on all local tracks (if none are passed) ignoring errors if
  172. * track is already disposed. After that signals tracks to be removed.
  173. *
  174. * @param {JitsiLocalTrack|null} [track] - The local track that needs to be destroyed.
  175. * @returns {Function}
  176. */
  177. export function destroyLocalTracks(track = null) {
  178. if (track) {
  179. return dispatch => {
  180. dispatch(_disposeAndRemoveTracks([ track ]));
  181. };
  182. }
  183. return (dispatch, getState) => {
  184. // First wait until any getUserMedia in progress is settled and then get
  185. // rid of all local tracks.
  186. _cancelGUMProcesses(getState)
  187. .then(() =>
  188. dispatch(
  189. _disposeAndRemoveTracks(
  190. getState()['features/base/tracks']
  191. .filter(t => t.local)
  192. .map(t => t.jitsiTrack))));
  193. };
  194. }
  195. /**
  196. * Signals that the passed JitsiLocalTrack has triggered a no data from source event.
  197. *
  198. * @param {JitsiLocalTrack} track - The track.
  199. * @returns {{
  200. * type: TRACK_NO_DATA_FROM_SOURCE,
  201. * track: Track
  202. * }}
  203. */
  204. export function noDataFromSource(track) {
  205. return {
  206. type: TRACK_NO_DATA_FROM_SOURCE,
  207. track
  208. };
  209. }
  210. /**
  211. * Displays a no data from source video error if needed.
  212. *
  213. * @param {JitsiLocalTrack} jitsiTrack - The track.
  214. * @returns {Function}
  215. */
  216. export function showNoDataFromSourceVideoError(jitsiTrack) {
  217. return async (dispatch, getState) => {
  218. let notificationInfo;
  219. const track = getTrackByJitsiTrack(getState()['features/base/tracks'], jitsiTrack);
  220. if (!track) {
  221. return;
  222. }
  223. if (track.isReceivingData) {
  224. notificationInfo = undefined;
  225. } else {
  226. const notificationAction = await dispatch(showErrorNotification({
  227. descriptionKey: 'dialog.cameraNotSendingData',
  228. titleKey: 'dialog.cameraNotSendingDataTitle'
  229. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  230. notificationInfo = {
  231. uid: notificationAction.uid
  232. };
  233. }
  234. dispatch(trackNoDataFromSourceNotificationInfoChanged(jitsiTrack, notificationInfo));
  235. };
  236. }
  237. /**
  238. * Signals that the local participant is ending screensharing or beginning the
  239. * screensharing flow.
  240. *
  241. * @param {boolean} enabled - The state to toggle screen sharing to.
  242. * @param {boolean} audioOnly - Only share system audio.
  243. * @param {boolean} ignoreDidHaveVideo - Wether or not to ignore if video was on when sharing started.
  244. * @returns {{
  245. * type: TOGGLE_SCREENSHARING,
  246. * on: boolean,
  247. * audioOnly: boolean,
  248. * ignoreDidHaveVideo: boolean
  249. * }}
  250. */
  251. export function toggleScreensharing(enabled, audioOnly = false, ignoreDidHaveVideo = false) {
  252. return {
  253. type: TOGGLE_SCREENSHARING,
  254. enabled,
  255. audioOnly,
  256. ignoreDidHaveVideo
  257. };
  258. }
  259. /**
  260. * Replaces one track with another for one renegotiation instead of invoking
  261. * two renegotiations with a separate removeTrack and addTrack. Disposes the
  262. * removed track as well.
  263. *
  264. * @param {JitsiLocalTrack|null} oldTrack - The track to dispose.
  265. * @param {JitsiLocalTrack|null} newTrack - The track to use instead.
  266. * @param {JitsiConference} [conference] - The conference from which to remove
  267. * and add the tracks. If one is not provided, the conference in the redux store
  268. * will be used.
  269. * @returns {Function}
  270. */
  271. export function replaceLocalTrack(oldTrack, newTrack, conference) {
  272. return async (dispatch, getState) => {
  273. conference
  274. // eslint-disable-next-line no-param-reassign
  275. || (conference = getState()['features/base/conference'].conference);
  276. if (conference) {
  277. await conference.replaceTrack(oldTrack, newTrack);
  278. }
  279. return dispatch(replaceStoredTracks(oldTrack, newTrack));
  280. };
  281. }
  282. /**
  283. * Replaces a stored track with another.
  284. *
  285. * @param {JitsiLocalTrack|null} oldTrack - The track to dispose.
  286. * @param {JitsiLocalTrack|null} newTrack - The track to use instead.
  287. * @returns {Function}
  288. */
  289. function replaceStoredTracks(oldTrack, newTrack) {
  290. return dispatch => {
  291. // We call dispose after doing the replace because dispose will
  292. // try and do a new o/a after the track removes itself. Doing it
  293. // after means the JitsiLocalTrack.conference is already
  294. // cleared, so it won't try and do the o/a.
  295. const disposePromise
  296. = oldTrack
  297. ? dispatch(_disposeAndRemoveTracks([ oldTrack ]))
  298. : Promise.resolve();
  299. return disposePromise
  300. .then(() => {
  301. if (newTrack) {
  302. // The mute state of the new track should be
  303. // reflected in the app's mute state. For example,
  304. // if the app is currently muted and changing to a
  305. // new track that is not muted, the app's mute
  306. // state should be falsey. As such, emit a mute
  307. // event here to set up the app to reflect the
  308. // track's mute state. If this is not done, the
  309. // current mute state of the app will be reflected
  310. // on the track, not vice-versa.
  311. const setMuted
  312. = newTrack.isVideoTrack()
  313. ? setVideoMuted
  314. : setAudioMuted;
  315. const isMuted = newTrack.isMuted();
  316. sendAnalytics(createTrackMutedEvent(
  317. newTrack.getType(),
  318. 'track.replaced',
  319. isMuted));
  320. logger.log(`Replace ${newTrack.getType()} track - ${
  321. isMuted ? 'muted' : 'unmuted'}`);
  322. return dispatch(setMuted(isMuted));
  323. }
  324. })
  325. .then(() => {
  326. if (newTrack) {
  327. return dispatch(_addTracks([ newTrack ]));
  328. }
  329. });
  330. };
  331. }
  332. /**
  333. * Create an action for when a new track has been signaled to be added to the
  334. * conference.
  335. *
  336. * @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
  337. * @returns {{ type: TRACK_ADDED, track: Track }}
  338. */
  339. export function trackAdded(track) {
  340. return async (dispatch, getState) => {
  341. track.on(
  342. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  343. () => dispatch(trackMutedChanged(track)));
  344. track.on(
  345. JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED,
  346. type => dispatch(trackVideoTypeChanged(track, type)));
  347. // participantId
  348. const local = track.isLocal();
  349. const mediaType = track.getType();
  350. let isReceivingData, noDataFromSourceNotificationInfo, participantId;
  351. if (local) {
  352. // Reset the no data from src notification state when we change the track, as it's context is set
  353. // on a per device basis.
  354. dispatch(setNoSrcDataNotificationUid());
  355. const participant = getLocalParticipant(getState);
  356. if (participant) {
  357. participantId = participant.id;
  358. }
  359. isReceivingData = track.isReceivingData();
  360. track.on(JitsiTrackEvents.NO_DATA_FROM_SOURCE, () => dispatch(noDataFromSource({ jitsiTrack: track })));
  361. if (!isReceivingData) {
  362. if (mediaType === MEDIA_TYPE.AUDIO) {
  363. const notificationAction = await dispatch(showNotification({
  364. descriptionKey: 'dialog.micNotSendingData',
  365. titleKey: 'dialog.micNotSendingDataTitle'
  366. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  367. // Set the notification ID so that other parts of the application know that this was
  368. // displayed in the context of the current device.
  369. // I.E. The no-audio-signal notification shouldn't be displayed if this was already shown.
  370. dispatch(setNoSrcDataNotificationUid(notificationAction.uid));
  371. noDataFromSourceNotificationInfo = { uid: notificationAction.uid };
  372. } else {
  373. const timeout = setTimeout(() => dispatch(
  374. showNoDataFromSourceVideoError(track)),
  375. NOTIFICATION_TIMEOUT_TYPE.MEDIUM);
  376. noDataFromSourceNotificationInfo = { timeout };
  377. }
  378. }
  379. track.on(JitsiTrackEvents.LOCAL_TRACK_STOPPED,
  380. () => dispatch({
  381. type: TRACK_STOPPED,
  382. track: {
  383. jitsiTrack: track
  384. }
  385. }));
  386. } else {
  387. participantId = track.getParticipantId();
  388. isReceivingData = true;
  389. }
  390. return dispatch({
  391. type: TRACK_ADDED,
  392. track: {
  393. jitsiTrack: track,
  394. isReceivingData,
  395. local,
  396. mediaType,
  397. mirror: _shouldMirror(track),
  398. muted: track.isMuted(),
  399. noDataFromSourceNotificationInfo,
  400. participantId,
  401. videoStarted: false,
  402. videoType: track.videoType
  403. }
  404. });
  405. };
  406. }
  407. /**
  408. * Create an action for when a track's muted state has been signaled to be
  409. * changed.
  410. *
  411. * @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
  412. * @returns {{
  413. * type: TRACK_UPDATED,
  414. * track: Track
  415. * }}
  416. */
  417. export function trackMutedChanged(track) {
  418. return {
  419. type: TRACK_UPDATED,
  420. track: {
  421. jitsiTrack: track,
  422. muted: track.isMuted()
  423. }
  424. };
  425. }
  426. /**
  427. * Create an action for when a track's no data from source notification information changes.
  428. *
  429. * @param {JitsiLocalTrack} track - JitsiTrack instance.
  430. * @param {Object} noDataFromSourceNotificationInfo - Information about no data from source notification.
  431. * @returns {{
  432. * type: TRACK_UPDATED,
  433. * track: Track
  434. * }}
  435. */
  436. export function trackNoDataFromSourceNotificationInfoChanged(track, noDataFromSourceNotificationInfo) {
  437. return {
  438. type: TRACK_UPDATED,
  439. track: {
  440. jitsiTrack: track,
  441. noDataFromSourceNotificationInfo
  442. }
  443. };
  444. }
  445. /**
  446. * Create an action for when a track has been signaled for removal from the
  447. * conference.
  448. *
  449. * @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
  450. * @returns {{
  451. * type: TRACK_REMOVED,
  452. * track: Track
  453. * }}
  454. */
  455. export function trackRemoved(track) {
  456. track.removeAllListeners(JitsiTrackEvents.TRACK_MUTE_CHANGED);
  457. track.removeAllListeners(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED);
  458. track.removeAllListeners(JitsiTrackEvents.NO_DATA_FROM_SOURCE);
  459. return {
  460. type: TRACK_REMOVED,
  461. track: {
  462. jitsiTrack: track
  463. }
  464. };
  465. }
  466. /**
  467. * Signal that track's video started to play.
  468. *
  469. * @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
  470. * @returns {{
  471. * type: TRACK_UPDATED,
  472. * track: Track
  473. * }}
  474. */
  475. export function trackVideoStarted(track) {
  476. return {
  477. type: TRACK_UPDATED,
  478. track: {
  479. jitsiTrack: track,
  480. videoStarted: true
  481. }
  482. };
  483. }
  484. /**
  485. * Create an action for when participant video type changes.
  486. *
  487. * @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
  488. * @param {VIDEO_TYPE|undefined} videoType - Video type.
  489. * @returns {{
  490. * type: TRACK_UPDATED,
  491. * track: Track
  492. * }}
  493. */
  494. export function trackVideoTypeChanged(track, videoType) {
  495. return {
  496. type: TRACK_UPDATED,
  497. track: {
  498. jitsiTrack: track,
  499. videoType
  500. }
  501. };
  502. }
  503. /**
  504. * Signals passed tracks to be added.
  505. *
  506. * @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} tracks - List of tracks.
  507. * @private
  508. * @returns {Function}
  509. */
  510. function _addTracks(tracks) {
  511. return dispatch => Promise.all(tracks.map(t => dispatch(trackAdded(t))));
  512. }
  513. /**
  514. * Cancels and waits for any {@code getUserMedia} process/currently in progress
  515. * to complete/settle.
  516. *
  517. * @param {Function} getState - The redux store {@code getState} function used
  518. * to obtain the state.
  519. * @private
  520. * @returns {Promise} - A {@code Promise} resolved once all
  521. * {@code gumProcess.cancel()} {@code Promise}s are settled because all we care
  522. * about here is to be sure that the {@code getUserMedia} callbacks have
  523. * completed (i.e. Returned from the native side).
  524. */
  525. function _cancelGUMProcesses(getState) {
  526. const logError
  527. = error =>
  528. logger.error('gumProcess.cancel failed', JSON.stringify(error));
  529. return Promise.all(
  530. getState()['features/base/tracks']
  531. .filter(t => t.local)
  532. .map(({ gumProcess }) =>
  533. gumProcess && gumProcess.cancel().catch(logError)));
  534. }
  535. /**
  536. * Disposes passed tracks and signals them to be removed.
  537. *
  538. * @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} tracks - List of tracks.
  539. * @protected
  540. * @returns {Function}
  541. */
  542. export function _disposeAndRemoveTracks(tracks) {
  543. return dispatch =>
  544. _disposeTracks(tracks)
  545. .then(() =>
  546. Promise.all(tracks.map(t => dispatch(trackRemoved(t)))));
  547. }
  548. /**
  549. * Disposes passed tracks.
  550. *
  551. * @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} tracks - List of tracks.
  552. * @private
  553. * @returns {Promise} - A Promise resolved once {@link JitsiTrack.dispose()} is
  554. * done for every track from the list.
  555. */
  556. function _disposeTracks(tracks) {
  557. return Promise.all(
  558. tracks.map(t =>
  559. t.dispose()
  560. .catch(err => {
  561. // Track might be already disposed so ignore such an error.
  562. // Of course, re-throw any other error(s).
  563. if (err.name !== JitsiTrackErrors.TRACK_IS_DISPOSED) {
  564. throw err;
  565. }
  566. })));
  567. }
  568. /**
  569. * Implements the {@code Promise} rejection handler of
  570. * {@code createLocalTracksA} and {@code createLocalTracksF}.
  571. *
  572. * @param {Object} error - The {@code Promise} rejection reason.
  573. * @param {string} device - The device/{@code MEDIA_TYPE} associated with the
  574. * rejection.
  575. * @private
  576. * @returns {Function}
  577. */
  578. function _onCreateLocalTracksRejected(error, device) {
  579. return dispatch => {
  580. // If permissions are not allowed, alert the user.
  581. dispatch({
  582. type: TRACK_CREATE_ERROR,
  583. permissionDenied: error?.name === 'SecurityError',
  584. trackType: device
  585. });
  586. };
  587. }
  588. /**
  589. * Returns true if the provided {@code JitsiTrack} should be rendered as a
  590. * mirror.
  591. *
  592. * We only want to show a video in mirrored mode when:
  593. * 1) The video source is local, and not remote.
  594. * 2) The video source is a camera, not a desktop (capture).
  595. * 3) The camera is capturing the user, not the environment.
  596. *
  597. * TODO Similar functionality is part of lib-jitsi-meet. This function should be
  598. * removed after https://github.com/jitsi/lib-jitsi-meet/pull/187 is merged.
  599. *
  600. * @param {(JitsiLocalTrack|JitsiRemoteTrack)} track - JitsiTrack instance.
  601. * @private
  602. * @returns {boolean}
  603. */
  604. function _shouldMirror(track) {
  605. return (
  606. track
  607. && track.isLocal()
  608. && track.isVideoTrack()
  609. // XXX The type of the return value of JitsiLocalTrack's
  610. // getCameraFacingMode happens to be named CAMERA_FACING_MODE as
  611. // well, it's defined by lib-jitsi-meet. Note though that the type
  612. // of the value on the right side of the equality check is defined
  613. // by jitsi-meet. The type definitions are surely compatible today
  614. // but that may not be the case tomorrow.
  615. && track.getCameraFacingMode() === CAMERA_FACING_MODE.USER);
  616. }
  617. /**
  618. * Signals that track create operation for given media track has been canceled.
  619. * Will clean up local track stub from the redux state which holds the
  620. * {@code gumProcess} reference.
  621. *
  622. * @param {MEDIA_TYPE} mediaType - The type of the media for which the track was
  623. * being created.
  624. * @private
  625. * @returns {{
  626. * type,
  627. * trackType: MEDIA_TYPE
  628. * }}
  629. */
  630. function _trackCreateCanceled(mediaType) {
  631. return {
  632. type: TRACK_CREATE_CANCELED,
  633. trackType: mediaType
  634. };
  635. }
  636. /**
  637. * If thee local track if of type Desktop, it calls _disposeAndRemoveTracks) on it.
  638. *
  639. * @returns {Function}
  640. */
  641. export function destroyLocalDesktopTrackIfExists() {
  642. return (dispatch, getState) => {
  643. const videoTrack = getLocalVideoTrack(getState()['features/base/tracks']);
  644. const isDesktopTrack = videoTrack && videoTrack.videoType === VIDEO_TYPE.DESKTOP;
  645. if (isDesktopTrack) {
  646. dispatch(_disposeAndRemoveTracks([ videoTrack.jitsiTrack ]));
  647. }
  648. };
  649. }
  650. /**
  651. * Sets UID of the displayed no data from source notification. Used to track
  652. * if the notification was previously displayed in this context.
  653. *
  654. * @param {number} uid - Notification UID.
  655. * @returns {{
  656. * type: SET_NO_AUDIO_SIGNAL_UID,
  657. * uid: number
  658. * }}
  659. */
  660. export function setNoSrcDataNotificationUid(uid) {
  661. return {
  662. type: SET_NO_SRC_DATA_NOTIFICATION_UID,
  663. uid
  664. };
  665. }
  666. /**
  667. * Updates the last media event received for a video track.
  668. *
  669. * @param {JitsiRemoteTrack} track - JitsiTrack instance.
  670. * @param {string} name - The current media event name for the video.
  671. * @returns {{
  672. * type: TRACK_UPDATE_LAST_VIDEO_MEDIA_EVENT,
  673. * track: Track,
  674. * name: string
  675. * }}
  676. */
  677. export function updateLastTrackVideoMediaEvent(track, name) {
  678. return {
  679. type: TRACK_UPDATE_LAST_VIDEO_MEDIA_EVENT,
  680. track,
  681. name
  682. };
  683. }
  684. /**
  685. * Toggles the facingMode constraint on the video stream.
  686. *
  687. * @returns {Function}
  688. */
  689. export function toggleCamera() {
  690. return async (dispatch, getState) => {
  691. const state = getState();
  692. const tracks = state['features/base/tracks'];
  693. const localVideoTrack = getLocalVideoTrack(tracks).jitsiTrack;
  694. const currentFacingMode = localVideoTrack.getCameraFacingMode();
  695. /**
  696. * FIXME: Ideally, we should be dispatching {@code replaceLocalTrack} here,
  697. * but it seems to not trigger the re-rendering of the local video on Chrome;
  698. * could be due to a plan B vs unified plan issue. Therefore, we use the legacy
  699. * method defined in conference.js that manually takes care of updating the local
  700. * video as well.
  701. */
  702. await APP.conference.useVideoStream(null);
  703. const targetFacingMode = currentFacingMode === CAMERA_FACING_MODE.USER
  704. ? CAMERA_FACING_MODE.ENVIRONMENT
  705. : CAMERA_FACING_MODE.USER;
  706. // Update the flipX value so the environment facing camera is not flipped, before the new track is created.
  707. dispatch(updateSettings({ localFlipX: targetFacingMode === CAMERA_FACING_MODE.USER }));
  708. const newVideoTrack = await createLocalTrack('video', null, null, { facingMode: targetFacingMode });
  709. // FIXME: See above.
  710. await APP.conference.useVideoStream(newVideoTrack);
  711. };
  712. }