chatting app documenation
Setup Server "Mongodb ,Nodejs and other tools"
1.
setup Server steps
Setup Mongodb :
Step 1- Initialation :
if you already have installed the mongodb and you remove it make sure your run this command :
First, remove any existing repository file for MongoDB.
sudo rm /etc/apt/sources.list.d/mongodb*.list
Next, add the key: (without the key, the repository will not load)
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E52529D4
Now, create a new MongoDB repository list file:
sudo bash -c 'echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-4.0.list'
Step 2 - Update the repository :
update the repository with the apt command:
sudo apt-get update
Step 3 - Install MongoDB
Now you can install MongoDB by typing this command:
sudo apt-get install -y mongodb-org
The MongoDB apt installer created a mongod.service file for Systemd automatically, so there is no need to create it manually anymore.
Start MongoDB and add it as a service to be started at boot time:
sudo systemctl start mongod
sudo systemctl enable mongod
Now check that MongoDB has been started on port 27017 with the netstat command.
sudo netstat -plntu
2. Configure MongoDB username and password :
When the MongoDB packages are installed you can configure username and password for the database server:
Step 1 - Open mongo shell :
Before you set up a username and password for MongoDB, you need to open the MongoDB shell on your server. You can login by typing:
mongo
If you get error:
Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_* environment variables are set correctly
try the command:
export LC_ALL=C
mongo
Step 2 - Switch to the database admin :
Once you`re in the MongoDB shell, switch to the database named admin:
use admin
Step 3 - Create the root user :
Create the root user with this command :
db.createUser({user:"admin", pwd:"admin123", roles:[{role:"root", db:"admin"}]})
Description : Create user admin with password admin123 and have the permission/role as root and the database is admin.
Now type exit to exit from MongoDB shell.
exit
And you are back on the Linux shell.
Step 4 - Enable MongoDB authentication and open MongoDB access up to all IPs :
Edit your MongoDB config file. On Ubuntu:
sudo nano /etc/mongod.conf
Scroll down to the #security: section and add the following line. Make sure to un-comment the security: line.
security:
authorization: 'enabled'
add the IP address of the server in the bind_ip line like this:
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 , 192.168.1.100
Replace 192.168.1.100 with the IP of your server, then restart MongoDB to apply the changes.
sudo service mongod restart
Now you can access the MongoDB database server over the network.
Edit the mongodb service file '/lib/systemd/system/mongod.service' with your editor.
sudo nano /lib/systemd/system/mongod.service
On the 'ExecStart' line 9, add the new option '--auth'.
ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf
Save the service file and exit nano.
Reload the systemd service:
sudo systemctl daemon-reload
Step 5 - Restart MongoDB and try to connect :
Now restart MongoDB and connect with the user created.
sudo service mongod restart
and connect to the MongoDB shell with this command:
mongo -u admin -p admin123 --authenticationDatabase admin
Now type exit to exit from MongoDB shell.
exit
Step 6 - Insert admin info & default settings:
run this command to insert admin info :
mongoimport -u admin -p "admin123" -d whatsclone -c admins --drop --file default-admin-info-db.json
then run this one to insert default settings :
mongoimport -u admin -p "admin123" --jsonArray -d whatsclone -c settings --drop --file app-settings-db.json
Replace whatsclone word with your database name in the demo is "admin".
the last thing make sure your remove the app-settings-db.json & default-admin-info-db.json for security reasons.
to gurante the connection to mongo database, make sure you allow the port "27017" in your firewall by run this command:
sudo ufw allow 27017
3 . Setup Nodejs & application for Production :
Before all that we need to install some needy tools :
firstly install nano to edit files by run this command :
apt-get update -y
apt-get upgrade -y
You need to install above modules seperately :
apt-get install wget -y
apt-get install vim -y
apt-get install nano
Step 1 - Install Nodejs & npm :
apt-get install python-software-properties
apt-get install curl
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
apt-get install nodejs
Check node & npm version
node -v
npm -v
Step 2 - Upload script to server :
before upload the script you need to create directory by run this command :
sudo mkdir -p /var/www/whatsclone
you can change "whatsclone" word to your prefer folder name
then run this command for FTP :
sudo chown root:root /var/www/whatsclone
the last thing upload the script backend to server .
Step 3 - Install All dependencies :
after the script upload run this command to install all dependencies inside package.json file :
npm install --production
Step 4 - Install Pm2 :
to install the Pm2 tool we need to run this command :
sudo npm install pm2@latest -g
pm2 list
Step 5 - Run the node application :
run commands to set dev mode to production mode and set port as 80 :
export NODE_ENV=production
export PORT=80
now we need to run our app on background usign pm2 tool by run this command :
first make sure you are in the path /var/www/whatsclone
pm2 start ./bin/www --name="app_name"
and run this to save the app :
pm2 save
command to show logs :
pm2 logs
command to show runing apps :
pm2 list
Install script
1. Install Script :
After run the node application now we will start install our application :
Step 1- Initialation :
go to link http://localhost/install
replace localhost with your domain or ip ex : http://192.163.2.1/install
for database inofrmation use the info from Restart MongoDB and try to connect step in this documentation. Then click next .
this is an exmaple :
after this step you can login to your dashboard by fill login form like this :
before test login make sure you've restart pm2 to save changes by run this command : pm2 restart app_name

Setup firebase
Firebase is used for notification so you need to create a firebase account and add google-services.json file in the root of /app/ (inside project)
1- Goto https://firebase.google.com/
1- Goto https://firebase.google.com/
Log in to your google account and add a new project :
Enter project name - select country and create project .
2- Now click on the settings icon on top and choose project settings. and add firebase to your android app
3- Choose a package name make sure you use same package name everywhere in Android Studio Facebook and dashboard. Click on register app and download and then click skip and move to firebase consol.
for certificate SHA-1 you can it by click on gradle the signing report :
4- Add downloaded json file in your app folder of project :
5- Click on CLOUD MESSAGING tab and you will get server key copy this key paste in the dashboard in the settings section :
in the Topic field please put your package name of your android app .
Setup Android side
1. Import Project :
In this video we will explain how to :
- Import android project.
- Edit package name .
- Edit notification icon.
- Edit the application name & app icon .
- Set the base url of backend.
2.Edit proguard file :
just replace the old package name with the old one .
3. Google maps key :
you can get one from here
by click on GET KEY button :
and put it in the strings.xml file :
Setup CALLS "Agora" & GHYPI & OTP & ADMOB
1. Setup CALLS "Agora.io" :
to setup ghypi go to this link :
https://dashboard.agora.io/
https://dashboard.agora.io/
create your project and get your app ID .
Then put it in strings.xml .
2. Setup GHYPI :
to setup ghypi go to this link :
https://developers.giphy.com/dashboard/
https://developers.giphy.com/dashboard/
create app and request an app key .they will ask for a screen shot has power by ghypi .
3. Setup OTP :
setup facebook account kit:
so you need to create your app on facebook console developers : go to :Once you create the app click on it to get into dashboard :
Now you need to click on add product to add Account kit then click setup :
so we finish setup facebook side on facebook console :
The last step is to copy the App ID on the top and Account Kit Client Token and past them on strings.xml file on android project :
also put the Account Kit Client Token in the dashboard side under settings section
setup twillio provider:
Once your create your account on Twilio web site ,then please follow this
4. Setup Admob :
This step for admob ,so you can cntrol your ads from your dashaboard panel:
this an old video but it's the same you get your values from admob dashboard and you put it on dashboard then enable ads :
one important thing is you need to put your google_application_id from your admob dashboard
follow this link to get your app id : https://support.google.com/admob/answer/7356431?hl=en
when you get put it in the strings.xml file as below :
Sources and Credits
I've used the following libraries as listed.
- Agora.io platforme for calls By Agora
- Fabric Crashlytics Kit By twitter
- libphonenumber Google’s common Java Library
- Facebook account kit By facebook
- RxJava Library: Reactive Extensions for the JVM.
- Retrofit Library: Type-safe HTTP client for Android and Java.
- WebRtc library: for peer-to-peer applications "voice / video conferencing".
- Socket.io library: Realtime application framework (client).
- ExoPlayer library: An extensible media player for Android.
- MP4 Parser library: A Java API to read, write and create MP4 files.
- ButterKnife library: Bind Android views and callbacks to fields and methods.
- Firebase Cloud Messaging: cloud solution for messages and notifications for Android.
- Google maps library: Java client library for Google Maps API Web Services.
- JetPack Android WorkManager Library: API makes it easy to schedule deferrable, asynchronous tasks that must be run reliably
- JetPack AndroidX: a major improvement to the original Android Support Library.
- Realm android library: an open source object database management system, initially for mobile.
- The theme i've used Adminator HTML5 Admin Template Designed by Colorlib it is free But you always need to state that Colorlib is the original author of this template.



















Comments
Post a Comment