127 lines
3.4 KiB
TypeScript
127 lines
3.4 KiB
TypeScript
import { IStore } from '../app/types';
|
|
import { getCurrentConference } from '../base/conference/functions';
|
|
import { openDialog } from '../base/dialog/actions';
|
|
import { getLocalParticipant } from '../base/participants/functions';
|
|
|
|
import { RESET_SHARED_VIDEO_STATUS, SET_SHARED_VIDEO_STATUS } from './actionTypes';
|
|
// eslint-disable-next-line lines-around-comment
|
|
// @ts-ignore
|
|
import { SharedVideoDialog } from './components';
|
|
|
|
/**
|
|
* Resets the status of the shared video.
|
|
*
|
|
* @returns {{
|
|
* type: SET_SHARED_VIDEO_STATUS,
|
|
* }}
|
|
*/
|
|
export function resetSharedVideoStatus() {
|
|
return {
|
|
type: RESET_SHARED_VIDEO_STATUS
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Updates the current known status of the shared video.
|
|
*
|
|
* @param {Object} options - The options.
|
|
* @param {boolean} options.muted - Is video muted.
|
|
* @param {boolean} options.ownerId - Participant ID of the owner.
|
|
* @param {boolean} options.status - Sharing status.
|
|
* @param {boolean} options.time - Playback timestamp.
|
|
* @param {boolean} options.videoUrl - URL of the shared video.
|
|
*
|
|
* @returns {{
|
|
* type: SET_SHARED_VIDEO_STATUS,
|
|
* muted: boolean,
|
|
* ownerId: string,
|
|
* status: string,
|
|
* time: number,
|
|
* videoUrl: string,
|
|
* }}
|
|
*/
|
|
export function setSharedVideoStatus({ videoUrl, status, time, ownerId, muted }: {
|
|
muted?: boolean; ownerId?: string; status: string; time: number; videoUrl: string;
|
|
}) {
|
|
return {
|
|
type: SET_SHARED_VIDEO_STATUS,
|
|
ownerId,
|
|
status,
|
|
time,
|
|
videoUrl,
|
|
muted
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Displays the dialog for entering the video link.
|
|
*
|
|
* @param {Function} onPostSubmit - The function to be invoked when a valid link is entered.
|
|
* @returns {Function}
|
|
*/
|
|
export function showSharedVideoDialog(onPostSubmit: Function) {
|
|
return openDialog(SharedVideoDialog, { onPostSubmit });
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Stops playing a shared video.
|
|
*
|
|
* @returns {Function}
|
|
*/
|
|
export function stopSharedVideo() {
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
|
const state = getState();
|
|
const { ownerId } = state['features/shared-video'];
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
if (ownerId === localParticipant?.id) {
|
|
dispatch(resetSharedVideoStatus());
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Plays a shared video.
|
|
*
|
|
* @param {string} videoUrl - The video url to be played.
|
|
*
|
|
* @returns {Function}
|
|
*/
|
|
export function playSharedVideo(videoUrl: string) {
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
|
const conference = getCurrentConference(getState());
|
|
|
|
if (conference) {
|
|
const localParticipant = getLocalParticipant(getState());
|
|
|
|
dispatch(setSharedVideoStatus({
|
|
videoUrl,
|
|
status: 'start',
|
|
time: 0,
|
|
ownerId: localParticipant?.id
|
|
}));
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Stops playing a shared video.
|
|
*
|
|
* @returns {Function}
|
|
*/
|
|
export function toggleSharedVideo() {
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
|
const state = getState();
|
|
const { status = '' } = state['features/shared-video'];
|
|
|
|
if ([ 'playing', 'start', 'pause' ].includes(status)) {
|
|
dispatch(stopSharedVideo());
|
|
} else {
|
|
dispatch(showSharedVideoDialog((id: string) => dispatch(playSharedVideo(id))));
|
|
}
|
|
};
|
|
}
|