You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.native.ts 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* eslint-disable lines-around-comment */
  2. import { IReduxState, IStore } from '../../app/types';
  3. // @ts-ignore
  4. import { setPictureInPictureEnabled } from '../../mobile/picture-in-picture/functions';
  5. import { setAudioOnly } from '../audio-only/actions';
  6. import JitsiMeetJS from '../lib-jitsi-meet';
  7. import { destroyLocalDesktopTrackIfExists, replaceLocalTrack } from './actions.any';
  8. import { getLocalVideoTrack, isLocalVideoTrackDesktop } from './functions';
  9. /* eslint-enable lines-around-comment */
  10. export * from './actions.any';
  11. /**
  12. * Signals that the local participant is ending screensharing or beginning the screensharing flow.
  13. *
  14. * @param {boolean} enabled - The state to toggle screen sharing to.
  15. * @returns {Function}
  16. */
  17. export function toggleScreensharing(enabled: boolean) {
  18. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  19. const state = getState();
  20. if (enabled) {
  21. const isSharing = isLocalVideoTrackDesktop(state);
  22. if (!isSharing) {
  23. _startScreenSharing(dispatch, state);
  24. }
  25. } else {
  26. dispatch(destroyLocalDesktopTrackIfExists());
  27. setPictureInPictureEnabled(true);
  28. }
  29. };
  30. }
  31. /**
  32. * Creates desktop track and replaces the local one.
  33. *
  34. * @private
  35. * @param {Dispatch} dispatch - The redux {@code dispatch} function.
  36. * @param {Object} state - The redux state.
  37. * @returns {void}
  38. */
  39. function _startScreenSharing(dispatch: Function, state: IReduxState) {
  40. setPictureInPictureEnabled(false);
  41. JitsiMeetJS.createLocalTracks({ devices: [ 'desktop' ] })
  42. .then((tracks: any[]) => {
  43. const track = tracks[0];
  44. const currentLocalTrack = getLocalVideoTrack(state['features/base/tracks']);
  45. const currentJitsiTrack = currentLocalTrack?.jitsiTrack;
  46. dispatch(replaceLocalTrack(currentJitsiTrack, track));
  47. const { enabled: audioOnly } = state['features/base/audio-only'];
  48. if (audioOnly) {
  49. dispatch(setAudioOnly(false));
  50. }
  51. })
  52. .catch((error: any) => {
  53. console.log('ERROR creating ScreeSharing stream ', error);
  54. setPictureInPictureEnabled(true);
  55. });
  56. }