Skip to content

Instantly share code, notes, and snippets.

@swahaniroy
swahaniroy / index.js
Created May 26, 2022 15:23
The index.js file
logoutButon.addEventListener('click', function() {
const isLeaved = confirm('Do you want to log out?');
if (isLeaved) {
// logout from cometchat and then clear storage.
CometChatWidget.logout().then(response => {
// User successfully logged out.
// Perform any clean up if required.
// redirect to login page.
window.location.href = '/login.html';
});
@swahaniroy
swahaniroy / index.js
Created May 26, 2022 15:22
The index.js file
CometChatWidget.launch({
"widgetID": `${config.CometChatWidgetId}`,
"target": "#cometchat",
"roundedCorners": "false",
"height": "100%",
"width": "100%",
"defaultID": `${user.uid}`, //default UID (user) or GUID (group) to show,
"defaultType": 'user' //user or group
});
@swahaniroy
swahaniroy / index.js
Created May 26, 2022 15:20
The index.js file
window.addEventListener('DOMContentLoaded', function() {
// hide loading indicator.
hideLoading();
// get authenticated user
CometChatWidget.init({
"appID": `${config.CometChatAppId}`,
"appRegion": `${config.CometChatRegion}`,
"authKey": `${config.CometChatAuthKey}`
}).then(response => {
CometChatWidget.CometChat.getLoggedinUser().then(
@swahaniroy
swahaniroy / index.html
Created May 26, 2022 15:19
The index.html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Video Chat App with Vanilla JS</title>
<link rel="stylesheet" href="/css/styles.css" />
<script
defer
@swahaniroy
swahaniroy / config.js
Created May 26, 2022 15:14
The config.js file
const config = {
...
CometChatAppId: xxx - xxx - xxx - xxx - xxx - xxx - xxx - xxx,
CometChatRegion: xxx - xxx - xxx - xxx - xxx - xxx - xxx - xxx,
CometChatAuthKey: xxx - xxx - xxx - xxx - xxx - xxx - xxx - xxx,
CometChatAPIKey: xxx - xxx - xxx - xxx - xxx - xxx - xxx - xxx,
CometChatWidgetId: xxx - xxx - xxx - xxx - xxx - xxx - xxx - xxx,
};
@swahaniroy
swahaniroy / login.js
Created May 26, 2022 15:11
the login.js file
loginBtn.addEventListener("click", function () {
// show loading indicator.
showLoading();
// get input user's credentials.
const email = emailLoginInputElement ? emailLoginInputElement.value : null;
const password = passwordLoginInputElement
? passwordLoginInputElement.value
: null;
if (isUserCredentialsValid({ email, password })) {
// if the user's credentials are valid, call Firebase authentication service.
@swahaniroy
swahaniroy / login.js
Created May 26, 2022 15:11
The login.js file
// hide loading indicator.
hideLoading();
// get sign up container.
const signUpContainer = document.getElementById("signup");
// set up event for sign up close btn
const signUpCloseBtn = document.getElementById("signup__close-btn");
// set up event for create new account button.
const createNewAccountBtn = document.getElementById(
"login__create-account-btn"
);
@swahaniroy
swahaniroy / util.js
Created May 26, 2022 15:09
The Util.js File
const loading = document.getElementById('loading');
function hideLoading() {
loading.classList.add('loading--hide');
}
function showLoading() {
loading.classList.remove('loading--hide');
loading.classList.add('loading--active');
}
@swahaniroy
swahaniroy / auth.js
Created May 26, 2022 15:07
The Auth File
window.addEventListener('DOMContentLoaded', function() {
function shouldRedirectToHomePage(user, isLoginPage) {
return user && isLoginPage;
}
function shouldRedirectToLoginPage(user, isLoginPage) {
return !user && !isLoginPage;
}
CometChatWidget.init({
@swahaniroy
swahaniroy / login.html
Created May 26, 2022 15:05
The Login Page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link rel="stylesheet" href="/css/styles.css">
<script
defer