Created
November 14, 2021 06:05
-
-
Save hieptl/bf4f17c2382f9dd9f367232a242f8e01 to your computer and use it in GitHub Desktop.
Main.js - Server - Discord Clone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useContext } from 'react'; | |
import { CometChatMessages } from '../../cometchat-pro-react-ui-kit/CometChatWorkspace/src'; | |
import Header from './Header'; | |
import RightSidebar from './RightSidebar'; | |
import Context from '../../context'; | |
const Main = () => { | |
const { cometChat, selectedChannel, selectedChannelType, setSelectedChannelType } = useContext(Context); | |
useEffect(() => { | |
if (cometChat, selectedChannel && selectedChannelType === 2) { | |
startDirectCall(); | |
} | |
}, [cometChat, selectedChannel, selectedChannelType]); | |
const startDirectCall = () => { | |
if (cometChat && selectedChannel && selectedChannelType === 2) { | |
const sessionID = selectedChannel.guid; | |
const audioOnly = false; | |
const defaultLayout = true; | |
const callSettings = new cometChat.CallSettingsBuilder() | |
.enableDefaultLayout(defaultLayout) | |
.setSessionID(sessionID) | |
.setIsAudioOnlyCall(audioOnly) | |
.build(); | |
const callSceen = document.getElementById("call__screen"); | |
callSceen.classList.add('call__screen--active'); | |
cometChat.startCall( | |
callSettings, | |
document.getElementById("call__screen"), | |
new cometChat.OngoingCallListener({ | |
onUserListUpdated: userList => { | |
}, | |
onCallEnded: call => { | |
callSceen.classList.remove('call__screen--active'); | |
setSelectedChannelType(null); | |
}, | |
onError: error => { | |
callSceen.classList.remove('call__screen--active'); | |
setSelectedChannelType(null); | |
}, | |
onMediaDeviceListUpdated: deviceList => { | |
}, | |
onUserMuted: (userMuted, userMutedBy) => { | |
}, | |
onScreenShareStarted: () => { | |
}, | |
onScreenShareStopped: () => { | |
} | |
}) | |
); | |
} | |
}; | |
return ( | |
<> | |
<div className="server__main"> | |
<Header /> | |
<div className="server__container"> | |
<div className="server__container-body"> | |
{selectedChannel && selectedChannelType === 1 && <CometChatMessages chatWithGroup={selectedChannel.guid} />} | |
</div> | |
<RightSidebar /> | |
</div> | |
</div> | |
<div id="call__screen"></div> | |
</> | |
); | |
}; | |
export default Main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment