bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/layout/context.jsx

307 lines
6.4 KiB
React
Raw Normal View History

2020-04-23 22:07:44 +08:00
import React, { createContext, useReducer, useEffect } from 'react';
import Storage from '/imports/ui/services/storage/session';
export const LayoutContext = createContext();
const initialState = {
2020-04-23 22:07:44 +08:00
autoArrangeLayout: true,
2020-06-16 23:20:24 +08:00
webcamsAreaResizing: false,
2020-06-09 11:09:46 +08:00
numUsersVideo: null,
windowSize: {
width: 0,
height: 0,
},
2020-04-23 22:07:44 +08:00
mediaBounds: {
width: 0,
height: 0,
top: 0,
left: 0,
},
userListSize: {
width: 0,
},
2021-05-18 04:25:07 +08:00
secondPanelSize: {
width: 0,
},
chatSize: {
width: 0,
},
noteSize: {
width: 0,
},
captionsSize: {
width: 0,
},
pollSize: {
width: 0,
},
waitingSize: {
width: 0,
},
breakoutRoomSize: {
width: 0,
},
webcamsAreaSize: {
width: 0,
height: 0,
},
2020-06-16 23:20:24 +08:00
tempWebcamsAreaSize: {
width: 0,
height: 0,
},
2020-05-01 06:18:03 +08:00
webcamsAreaUserSetsHeight: 0,
webcamsAreaUserSetsWidth: 0,
webcamsPlacement: 'top',
2020-05-01 06:18:03 +08:00
presentationAreaSize: {
2020-04-23 22:07:44 +08:00
width: 0,
height: 0,
},
2020-05-01 06:18:03 +08:00
presentationSlideSize: {
width: 0,
height: 0,
},
presentationIsFullscreen: null,
2020-04-23 22:07:44 +08:00
presentationOrientation: null,
screenShareIsFullscreen: null,
};
const reducer = (state, action) => {
switch (action.type) {
2020-04-23 22:07:44 +08:00
case 'setAutoArrangeLayout': {
return {
...state,
autoArrangeLayout: action.value,
};
}
2020-06-16 23:20:24 +08:00
case 'setWebcamsAreaResizing': {
return {
...state,
webcamsAreaResizing: action.value,
};
}
2020-06-05 07:01:17 +08:00
case 'setUsersVideo': {
return {
...state,
2020-06-09 11:09:46 +08:00
numUsersVideo: action.value,
2020-06-05 07:01:17 +08:00
};
}
case 'setWindowSize': {
return {
...state,
windowSize: {
width: action.value.width,
height: action.value.height,
},
};
}
2020-04-23 22:07:44 +08:00
case 'setMediaBounds': {
return {
...state,
mediaBounds: {
width: action.value.width,
height: action.value.height,
top: action.value.top,
left: action.value.left,
},
};
}
case 'setUserListSize': {
return {
...state,
userListSize: {
width: action.value.width,
},
};
}
2021-05-18 04:25:07 +08:00
case 'setSecondPanelSize': {
return {
...state,
secondPanelSize: {
width: action.value,
},
};
}
case 'setChatSize': {
return {
...state,
chatSize: {
width: action.value.width,
},
};
}
case 'setNoteSize': {
return {
...state,
noteSize: {
width: action.value.width,
},
};
}
case 'setCaptionsSize': {
return {
...state,
captionsSize: {
width: action.value.width,
},
};
}
case 'setPollSize': {
return {
...state,
pollSize: {
width: action.value.width,
},
};
}
case 'setWaitingUsersPanelSize': {
return {
...state,
waitingSize: {
width: action.value.width,
},
};
}
case 'setBreakoutRoomSize': {
return {
...state,
breakoutRoomSize: {
width: action.value.width,
},
};
}
2020-04-23 22:07:44 +08:00
case 'setWebcamsPlacement': {
// webcamsPlacement: ('top' | 'right' | 'bottom' | 'left') string
return {
...state,
webcamsPlacement: action.value,
};
}
case 'setWebcamsAreaSize': {
return {
...state,
webcamsAreaSize: {
width: action.value.width,
height: action.value.height,
},
};
}
2020-06-16 23:20:24 +08:00
case 'setTempWebcamsAreaSize': {
return {
...state,
tempWebcamsAreaSize: {
width: action.value.width,
height: action.value.height,
},
};
}
2020-05-01 06:18:03 +08:00
case 'setWebcamsAreaUserSetsHeight': {
return {
...state,
webcamsAreaUserSetsHeight: action.value,
};
}
case 'setWebcamsAreaUserSetsWidth': {
return {
...state,
webcamsAreaUserSetsWidth: action.value,
};
}
case 'setPresentationAreaSize': {
2020-04-23 22:07:44 +08:00
return {
...state,
2020-05-01 06:18:03 +08:00
presentationAreaSize: {
2020-04-23 22:07:44 +08:00
width: action.value.width,
height: action.value.height,
},
};
}
2020-05-01 06:18:03 +08:00
case 'setPresentationSlideSize': {
return {
...state,
2020-05-01 06:18:03 +08:00
presentationSlideSize: {
width: action.value.width,
height: action.value.height,
},
};
}
case 'setPresentationFullscreen': {
2020-04-23 22:07:44 +08:00
// presentationIsFullscreen: (true | false) boolean
return {
...state,
presentationIsFullscreen: action.value,
};
}
2020-04-23 22:07:44 +08:00
case 'setPresentationOrientation': {
// presentationOrientation: ('portrait' | 'landscape') string
return {
...state,
presentationOrientation: action.value,
};
}
case 'setScreenShareFullscreen': {
// screenshareIsFullscreen: (true | false) boolean
return {
...state,
screenShareIsFullscreen: action.value,
};
}
default: {
throw new Error('Unexpected action');
}
}
};
const ContextProvider = (props) => {
const [layoutContextState, layoutContextDispatch] = useReducer(reducer, initialState);
2020-05-01 06:18:03 +08:00
const {
webcamsPlacement,
webcamsAreaUserSetsHeight,
webcamsAreaUserSetsWidth,
autoArrangeLayout,
} = layoutContextState;
const { children } = props;
2020-04-23 22:07:44 +08:00
useEffect(() => {
Storage.setItem('webcamsPlacement', webcamsPlacement);
2020-05-01 06:18:03 +08:00
Storage.setItem('webcamsAreaUserSetsHeight', webcamsAreaUserSetsHeight);
Storage.setItem('webcamsAreaUserSetsWidth', webcamsAreaUserSetsWidth);
2020-04-23 22:07:44 +08:00
Storage.setItem('autoArrangeLayout', autoArrangeLayout);
}, [
webcamsPlacement,
2020-05-01 06:18:03 +08:00
webcamsAreaUserSetsHeight,
webcamsAreaUserSetsWidth,
2020-04-23 22:07:44 +08:00
autoArrangeLayout,
]);
return (
<LayoutContext.Provider value={{
layoutContextState,
layoutContextDispatch,
}}
>
{children}
</LayoutContext.Provider>
);
};
const withProvider = Component => props => (
2021-05-18 04:25:07 +08:00
<ContextProvider>
<Component {...props} />
</ContextProvider>
);
const ContextConsumer = Component => props => (
<LayoutContext.Consumer>
{contexts => <Component {...props} {...contexts} />}
</LayoutContext.Consumer>
);
const withLayoutConsumer = Component => ContextConsumer(Component);
const withLayoutContext = Component => withProvider(withLayoutConsumer(Component));
export {
withProvider,
withLayoutConsumer,
withLayoutContext,
};