mirror of https://github.com/jitsi/jitsi-meet
Co-authored-by: Saúl Ibarra Corretgé <saghul@jitsi.org> Co-authored-by: zycwind <391321232@qq.com>pull/8039/head
parent
9742e90bb5
commit
9a35026d6a
@ -0,0 +1,74 @@ |
||||
// @flow
|
||||
|
||||
import { setPictureInPictureDisabled } from '../../mobile/picture-in-picture/functions'; |
||||
import { setAudioOnly } from '../audio-only'; |
||||
import JitsiMeetJS from '../lib-jitsi-meet'; |
||||
import { MiddlewareRegistry } from '../redux'; |
||||
import { TOGGLE_SCREENSHARING } from '../tracks/actionTypes'; |
||||
import { destroyLocalDesktopTrackIfExists, replaceLocalTrack } from '../tracks/actions'; |
||||
import { getLocalVideoTrack, isLocalVideoTrackDesktop } from '../tracks/functions'; |
||||
|
||||
import './middleware.any'; |
||||
|
||||
MiddlewareRegistry.register(store => next => action => { |
||||
switch (action.type) { |
||||
case TOGGLE_SCREENSHARING: { |
||||
_toggleScreenSharing(store); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return next(action); |
||||
}); |
||||
|
||||
/** |
||||
* Toggles screen sharing. |
||||
* |
||||
* @private |
||||
* @param {Store} store - The redux. |
||||
* @returns {void} |
||||
*/ |
||||
function _toggleScreenSharing(store) { |
||||
const { dispatch, getState } = store; |
||||
const state = getState(); |
||||
|
||||
const isSharing = isLocalVideoTrackDesktop(state); |
||||
|
||||
if (isSharing) { |
||||
dispatch(destroyLocalDesktopTrackIfExists()); |
||||
} else { |
||||
_startScreenSharing(dispatch, state); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Creates desktop track and replaces the local one. |
||||
* |
||||
* @private |
||||
* @param {Dispatch} dispatch - The redux {@code dispatch} function. |
||||
* @param {Object} state - The redux state. |
||||
* @returns {void} |
||||
*/ |
||||
function _startScreenSharing(dispatch, state) { |
||||
setPictureInPictureDisabled(true); |
||||
|
||||
JitsiMeetJS.createLocalTracks({ devices: [ 'desktop' ] }) |
||||
.then(tracks => { |
||||
const track = tracks[0]; |
||||
const currentLocalTrack = getLocalVideoTrack(state['features/base/tracks']); |
||||
const currentJitsiTrack = currentLocalTrack && currentLocalTrack.jitsiTrack; |
||||
|
||||
dispatch(replaceLocalTrack(currentJitsiTrack, track)); |
||||
|
||||
const { enabled: audioOnly } = state['features/base/audio-only']; |
||||
|
||||
if (audioOnly) { |
||||
dispatch(setAudioOnly(false)); |
||||
} |
||||
}) |
||||
.catch(error => { |
||||
console.log('ERROR creating ScreeSharing stream ', error); |
||||
|
||||
setPictureInPictureDisabled(false); |
||||
}); |
||||
} |
@ -0,0 +1,23 @@ |
||||
// @flow
|
||||
|
||||
import UIEvents from '../../../../service/UI/UIEvents'; |
||||
import { MiddlewareRegistry } from '../redux'; |
||||
import { TOGGLE_SCREENSHARING } from '../tracks/actionTypes'; |
||||
|
||||
import './middleware.any'; |
||||
|
||||
declare var APP: Object; |
||||
|
||||
MiddlewareRegistry.register((/* store */) => next => action => { |
||||
switch (action.type) { |
||||
case TOGGLE_SCREENSHARING: { |
||||
if (typeof APP === 'object') { |
||||
APP.UI.emitEvent(UIEvents.TOGGLE_SCREENSHARING); |
||||
} |
||||
|
||||
break; |
||||
} |
||||
} |
||||
|
||||
return next(action); |
||||
}); |
@ -0,0 +1,15 @@ |
||||
// @flow
|
||||
|
||||
import { NativeModules } from 'react-native'; |
||||
|
||||
/** |
||||
* Enabled/Disables the PictureInPicture mode in PiP native module. |
||||
* |
||||
* @param {boolean} disabled - Whether the PiP mode should be disabled. |
||||
* @returns {void} |
||||
*/ |
||||
export function setPictureInPictureDisabled(disabled: boolean) { |
||||
const { PictureInPicture } = NativeModules; |
||||
|
||||
PictureInPicture.setPictureInPictureDisabled(disabled); |
||||
} |
@ -1,3 +1,4 @@ |
||||
export * from './actions'; |
||||
export * from './actionTypes'; |
||||
export * from './components'; |
||||
export * from './functions'; |
||||
|
@ -0,0 +1,77 @@ |
||||
// @flow
|
||||
|
||||
import { Platform } from 'react-native'; |
||||
|
||||
import { translate } from '../../../base/i18n'; |
||||
import { IconShareDesktop } from '../../../base/icons'; |
||||
import { connect } from '../../../base/redux'; |
||||
import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components'; |
||||
import { toggleScreensharing, isLocalVideoTrackDesktop } from '../../../base/tracks'; |
||||
|
||||
/** |
||||
* The type of the React {@code Component} props of {@link ScreenSharingButton}. |
||||
*/ |
||||
type Props = AbstractButtonProps & { |
||||
|
||||
/** |
||||
* Whether video is currently muted or not. |
||||
*/ |
||||
_screensharing: boolean, |
||||
|
||||
/** |
||||
* The redux {@code dispatch} function. |
||||
*/ |
||||
dispatch: Function |
||||
}; |
||||
|
||||
/** |
||||
* An implementation of a button for toggling screen sharing. |
||||
*/ |
||||
class ScreenSharingButton extends AbstractButton<Props, *> { |
||||
accessibilityLabel = 'toolbar.accessibilityLabel.shareYourScreen'; |
||||
icon = IconShareDesktop; |
||||
label = 'toolbar.startScreenSharing'; |
||||
toggledLabel = 'toolbar.stopScreenSharing'; |
||||
|
||||
/** |
||||
* Handles clicking / pressing the button. |
||||
* |
||||
* @override |
||||
* @protected |
||||
* @returns {void} |
||||
*/ |
||||
_handleClick() { |
||||
this.props.dispatch(toggleScreensharing()); |
||||
} |
||||
|
||||
/** |
||||
* Indicates whether this button is in toggled state or not. |
||||
* |
||||
* @override |
||||
* @protected |
||||
* @returns {boolean} |
||||
*/ |
||||
_isToggled() { |
||||
return this.props._screensharing; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Maps (parts of) the redux state to the associated props for the |
||||
* {@code ToggleCameraButton} component. |
||||
* |
||||
* @param {Object} state - The Redux state. |
||||
* @private |
||||
* @returns {{ |
||||
* _disabled: boolean, |
||||
* _screensharing: boolean |
||||
* }} |
||||
*/ |
||||
function _mapStateToProps(state): Object { |
||||
return { |
||||
_screensharing: isLocalVideoTrackDesktop(state), |
||||
visible: Platform.OS === 'android' |
||||
}; |
||||
} |
||||
|
||||
export default translate(connect(_mapStateToProps)(ScreenSharingButton)); |
Loading…
Reference in new issue