Skip to content

Instantly share code, notes, and snippets.

@swahaniroy
swahaniroy / firebase.js
Created May 26, 2022 15:03
The firebase.js file
const firebaseConfig = {
apiKey: `${config.apiKey}`,
authDomain: `${config.authDomain}`,
databaseURL: `${config.databaseURL}`,
projectId: `${config.projectId}`,
storageBucket: `${config.storageBucket}`,
messagingSenderId: `${config.messagingSenderId}`,
appId: `${config.appId}`,
measurementId: `${config.measurementId}`
};
@swahaniroy
swahaniroy / config.js
Created May 26, 2022 14:41
Inject your secret keys
const config = {
apiKey: xxx-xxx-xxx-xxx-xxx-xxx-xxx-xxx,
authDomain: xxx-xxx-xxx-xxx-xxx-xxx-xxx-xxx,
databaseURL: xxx-xxx-xxx-xxx-xxx-xxx-xxx-xxx,
projectId: xxx-xxx-xxx-xxx-xxx-xxx-xxx-xxx,
storageBucket: xxx-xxx-xxx-xxx-xxx-xxx-xxx-xxx,
messagingSenderId: xxx-xxx-xxx-xxx-xxx-xxx-xxx-xxx,
appId: xxx-xxx-xxx-xxx-xxx-xxx-xxx-xxx,
measurementId: xxx-xxx-xxx-xxx-xxx-xxx-xxx-xxx,
CometChatAppId: xxx-xxx-xxx-xxx-xxx-xxx-xxx-xxx,
@swahaniroy
swahaniroy / install.js
Created May 26, 2022 14:36
Installing the dependencies
npm install -g http-server
@swahaniroy
swahaniroy / index.js
Created May 19, 2022 15:06
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 19, 2022 15:05
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 19, 2022 15:04
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 19, 2022 15:02
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 19, 2022 14:57
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 19, 2022 14:54
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 19, 2022 14:53
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"
);