sfm-uikit-react-native
Version:
It is a react native component for SmartFloMeet users.
420 lines (418 loc) • 18.8 kB
JavaScript
import EnxRequiredEventsOption from "./EnxRequiredEventsOption";
import EnxParticipantListOptions from "./EnxParticipantListOptions";
import EnxPageSlideEventName from "./EnxPageSlideEventName";
class EnxSetting {
constructor(){
if(!EnxSetting.instance){
this.isConnected = false;
this.loadConfirmationScreen = true;
this.roomMode = 'group';
this.role = 'moderator';
this.shareOption = {};
this.clientID = '';
this.moreOptionList = []; // More options
this.requiredEventsOptList = []; // This will store all default option or user passed options
this.userDefaultOption = [];// User default bahaviour for botton visiable option
this.participantsOptions = []; //This is for participant options Like Audio/Video/Chat/Disconnect
this.participantEventDefault = []; //this is for participant screen for which store the default options
this.participantEventsOption = []; //This will store after filttering the aprticipant option
this.joinText = 'Join Now!';
this.isAudioOnly = false;
this.audioMuted = false;
this.videoMuted = false;
this.startWithFontCamera = true;
this.rtmpDetails = {};
this.startLiveStreamAfterJoin = false;
this.bottomOptions = [];
this.isMore = false;
this.events = {}; // Store event listeners
EnxSetting.instance = this;
}
return EnxSetting.instance;
}
//Register the listener
addEventListener(eventName, listener) {
if (!this.events[eventName]) {
this.events[eventName] = [];
}
this.events[eventName].push(listener);
}
//Remove the register listener
removeEventListener(eventName, listener) {
if (!this.events[eventName]) return;
this.events[eventName] = this.events[eventName].filter(
(l) => l !== listener
);
}
//send/emit the listener
emitEvent(eventName, data) {
if (!this.events[eventName]) return;
this.events[eventName].forEach((listener) => {
listener(data);
});
}
//Update Connection status
updateIsConnected =(value) =>{
this.isConnected = value;
}
//get Connection Status
getIsConnected = () =>{
return this.isConnected;
}
//Update flag to show confirmation screen
setIsShowConfirmationScreen(value) {
this.loadConfirmationScreen = value;
}
//Get updated flag either to show/Not confirmation screen
getIsShowConfirmationScreen() {
return this.loadConfirmationScreen;
}
//Set join Text
setJointext =(value) =>{
this.joinText = value
}
//Get update join text
getJoinText = () => {
return this.joinText
}
//Update roomMode
updateRoomMode =(value) =>{
this.roomMode = value;
}
//get roomMode
getRoomMode = () =>{
return this.roomMode;
}
//Set camera position font/back
setFontCameraPosition =(value) =>{
this.startWithFontCamera = value
}
//get latest updated camera position
getCameraPosition = () =>{
return this.startWithFontCamera
}
//set flag while join, wanted to self join either audio only or audio/Video
joinAsAudioOnlyCall =(value) =>{
this.isAudioOnly = value
}
//get latest updated flag for audio only
getIsAudioOnly =()=>{
return this.isAudioOnly
}
//Set whether join as audio muted/unmuted
joinAsAudioMute =(value)=>{
this.audioMuted = value
}
//Get latest updated flag for join either audio muted/unmuted
getIsAudioMuted =()=>{
return this.audioMuted
}
//Set whether joining as video/muted/unmuted
joinAsVideoMute = (value)=>{
this.videoMuted = value
}
//Get latest updated flage for video muted/unmuted
getIsVideoMuted = () =>{
return this.videoMuted
}
//Set flag to start live streaming asap joining to room
startLiveStreamingAfterJoin = (value) =>{
this.startLiveStreamAfterJoin = value
}
//Get update flag status to start live Stream after join room
getStartLibeSteamingFalg=()=>{
return this.startLiveStreamAfterJoin
}
//Set information for live Streaming after join the room
liveStreamingInformation = (value) =>{
this.rtmpDetails = value
}
//Get live styreaming updated information , while starting the live streaming
getRTMPInfoDetails =() =>{
return this.rtmpDetails
}
// Helper method to validate if the option is a valid enum value
isValidEnumValue(value) {
return Object.values(EnxRequiredEventsOption).includes(value);
}
//Set Required event option , here user can set there own list of option like [EnxRequiredEventsOption, Bollen]
configureRequiredEventList = (value) =>{
if (!Array.isArray(value)) {
throw new Error('Input must be an array of [Enum, Boolean] pairs');
}
optionsList.forEach(([option, value]) => {
// Check if option is valid enum
if (!this.isValidEnumValue(option)) {
throw new Error(`Invalid enum value: ${option}`);
}
// Check if value is boolean
if (typeof value !== 'boolean') {
throw new Error(`Invalid value type for ${option}: Expected boolean, but received ${typeof value}`);
}
});
// if all valid the assign the mail list
this.requiredEventsOptList= value
}
//This is internal after join the room , we are preparing the options
createRequiredOption =() =>{
this.requiredEventsOptList = (this.requiredEventsOptList === undefined || this.requiredEventsOptList.length === 0) ? [[EnxRequiredEventsOption.audio , true],[EnxRequiredEventsOption.video , true],[EnxRequiredEventsOption.cameraSwitch , true],[EnxRequiredEventsOption.audioSwitch , true],[EnxRequiredEventsOption.groupChat , true],[EnxRequiredEventsOption.disconnect ,true],[EnxRequiredEventsOption.muteRoom , true],[EnxRequiredEventsOption.recording , true],[EnxRequiredEventsOption.ScreenShare , true],[EnxRequiredEventsOption.annotation , true],[EnxRequiredEventsOption.lobby , true],[EnxRequiredEventsOption.requestList , true],[EnxRequiredEventsOption.roomSetting , true],[EnxRequiredEventsOption.polling , true],[EnxRequiredEventsOption.qna , true]] : this.requiredEventsOptList
// Reset the list before processing
this.userDefaultOption = []; // Ensure reset happens only once before processing
this.requiredEventsOptList.forEach(([eventOption, isEnabled]) => {
if (isEnabled) {
switch (eventOption) {
case EnxRequiredEventsOption.audio:
if (this.role !== 'audience') {
this.userDefaultOption.push('Audio');
}
break;
case EnxRequiredEventsOption.video:
if (this.role !== 'audience') {
this.userDefaultOption.push('Video');
}
break;
case EnxRequiredEventsOption.cameraSwitch:
if (this.role !== 'audience') {
this.userDefaultOption.push('Camera');
}
break;
case EnxRequiredEventsOption.audioSwitch:
if (this.role !== 'audience') {
this.userDefaultOption.push('AudioMedia');
}
break;
case EnxRequiredEventsOption.groupChat:
this.userDefaultOption.push('Chat');
break;
case EnxRequiredEventsOption.disconnect:
this.userDefaultOption.push('Disconnect');
break;
default:
break;
}
}
});
// Check for 'more' options that are not dependent on role
// Define your required events options
const requiredEnums = [
EnxRequiredEventsOption.annotation,
EnxRequiredEventsOption.muteRoom,
EnxRequiredEventsOption.recording,
EnxRequiredEventsOption.ScreenShare,
EnxRequiredEventsOption.lobby,
EnxRequiredEventsOption.requestList,
EnxRequiredEventsOption.roomSetting,
EnxRequiredEventsOption.polling,
EnxRequiredEventsOption.qna
];
// Check if any of the required events options have a true value
this.isMore = this.requiredEventsOptList.some(([eventOption, isEnabled]) => {
return requiredEnums.includes(eventOption) && isEnabled;
});
// // If 'more' options exist, add 'more' to userDefaultOption array
if (this.isMore && this.role !== 'audience') {
//this.userDefaultOption.push('More');
this.userDefaultOption.splice(this.userDefaultOption.length - 1, 0, 'More');
}
return this.userDefaultOption
}
//Create more options if its not created early
createMoreOptions = () => {
// Reset the list before processing
this.moreOptionList = []; // Ensure reset happens only once before processing
this.requiredEventsOptList.forEach(([eventOption, isEnabled]) => {
if (isEnabled) {
switch (eventOption) {
case EnxRequiredEventsOption.muteRoom:
if(this.role == 'moderator'){
this.moreOptionList.push({
name:'Mute Room',
imageIcon : require("../image_asset/moderator_unmute.png"),
status:false,
isSwitch:true})
}
break;
case EnxRequiredEventsOption.recording :
if(this.role == 'moderator'){
this.moreOptionList.push({
name:'Start Recording',
imageIcon: require("../image_asset/recording_on.png"),
status:false,
isSwitch:true
})
}
break;
case EnxRequiredEventsOption.annotation :
this.moreOptionList.push({
name:'Start Annotation',
imageIcon : require("../image_asset/screen_share_off.png"),
status:false,
isSwitch:true
})
break;
case EnxRequiredEventsOption.ScreenShare :
if(Platform.OS === 'android'){
this.moreOptionList.push({
name:'Start Screen Share',
imageIcon:require("../image_asset/screen_share_off.png"),
status:false,
isSwitch:true
})
}
break;
case EnxRequiredEventsOption.lobby :
if(this.role == 'moderator'){
this.moreOptionList.push({
name:'Lobby',
imageIcon:require("../image_asset/lobby.png"),
status:false,
isSwitch:false
})
}
break;
case EnxRequiredEventsOption.roomSetting :
if(this.role == 'moderator'){
this.moreOptionList.push({
name:'Room Setting',
imageIcon:require("../image_asset/settings.png"),
status:false,
isSwitch:false
})
}
break;
case EnxRequiredEventsOption.requestList :
if(this.role == 'moderator'){
this.moreOptionList.push({
name:'Requests',
imageIcon: require("../image_asset/notification_icon.png"),
status:false,
isSwitch:false
})
}
break;
case EnxRequiredEventsOption.polling :
if(this.role == 'moderator'){
this.moreOptionList.push({
name:'Polling',
imageIcon:require("../image_asset/polling_black.png"),
status:false,
isSwitch:false
})
}
break;
case EnxRequiredEventsOption.qna :
this.moreOptionList.push({
name:'Q&A',
imageIcon:require("../image_asset/qna.png"),
status:false,
isSwitch:false
})
break;
default:
break;
}
}
});
return this.moreOptionList
}
//Update Status Of menuList after action Prefrom
updateMenuStatus=(values) =>{
this.moreOptionList[values].status = !this.moreOptionList[values].status;
}
//Get list of more options
getMoreOptions = () =>{
return (this.moreOptionList === undefined || this.moreOptionList.length === 0) ? this.createMoreOptions() : this.moreOptionList
}
//after join the room update the self role
setUserRole = (value) =>{
this.role = value
}
//get self role
getUserRole = () =>{
return this.role
}
//Set Required event option , here user can set there own list of option like [EnxRequiredEventsOption, Bollen]
configureParticipantEventList = (value) =>{
if (!Array.isArray(value)) {
throw new Error('Input must be an array of [Enum, Boolean] pairs');
}
optionsList.forEach(([option, value]) => {
// Check if option is valid enum
if (!this.isValidEnumValue(option)) {
throw new Error(`Invalid enum value: ${option}`);
}
// Check if value is boolean
if (typeof value !== 'boolean') {
throw new Error(`Invalid value type for ${option}: Expected boolean, but received ${typeof value}`);
}
});
// if all valid the assign the mail list
this.participantEventDefault= value
}
//This is internal after join the room , we are preparing the options
createRequiredParticipantOption =() =>{
this.participantEventDefault = (this.participantEventDefault === undefined || this.participantEventDefault.length === 0) ? [[EnxParticipantListOptions.audio , true],[EnxParticipantListOptions.video , true],[EnxParticipantListOptions.chat , true],[EnxParticipantListOptions.disconnect ,true]] : this.participantEventDefault
// Reset the list before processing
this.participantEventsOption = []; // Ensure reset happens only once before processing
this.participantEventDefault.forEach(([eventOption, isEnabled]) => {
if (isEnabled) {
switch (eventOption){
case EnxParticipantListOptions.audio:
this.participantEventsOption.push({
name:'Audio',
imageNormalIcon:require("../image_asset/audio_on.png"),
imageSelectedIcon:require("../image_asset/audio_off.png"),
});
break;
case EnxParticipantListOptions.video:
this.participantEventsOption.push({
name:'Video',
imageNormalIcon:require("../image_asset/video_on.png"),
imageSelectedIcon:require("../image_asset/video_off.png"),
});
break;
case EnxParticipantListOptions.chat:
this.participantEventsOption.push({
name:'Chat',
imageNormalIcon:require("../image_asset/chat_icon.png"),
imageSelectedIcon:require("../image_asset/chat_icon.png"),
});
break;
case EnxParticipantListOptions.disconnect:
this.participantEventsOption.push({
name:'Disconnect',
imageNormalIcon:require("../image_asset/end_call_new.png"),
imageSelectedIcon:require("../image_asset/end_call_new.png"),
});
break;
default:
break;
}
}
});
return this.participantEventsOption
}
navigateOutInternalOpenPage =(value) =>{
switch(value){
case EnxPageSlideEventName.EnxChat :
this.emitEvent('ChatPageBack',{});
break
case EnxPageSlideEventName.EnxQnA:
this.emitEvent('QNAPageBack',{});
break
case EnxPageSlideEventName.EnxPolling :
this.emitEvent('PollingPageBack',{});
break
case EnxPageSlideEventName.EnxCreatePoll :
this.emitEvent('CreatePoll',{});
break
case EnxPageSlideEventName.EnxRoomSetting:
break
default:
break
}
}
}
const instance = new EnxSetting();
//Object.freeze(instance);
export default instance;