Skip to content

Instantly share code, notes, and snippets.

@hieptlccc
hieptlccc / common.js
Created January 9, 2022 06:59
common.js - webex clone
import { realTimeDb } from "../firebase";
export const createCometChatGroup = async ({ cometChat, guid, name }) => {
const groupType = cometChat.GROUP_TYPE.PUBLIC;
const password = "";
const group = new cometChat.Group(guid, name, groupType, password);
await cometChat.createGroup(group);
};
export const showNotification = message => {
@hieptlccc
hieptlccc / app.js
Created January 9, 2022 07:02
app.js - init cometchat - webex clone
...
const initCometChat = async () => {
const { CometChat } = await import('@cometchat-pro/chat');
const appID = `${process.env.REACT_APP_COMETCHAT_APP_ID}`;
const region = `${process.env.REACT_APP_COMETCHAT_REGION}`;
const appSetting = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region).build();
CometChat.init(appID, appSetting).then(
() => {
setCometChat(() => CometChat);
},
@hieptlccc
hieptlccc / firebase.js
Created January 9, 2022 07:03
firebase.js - webex clone
import firebase from "firebase";
import "firebase/storage";
const firebaseConfig = {
apiKey: `${process.env.REACT_APP_FIREBASE_API_KEY}`,
authDomain: `${process.env.REACT_APP_FIREBASE_AUTH_DOMAIN}`,
databaseURL: `${process.env.REACT_APP_FIREBASE_DATABASE_URL}`,
projectId: `${process.env.REACT_APP_FIREBASE_PROJECT_ID}`,
storageBucket: `${process.env.REACT_APP_FIREBASE_STORAGE_BUCKET}`,
messagingSenderId: `${process.env.REACT_APP_FIREABSE_MESSAGING_SENDER_ID}`,
@hieptlccc
hieptlccc / app.js
Created January 9, 2022 08:17
global state - webex clone
...
const [isLoading, setIsLoading] = useState(false);
const [user, setUser] = useState(null);
const [cometChat, setCometChat] = useState(null);
// menu id.
const [id, setId] = useState(null);
// chose meeting.
const [meeting, setMeeting] = useState(null);
// detect whether a new meeting was created so the list of meetings will be refreshed.
const [hasNewMeeting, setHasNewMeeting] = useState(false);
@hieptlccc
hieptlccc / login.js
Created January 9, 2022 08:30
login.js - webex clone
import { useEffect, useRef, useContext, useCallback } from "react";
import validator from "validator";
import { useHistory } from 'react-router-dom';
import withModal from "../common/Modal";
import SignUp from "../register/SignUp";
import Context from "../../context";
import { auth, realTimeDb } from "../../firebase";
@hieptlccc
hieptlccc / login.js
Last active January 9, 2022 08:38
login.js - login cometchat -webex clone
...
const loginWithCometChat = async (user) => {
if (!user) return;
const authKey = `${process.env.REACT_APP_COMETCHAT_AUTH_KEY}`;
const cometChatUser = await cometChat.login(user.id, authKey);
if (cometChatUser) {
...
}
};
...
@hieptlccc
hieptlccc / modal.js
Created January 9, 2022 08:40
modal.js - webex clone
import { useState } from 'react';
const withModal = ModalComponent => WrapperComponent => {
return function () {
const [isModalShown, setIsModalShown] = useState(false);
return (
<>
<WrapperComponent toggleModal={setIsModalShown}/>
{isModalShown && <ModalComponent toggleModal={setIsModalShown} />}
@hieptlccc
hieptlccc / meeting.js
Created January 9, 2022 08:47
meeting.js - higher-order component - webex clone
import { useContext } from 'react';
import { useHistory } from 'react-router';
import Context from '../../context';
import { saveDataToLocalStorage, navigate } from '../../services/common';
const withMeeting = WrapperComponent => {
return function (props) {
const { setMeeting } = useContext(Context);
@hieptlccc
hieptlccc / signup.js
Created January 9, 2022 08:52
signup.js - webex clone
import { useRef, useContext } from "react";
import validator from "validator";
import { v4 as uuidv4 } from "uuid";
import Context from "../../context";
import { auth } from "../../firebase";
import { showNotification, insertFirebaseDatabase } from "../../services/common";
@hieptlccc
hieptlccc / signup.js
Created January 9, 2022 10:46
signup.js - create cometchat account - webex clone
...
const createCometChatAccount = async ({ id, fullname, avatar }) => {
const authKey = `${process.env.REACT_APP_COMETCHAT_AUTH_KEY}`;
const user = new cometChat.User(id);
user.setName(fullname);
user.setAvatar(avatar);
return await cometChat.createUser(user, authKey);
};
...