Skip to content

Instantly share code, notes, and snippets.

View hieptl's full-sized avatar
🎯
Focusing

Hiep Le hieptl

🎯
Focusing
View GitHub Profile
@hieptl
hieptl / login.js
Created December 7, 2021 07:59
login.js - login cometchat - ZocDoc Clone
const loginCometChat = async (id) => {
if (!id) {
return;
}
try {
const user = await cometChat.login(id, `${cometChatConfig.cometChatAuthKey}`);
if (user) {
const authenticatedUser = await getUser(id);
if (authenticatedUser) {
AsyncStorage.setItem('auth', JSON.stringify(authenticatedUser));
@hieptl
hieptl / login.js
Last active December 7, 2021 08:01
login.js - ZocDoc Clone
import React, { useState, useContext, useEffect } from 'react';
import { StyleSheet, View, TextInput, TouchableOpacity, Text, ActivityIndicator, Alert, Image } from 'react-native';
import validator from "validator";
import AsyncStorage from '@react-native-async-storage/async-storage';
import Context from "../context";
import { cometChatConfig } from '../env';
import { auth, signInWithEmailAndPassword, database, databaseRef, databaseGet, databaseChild } from "../firebase";
@hieptl
hieptl / App.js
Created December 7, 2021 07:53
App.js - init CometChat - Zocdoc Clone
useEffect(() => {
initCometChat();
}, []);
const initCometChat = async () => {
const { CometChat } = await import('@cometchat-pro/react-native-chat');
const appID = `${cometChatConfig.cometChatAppId}`;
const region = `${cometChatConfig.cometChatRegion}`;
const appSetting = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region).build();
CometChat.init(appID, appSetting).then(
@hieptl
hieptl / join.js
Created December 3, 2021 05:00
join.js - client - join the cometchat group - Zoom Clone
const joinCometChatGroup = async ({ guid }) => {
var password = "";
var groupType = cometChat.GROUP_TYPE.PUBLIC;
await cometChat.joinGroup(guid, groupType, password);
};
@hieptl
hieptl / create.js
Created December 3, 2021 04:58
create.js - client - create cometchat group - Zoom Clone
const createCometChatGroup = async ({ uid, name }) => {
const groupType = cometChat.GROUP_TYPE.PUBLIC;
const password = "";
const group = new cometChat.Group(uid, name, groupType, password);
await cometChat.createGroup(group);
};
@hieptl
hieptl / header.js
Created December 3, 2021 04:56
header.js - client - logout - Zoom Clone
const logout = async () => {
const isLogout = window.confirm('Do you want to log out ?');
if (isLogout) {
await cometChat.logout();
setUser(null);
localStorage.removeItem('auth');
history.push('/login');
}
}
@hieptl
hieptl / meeting.js
Created December 3, 2021 04:54
meeting.js - client - start direct call - Zoom Clone
const startDirectCall = () => {
if (cometChat && meeting) {
const sessionID = meeting.meeting_uid;
const audioOnly = false;
const defaultLayout = true;
const callSettings = new cometChat.CallSettingsBuilder()
.enableDefaultLayout(defaultLayout)
.setSessionID(sessionID)
.setIsAudioOnlyCall(audioOnly)
.build();
@hieptl
hieptl / meeting.js
Created December 3, 2021 04:52
meeting.js - client - Zoom Clone
import { useEffect, useContext } from 'react';
import { useHistory } from 'react-router';
import MeetingHeader from './MeetingHeader';
import { CometChatMessages } from '../../cometchat-pro-react-ui-kit/CometChatWorkspace/src';
import Context from '../../context';
const Meeting = () => {
const { meeting, cometChat } = useContext(Context);
@hieptl
hieptl / meetingheader.js
Created December 3, 2021 04:49
meetingheader.js - client - Zoom Clone
import { useContext } from 'react';
import { useHistory } from 'react-router-dom';
import Context from '../../context';
function MeetingHeader() {
const { meeting } = useContext(Context);
const history = useHistory();
const stopMeeting = () => {
@hieptl
hieptl / join.js
Created December 3, 2021 04:43
join.js - client - Zoom Clone
import { useRef, useContext } from 'react';
import axios from 'axios';
import { useHistory } from 'react-router-dom';
import Context from '../../context';
const Join = (props) => {
const { toggleJoin } = props;
const { setIsLoading, setMeeting, cometChat } = useContext(Context);