您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 23KB

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