Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.native.ts 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { IReduxState, IStore } from '../../app/types';
  2. import { showNotification } from '../../notifications/actions';
  3. import { NOTIFICATION_TIMEOUT_TYPE } from '../../notifications/constants';
  4. import JitsiMeetJS from '../lib-jitsi-meet';
  5. import { setScreenshareMuted } from '../media/actions';
  6. import { addLocalTrack, replaceLocalTrack } from './actions.any';
  7. import { getLocalDesktopTrack, getTrackState } from './functions.native';
  8. export * from './actions.any';
  9. /**
  10. * Signals that the local participant is ending screensharing or beginning the screensharing flow.
  11. *
  12. * @param {boolean} enabled - The state to toggle screen sharing to.
  13. * @param {boolean} _ignore1 - Ignored.
  14. * @param {any} _ignore2 - Ignored.
  15. * @returns {Function}
  16. */
  17. export function toggleScreensharing(enabled: boolean, _ignore1?: boolean, _ignore2?: any) {
  18. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  19. const state = getState();
  20. if (enabled) {
  21. _startScreenSharing(dispatch, state);
  22. } else {
  23. dispatch(setScreenshareMuted(true));
  24. }
  25. };
  26. }
  27. /**
  28. * Creates desktop track and replaces the local one.
  29. *
  30. * @private
  31. * @param {Dispatch} dispatch - The redux {@code dispatch} function.
  32. * @param {Object} state - The redux state.
  33. * @returns {void}
  34. */
  35. async function _startScreenSharing(dispatch: IStore['dispatch'], state: IReduxState) {
  36. try {
  37. const tracks: any[] = await JitsiMeetJS.createLocalTracks({ devices: [ 'desktop' ] });
  38. const track = tracks[0];
  39. const currentLocalDesktopTrack = getLocalDesktopTrack(getTrackState(state));
  40. const currentJitsiTrack = currentLocalDesktopTrack?.jitsiTrack;
  41. // The first time the user shares the screen we add the track and create the transceiver.
  42. // Afterwards, we just replace the old track, so the transceiver will be reused.
  43. if (currentJitsiTrack) {
  44. dispatch(replaceLocalTrack(currentJitsiTrack, track));
  45. } else {
  46. dispatch(addLocalTrack(track));
  47. }
  48. const { enabled: audioOnly } = state['features/base/audio-only'];
  49. if (audioOnly) {
  50. dispatch(showNotification({
  51. titleKey: 'notify.screenSharingAudioOnlyTitle',
  52. descriptionKey: 'notify.screenSharingAudioOnlyDescription',
  53. maxLines: 3
  54. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  55. }
  56. } catch (error: any) {
  57. console.log('ERROR creating screen-sharing stream ', error);
  58. }
  59. }