123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- // @flow
-
- import {
- ADD_PREJOIN_AUDIO_TRACK,
- ADD_PREJOIN_CONTENT_SHARING_TRACK,
- ADD_PREJOIN_VIDEO_TRACK,
- PREJOIN_START_CONFERENCE,
- SET_DEVICE_STATUS,
- SET_JOIN_BY_PHONE_DIALOG_VISIBLITY,
- SET_PREJOIN_AUDIO_DISABLED,
- SET_PREJOIN_AUDIO_MUTED,
- SET_PREJOIN_DEVICE_ERRORS,
- SET_PREJOIN_NAME,
- SET_PREJOIN_PAGE_VISIBILITY,
- SET_PREJOIN_VIDEO_DISABLED,
- SET_PREJOIN_VIDEO_MUTED
- } from './actionTypes';
- import { createLocalTrack } from '../base/lib-jitsi-meet';
- import { getAudioTrack, getVideoTrack } from './functions';
- import logger from './logger';
-
- /**
- * Action used to add an audio track to the store.
- *
- * @param {Object} value - The track to be added.
- * @returns {Object}
- */
- export function addPrejoinAudioTrack(value: Object) {
- return {
- type: ADD_PREJOIN_AUDIO_TRACK,
- value
- };
- }
-
- /**
- * Action used to add a video track to the store.
- *
- * @param {Object} value - The track to be added.
- * @returns {Object}
- */
- export function addPrejoinVideoTrack(value: Object) {
- return {
- type: ADD_PREJOIN_VIDEO_TRACK,
- value
- };
- }
-
- /**
- * Action used to add a content sharing track to the store.
- *
- * @param {Object} value - The track to be added.
- * @returns {Object}
- */
- export function addPrejoinContentSharingTrack(value: Object) {
- return {
- type: ADD_PREJOIN_CONTENT_SHARING_TRACK,
- value
- };
- }
-
- /**
- * Adds all the newly created tracks to store on init.
- *
- * @param {Object[]} tracks - The newly created tracks.
- * @param {Object} errors - The errors from creating the tracks.
- *
- * @returns {Function}
- */
- export function initPrejoin(tracks: Object[], errors: Object) {
- return async function(dispatch: Function) {
- const audioTrack = tracks.find(t => t.isAudioTrack());
- const videoTrack = tracks.find(t => t.isVideoTrack());
-
- dispatch(setPrejoinDeviceErrors(errors));
-
- if (audioTrack) {
- dispatch(addPrejoinAudioTrack(audioTrack));
- } else {
- dispatch(setAudioDisabled());
- }
-
- if (videoTrack) {
- if (videoTrack.videoType === 'desktop') {
- dispatch(addPrejoinContentSharingTrack(videoTrack));
- dispatch(setPrejoinVideoDisabled(true));
- } else {
- dispatch(addPrejoinVideoTrack(videoTrack));
- }
- } else {
- dispatch(setPrejoinVideoDisabled(true));
- }
- };
- }
-
- /**
- * Joins the conference.
- *
- * @returns {Function}
- */
- export function joinConference() {
- return function(dispatch: Function) {
- dispatch(setPrejoinPageVisibility(false));
- dispatch(startConference());
- };
- }
-
- /**
- * Joins the conference without audio.
- *
- * @returns {Function}
- */
- export function joinConferenceWithoutAudio() {
- return async function(dispatch: Function, getState: Function) {
- const audioTrack = getAudioTrack(getState());
-
- if (audioTrack) {
- await dispatch(replacePrejoinAudioTrack(null));
- }
- dispatch(setAudioDisabled());
- dispatch(joinConference());
- };
- }
-
- /**
- * Replaces the existing audio track with a new one.
- *
- * @param {Object} track - The new track.
- * @returns {Function}
- */
- export function replacePrejoinAudioTrack(track: Object) {
- return async (dispatch: Function, getState: Function) => {
- const oldTrack = getAudioTrack(getState());
-
- oldTrack && await oldTrack.dispose();
- dispatch(addPrejoinAudioTrack(track));
- };
- }
-
- /**
- * Creates a new audio track based on a device id and replaces the current one.
- *
- * @param {string} deviceId - The deviceId of the microphone.
- * @returns {Function}
- */
- export function replaceAudioTrackById(deviceId: string) {
- return async (dispatch: Function) => {
- try {
- const track = await createLocalTrack('audio', deviceId);
-
- dispatch(replacePrejoinAudioTrack(track));
- } catch (err) {
- dispatch(setDeviceStatusWarning('prejoin.audioTrackError'));
- logger.log('Error replacing audio track', err);
- }
- };
- }
-
- /**
- * Replaces the existing video track with a new one.
- *
- * @param {Object} track - The new track.
- * @returns {Function}
- */
- export function replacePrejoinVideoTrack(track: Object) {
- return async (dispatch: Function, getState: Function) => {
- const oldTrack = getVideoTrack(getState());
-
- oldTrack && await oldTrack.dispose();
- dispatch(addPrejoinVideoTrack(track));
- };
- }
-
- /**
- * Creates a new video track based on a device id and replaces the current one.
- *
- * @param {string} deviceId - The deviceId of the camera.
- * @returns {Function}
- */
- export function replaceVideoTrackById(deviceId: Object) {
- return async (dispatch: Function) => {
- try {
- const track = await createLocalTrack('video', deviceId);
-
- dispatch(replacePrejoinVideoTrack(track));
- } catch (err) {
- dispatch(setDeviceStatusWarning('prejoin.videoTrackError'));
- logger.log('Error replacing video track', err);
- }
- };
- }
-
-
- /**
- * Action used to mark audio muted.
- *
- * @param {boolean} value - True for muted.
- * @returns {Object}
- */
- export function setPrejoinAudioMuted(value: boolean) {
- return {
- type: SET_PREJOIN_AUDIO_MUTED,
- value
- };
- }
-
- /**
- * Action used to mark video disabled.
- *
- * @param {boolean} value - True for muted.
- * @returns {Object}
- */
- export function setPrejoinVideoDisabled(value: boolean) {
- return {
- type: SET_PREJOIN_VIDEO_DISABLED,
- value
- };
- }
-
-
- /**
- * Action used to mark video muted.
- *
- * @param {boolean} value - True for muted.
- * @returns {Object}
- */
- export function setPrejoinVideoMuted(value: boolean) {
- return {
- type: SET_PREJOIN_VIDEO_MUTED,
- value
- };
- }
-
- /**
- * Action used to mark audio as disabled.
- *
- * @returns {Object}
- */
- export function setAudioDisabled() {
- return {
- type: SET_PREJOIN_AUDIO_DISABLED
- };
- }
-
- /**
- * Sets the device status as OK with the corresponding text.
- *
- * @param {string} deviceStatusText - The text to be set.
- * @returns {Object}
- */
- export function setDeviceStatusOk(deviceStatusText: string) {
- return {
- type: SET_DEVICE_STATUS,
- value: {
- deviceStatusText,
- deviceStatusType: 'ok'
- }
- };
- }
-
- /**
- * Sets the device status as 'warning' with the corresponding text.
- *
- * @param {string} deviceStatusText - The text to be set.
- * @returns {Object}
- */
- export function setDeviceStatusWarning(deviceStatusText: string) {
- return {
- type: SET_DEVICE_STATUS,
- value: {
- deviceStatusText,
- deviceStatusType: 'warning'
- }
- };
- }
-
-
- /**
- * Action used to set the visiblitiy of the 'JoinByPhoneDialog'.
- *
- * @param {boolean} value - The value.
- * @returns {Object}
- */
- export function setJoinByPhoneDialogVisiblity(value: boolean) {
- return {
- type: SET_JOIN_BY_PHONE_DIALOG_VISIBLITY,
- value
- };
- }
-
- /**
- * Action used to set the initial errors after creating the tracks.
- *
- * @param {Object} value - The track errors.
- * @returns {Object}
- */
- export function setPrejoinDeviceErrors(value: Object) {
- return {
- type: SET_PREJOIN_DEVICE_ERRORS,
- value
- };
- }
-
- /**
- * Action used to set the name of the guest user.
- *
- * @param {string} value - The name.
- * @returns {Object}
- */
- export function setPrejoinName(value: string) {
- return {
- type: SET_PREJOIN_NAME,
- value
- };
- }
-
- /**
- * Action used to set the visiblity of the prejoin page.
- *
- * @param {boolean} value - The value.
- * @returns {Object}
- */
- export function setPrejoinPageVisibility(value: boolean) {
- return {
- type: SET_PREJOIN_PAGE_VISIBILITY,
- value
- };
- }
-
- /**
- * Action used to mark the start of the conference.
- *
- * @returns {Object}
- */
- function startConference() {
- return {
- type: PREJOIN_START_CONFERENCE
- };
- }
|