jiti-meet/react/features/remote-control/reducer.ts

84 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-09-01 11:00:49 +00:00
import ReducerRegistry from '../base/redux/ReducerRegistry';
import { set } from '../base/redux/functions';
2020-11-14 04:09:25 +00:00
import {
CAPTURE_EVENTS,
REMOTE_CONTROL_ACTIVE,
SET_CONTROLLED_PARTICIPANT,
SET_CONTROLLER,
SET_RECEIVER_ENABLED,
SET_RECEIVER_TRANSPORT,
SET_REQUESTED_PARTICIPANT
} from './actionTypes';
/**
* The default state.
*/
const DEFAULT_STATE = {
active: false,
controller: {
isCapturingEvents: false
},
receiver: {
enabled: false
}
};
2022-09-01 11:00:49 +00:00
export interface IRemoteControlState {
active: boolean;
controller: {
controlled?: string;
isCapturingEvents: boolean;
requestedParticipant?: string;
};
receiver: {
controller?: string;
enabled: boolean;
transport?: Object;
};
2022-09-01 11:00:49 +00:00
}
2020-11-14 04:09:25 +00:00
/**
* Listen for actions that mutate the remote control state.
*/
2022-09-05 09:05:07 +00:00
ReducerRegistry.register<IRemoteControlState>(
'features/remote-control', (state = DEFAULT_STATE, action): IRemoteControlState => {
2020-11-14 04:09:25 +00:00
switch (action.type) {
case CAPTURE_EVENTS:
return {
...state,
controller: set(state.controller, 'isCapturingEvents', action.isCapturingEvents)
};
case REMOTE_CONTROL_ACTIVE:
return set(state, 'active', action.active);
case SET_RECEIVER_TRANSPORT:
return {
...state,
receiver: set(state.receiver, 'transport', action.transport)
};
case SET_RECEIVER_ENABLED:
return {
...state,
receiver: set(state.receiver, 'enabled', action.enabled)
};
case SET_REQUESTED_PARTICIPANT:
return {
...state,
controller: set(state.controller, 'requestedParticipant', action.requestedParticipant)
};
case SET_CONTROLLED_PARTICIPANT:
return {
...state,
controller: set(state.controller, 'controlled', action.controlled)
};
case SET_CONTROLLER:
return {
...state,
receiver: set(state.receiver, 'controller', action.controller)
};
}
return state;
2021-11-04 21:10:43 +00:00
}
2020-11-14 04:09:25 +00:00
);