@100mslive/react-native-room-kit
Version:
100ms Room Kit provides simple & easy to use UI components to build Live Streaming & Video Conferencing experiences in your apps.
48 lines • 4.87 kB
JavaScript
import { JoinForm_JoinBtnType } from '@100mslive/types-prebuilt/elements/join_form';
import { selectIsHLSStreamingOn } from './hooks-sdk-selectors';
export const selectIsHLSViewer = (role, layoutConfig) => {
var _role$name;
if (layoutConfig) {
var _layoutConfig$screens;
return !!((_layoutConfig$screens = layoutConfig.screens) !== null && _layoutConfig$screens !== void 0 && (_layoutConfig$screens = _layoutConfig$screens.conferencing) !== null && _layoutConfig$screens !== void 0 && _layoutConfig$screens.hls_live_streaming);
}
return (role === null || role === void 0 || (_role$name = role.name) === null || _role$name === void 0 ? void 0 : _role$name.includes('hls-')) ?? false;
};
export const selectLayoutConfigForRole = (layoutConfig, role) => {
if (layoutConfig === null || layoutConfig.length <= 0) {
return null;
}
if (role === null) {
return layoutConfig[0] || null;
}
const selectedLayout = layoutConfig.find(layout => layout.role === role.name);
return selectedLayout || layoutConfig[0] || null;
};
export const selectShouldGoLive = state => {
var _state$hmsStates$loca, _layoutConfig$screens2, _state$hmsStates$loca2;
const currentRole = ((_state$hmsStates$loca = state.hmsStates.localPeer) === null || _state$hmsStates$loca === void 0 ? void 0 : _state$hmsStates$loca.role) || null;
const layoutConfig = selectLayoutConfigForRole(state.hmsStates.layoutConfig, currentRole);
const isHLSStreaming = selectIsHLSStreamingOn(state);
const joinButtonType = (layoutConfig === null || layoutConfig === void 0 || (_layoutConfig$screens2 = layoutConfig.screens) === null || _layoutConfig$screens2 === void 0 || (_layoutConfig$screens2 = _layoutConfig$screens2.preview) === null || _layoutConfig$screens2 === void 0 || (_layoutConfig$screens2 = _layoutConfig$screens2.default) === null || _layoutConfig$screens2 === void 0 || (_layoutConfig$screens2 = _layoutConfig$screens2.elements) === null || _layoutConfig$screens2 === void 0 || (_layoutConfig$screens2 = _layoutConfig$screens2.join_form) === null || _layoutConfig$screens2 === void 0 ? void 0 : _layoutConfig$screens2.join_btn_type) ?? JoinForm_JoinBtnType.JOIN_BTN_TYPE_JOIN_ONLY;
const canStartHLSStreaming = joinButtonType === JoinForm_JoinBtnType.JOIN_BTN_TYPE_JOIN_AND_GO_LIVE || joinButtonType === JoinForm_JoinBtnType.JOIN_BTN_TYPE_JOIN_ONLY ?
// can start if `joinButtonType` is `JOIN_BTN_TYPE_JOIN_AND_GO_LIVE`
joinButtonType === JoinForm_JoinBtnType.JOIN_BTN_TYPE_JOIN_AND_GO_LIVE : // Check if the Role has permission to start HLS Stream
(_state$hmsStates$loca2 = state.hmsStates.localPeer) === null || _state$hmsStates$loca2 === void 0 || (_state$hmsStates$loca2 = _state$hmsStates$loca2.role) === null || _state$hmsStates$loca2 === void 0 || (_state$hmsStates$loca2 = _state$hmsStates$loca2.permissions) === null || _state$hmsStates$loca2 === void 0 ? void 0 : _state$hmsStates$loca2.hlsStreaming;
return canStartHLSStreaming && !isHLSStreaming;
};
export const selectChatLayoutConfig = layoutConfig => {
var _layoutConfig$screens3, _screenOptions$elemen;
const conferencingConfig = layoutConfig === null || layoutConfig === void 0 || (_layoutConfig$screens3 = layoutConfig.screens) === null || _layoutConfig$screens3 === void 0 ? void 0 : _layoutConfig$screens3.conferencing;
const screenOptions = conferencingConfig ? conferencingConfig.default || conferencingConfig.hls_live_streaming : null;
return (screenOptions === null || screenOptions === void 0 || (_screenOptions$elemen = screenOptions.elements) === null || _screenOptions$elemen === void 0 ? void 0 : _screenOptions$elemen.chat) ?? null;
};
export const selectVideoTileLayoutConfig = layoutConfig => {
var _layoutConfig$screens4;
return layoutConfig === null || layoutConfig === void 0 || (_layoutConfig$screens4 = layoutConfig.screens) === null || _layoutConfig$screens4 === void 0 || (_layoutConfig$screens4 = _layoutConfig$screens4.conferencing) === null || _layoutConfig$screens4 === void 0 || (_layoutConfig$screens4 = _layoutConfig$screens4.default) === null || _layoutConfig$screens4 === void 0 || (_layoutConfig$screens4 = _layoutConfig$screens4.elements) === null || _layoutConfig$screens4 === void 0 ? void 0 : _layoutConfig$screens4.video_tile_layout;
};
export const selectConferencingScreenConfig = layoutConfig => {
var _layoutConfig$screens5;
const conferencingConfig = layoutConfig === null || layoutConfig === void 0 || (_layoutConfig$screens5 = layoutConfig.screens) === null || _layoutConfig$screens5 === void 0 ? void 0 : _layoutConfig$screens5.conferencing;
return ((conferencingConfig === null || conferencingConfig === void 0 ? void 0 : conferencingConfig.default) || (conferencingConfig === null || conferencingConfig === void 0 ? void 0 : conferencingConfig.hls_live_streaming)) ?? null;
};
//# sourceMappingURL=hooks-util-selectors.js.map