123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- import { ReducerRegistry } from '../base/redux';
-
- import {
- ADD_PREJOIN_AUDIO_TRACK,
- ADD_PREJOIN_CONTENT_SHARING_TRACK,
- ADD_PREJOIN_VIDEO_TRACK,
- 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';
-
- const DEFAULT_STATE = {
- audioDisabled: false,
- audioMuted: false,
- videoMuted: false,
- videoDisabled: false,
- deviceStatusText: 'prejoin.configuringDevices',
- deviceStatusType: 'ok',
- showPrejoin: true,
- showJoinByPhoneDialog: false,
- videoTrack: null,
- audioTrack: null,
- contentSharingTrack: null,
- rawError: '',
- name: ''
- };
-
- /**
- * Listen for actions that mutate the prejoin state
- */
- ReducerRegistry.register(
- 'features/prejoin', (state = DEFAULT_STATE, action) => {
- switch (action.type) {
- case ADD_PREJOIN_AUDIO_TRACK: {
- return {
- ...state,
- audioTrack: action.value
- };
- }
-
- case ADD_PREJOIN_CONTENT_SHARING_TRACK: {
- return {
- ...state,
- contentSharingTrack: action.value
- };
- }
-
- case ADD_PREJOIN_VIDEO_TRACK: {
- return {
- ...state,
- videoTrack: action.value
- };
- }
-
- case SET_PREJOIN_NAME: {
- return {
- ...state,
- name: action.value
- };
- }
-
- case SET_PREJOIN_PAGE_VISIBILITY:
- return {
- ...state,
- showPrejoin: action.value
- };
-
- case SET_PREJOIN_VIDEO_DISABLED: {
- return {
- ...state,
- videoDisabled: action.value
- };
- }
-
- case SET_PREJOIN_VIDEO_MUTED:
- return {
- ...state,
- videoMuted: action.value
- };
-
- case SET_PREJOIN_AUDIO_MUTED:
- return {
- ...state,
- audioMuted: action.value
- };
-
- case SET_PREJOIN_DEVICE_ERRORS: {
- const status = getStatusFromErrors(action.value);
-
- return {
- ...state,
- ...status
- };
- }
-
- case SET_DEVICE_STATUS: {
- return {
- ...state,
- deviceStatusText: action.text,
- deviceStatusType: action.type
- };
- }
-
- case SET_PREJOIN_AUDIO_DISABLED: {
- return {
- ...state,
- audioDisabled: true
- };
- }
-
- case SET_JOIN_BY_PHONE_DIALOG_VISIBLITY: {
- return {
- ...state,
- showJoinByPhoneDialog: action.value
- };
- }
-
- default:
- return state;
- }
- },
- );
-
- /**
- * Returns a suitable error object based on the track errors.
- *
- * @param {Object} errors - The errors got while creating local tracks.
- * @returns {Object}
- */
- function getStatusFromErrors(errors) {
- const { audioOnlyError, videoOnlyError, audioAndVideoError } = errors;
-
- if (audioAndVideoError) {
- if (audioOnlyError) {
- if (videoOnlyError) {
- return {
- deviceStatusType: 'warning',
- deviceStatusText: 'prejoin.audioAndVideoError',
- rawError: audioAndVideoError.message
- };
- }
-
- return {
- deviceStatusType: 'warning',
- deviceStatusText: 'prejoin.audioOnlyError',
- rawError: audioOnlyError.message
- };
- }
-
- return {
- deviceStatusType: 'warning',
- deviceStatusText: 'prejoin.videoOnlyError',
- rawError: audioAndVideoError.message
- };
- }
-
- return {
- deviceStatusType: 'ok',
- deviceStatusText: 'prejoin.lookGood',
- rawError: ''
- };
- }
|