2020-04-23 22:07:44 +08:00
|
|
|
import React, { createContext, useReducer, useEffect } from 'react';
|
|
|
|
import Storage from '/imports/ui/services/storage/session';
|
|
|
|
|
2020-03-25 20:52:23 +08:00
|
|
|
export const LayoutContext = createContext();
|
2020-03-05 02:34:10 +08:00
|
|
|
|
|
|
|
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,
|
2020-03-25 20:52:23 +08:00
|
|
|
windowSize: {
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
},
|
2020-04-23 22:07:44 +08:00
|
|
|
mediaBounds: {
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
},
|
2020-03-05 02:34:10 +08:00
|
|
|
userListSize: {
|
|
|
|
width: 0,
|
|
|
|
},
|
2021-05-18 04:25:07 +08:00
|
|
|
secondPanelSize: {
|
|
|
|
width: 0,
|
|
|
|
},
|
2020-03-05 02:34:10 +08:00
|
|
|
chatSize: {
|
|
|
|
width: 0,
|
|
|
|
},
|
2020-06-20 13:46:10 +08:00
|
|
|
noteSize: {
|
|
|
|
width: 0,
|
|
|
|
},
|
|
|
|
captionsSize: {
|
|
|
|
width: 0,
|
|
|
|
},
|
|
|
|
pollSize: {
|
|
|
|
width: 0,
|
|
|
|
},
|
|
|
|
waitingSize: {
|
|
|
|
width: 0,
|
|
|
|
},
|
|
|
|
breakoutRoomSize: {
|
|
|
|
width: 0,
|
|
|
|
},
|
2020-03-05 02:34:10 +08:00
|
|
|
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,
|
2021-04-23 01:23:59 +08:00
|
|
|
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: {
|
2020-03-05 02:34:10 +08:00
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
},
|
2020-03-25 20:52:23 +08:00
|
|
|
presentationIsFullscreen: null,
|
2020-04-23 22:07:44 +08:00
|
|
|
presentationOrientation: null,
|
2021-02-24 01:04:00 +08:00
|
|
|
screenShareIsFullscreen: null,
|
2020-03-05 02:34:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
}
|
2020-03-25 20:52:23 +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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-03-05 02:34:10 +08:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-03-05 02:34:10 +08:00
|
|
|
case 'setChatSize': {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
chatSize: {
|
|
|
|
width: action.value.width,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-06-20 13:46:10 +08:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|
2020-03-05 02:34:10 +08:00
|
|
|
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': {
|
2020-03-05 02:34:10 +08:00
|
|
|
return {
|
|
|
|
...state,
|
2020-05-01 06:18:03 +08:00
|
|
|
presentationSlideSize: {
|
2020-03-05 02:34:10 +08:00
|
|
|
width: action.value.width,
|
|
|
|
height: action.value.height,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-03-25 20:52:23 +08:00
|
|
|
case 'setPresentationFullscreen': {
|
2020-04-23 22:07:44 +08:00
|
|
|
// presentationIsFullscreen: (true | false) boolean
|
2020-03-25 20:52:23 +08:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
presentationIsFullscreen: action.value,
|
|
|
|
};
|
|
|
|
}
|
2020-04-23 22:07:44 +08:00
|
|
|
case 'setPresentationOrientation': {
|
|
|
|
// presentationOrientation: ('portrait' | 'landscape') string
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
presentationOrientation: action.value,
|
|
|
|
};
|
|
|
|
}
|
2021-02-24 01:04:00 +08:00
|
|
|
case 'setScreenShareFullscreen': {
|
|
|
|
// screenshareIsFullscreen: (true | false) boolean
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
screenShareIsFullscreen: action.value,
|
|
|
|
};
|
|
|
|
}
|
2020-03-05 02:34:10 +08:00
|
|
|
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;
|
2020-03-05 02:34:10 +08:00
|
|
|
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,
|
|
|
|
]);
|
|
|
|
|
2020-03-05 02:34:10 +08:00
|
|
|
return (
|
|
|
|
<LayoutContext.Provider value={{
|
|
|
|
layoutContextState,
|
|
|
|
layoutContextDispatch,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</LayoutContext.Provider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const withProvider = Component => props => (
|
2021-05-18 04:25:07 +08:00
|
|
|
<ContextProvider>
|
|
|
|
<Component {...props} />
|
2020-03-05 02:34:10 +08:00
|
|
|
</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 {
|
2020-03-25 20:52:23 +08:00
|
|
|
withProvider,
|
2020-03-05 02:34:10 +08:00
|
|
|
withLayoutConsumer,
|
|
|
|
withLayoutContext,
|
|
|
|
};
|