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

actions.js 25KB

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