Private Rooms in BlueChat

Creating Private Rooms:

For every occasion of two users needing to chat(video/ text/ data), we create a new room to facilitate and secure their communications.
Creating a room in BlueCam is done on your server with a single PHP command:
PHP
$BlueCam = new BlueCamAPI(array());
$roomId = $BlueCam->CreateRoom(array(
	"owner"=>"ownerUserId",
	"visitor"=>"visitorUserId"
));

Importance of the Databases

BlueCam stores some persistent data about the room in the database for systematic reference and to facilitate and streamline the WebRTC handshake and to retain key statistics about the call such as who was involved and the duration.
BlueCam uses an awesome, cross-platform database called PostgreSQL to handle our persistent data. You may already be using it for the rest of you application, in which case use the same database for BlueCam and just add the PrivateRooms and BlueCamMessages tables as desribed below. If you're not using PostgreSQL yet, read the next two sections about isntallation and configuring.

install.sh: Installing PHP, PostgreSQL, Apache2

BlueCam includes a convenience file to install all of the open-source dependencies with a single command:
Ubuntu Command Line
sudo bash install.sh
BlueCam stores some persistent data about the room in the database for systematic reference and to facilitate and streamline the WebRTC handshake and to retain key statistics about the call such as who was involved and the duration. Here are a few key install commands for the major technologies utilized: (see install.sh section below for convenience script)
Ubuntu Command Line
//Install Apache2 Web Server
apt-get install apache2 -y

//Install PHP 7
add-apt-repository ppa:ondrej/php  -y     
apt-get update -y
apt-get upgrade -y
apt-get install php7.0 php7.0-fpm -y
apt-get install php7.0-pgsql -y

//Install Postgre 9.6 (Ubuntu 14.04)
add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" -y
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
apt-get update -y
apt-get install postgresql-9.6 -y

//Install Postgre 9.6 (Ubuntu 16.04)
add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" -y
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
apt-get update -y
apt-get install postgresql-9.6 -y

PostgreSQL Users

To check if PostgreSQL is successfully installed, run the psql command. If you just installed the software and have not yet configured the users you may see an error, role does not exist. See the following code to configure your Ubuntu user with the access you need:
Ubuntu Command Line
psql
psql: FATAL:  role "ubuntu" does not exist

whoami
ubuntu  #Take note of your username for the below commands marked with USERNAME

#Run psql qith the default psql user, named postgres:
sudo -u postgres psql

#Change the default password to something more secure
alter user postgres password 'apassword';

#Create a psql user for your USERNAME
create user USERNAME createdb password 'PASSWORD'
#Create a database for your USERNAME
create database USERNAME owner USERNAME;
#Press Ctrl+Z To Exit psql shell

#You should now be able to connect with the psql command:
psql

Creating Database and User

PostgreSQL Command Line (psql)
#Make a New User if Needed
CREATE USER bluecam_user createdb PASSWORD 'YourSecurePassword';

#Create a New Database if Needed (Use your own if applicable)
CREATE DATABASE "BlueCam" owner bluecam_user;

#Ensure Permissions
GRANT ALL PRIVILEGES ON DATABASE "BlueCam" to bluecam_user;

#Conenct to Dataabse
\c "BlueCam"

#Make sure to update php/configDB.php
#Create PrivateRooms and BlueCamMessages tables with CREATE TABLE Queries, or by running php/installDBs.php

installDBs.php Install Tables Stript

Once you've installed and configured PostgreSQL and updated the configDB.php file, run the installDBs.php files to check your installation, config, and create any missing database tables.
Javascript
sudo php php/installDBs.php

The PrivateRooms Table

Here is the structure of the PrivateRooms Table for your reference or if you need to install manually.
PostgreSQL
CREATE TABLE IF NOT EXISTS "PrivateRooms" (
	"id" text PRIMARY KEY,
	"roomName" text default '',
	"roomDescription" text default '',
	"owner" text,
	"visitor" text,
	"ownerSeen" timestamp,
	"visitorSeen" timestamp,
	"ownerStatus" text default 'notstarted',
	"visitorStatus" text default 'notstarted',
	"ownerBrowser" text default 'unknown',
	"visitorBrowser" text default 'unknown',
	"_cBy" char(10) default '',
	"_lmBy" char(10) default '',
	"_cOn" timestamp NOT NULL,
	"_lm" timestamp NOT NULL
);

The BlueCamMessages Table

Here is the structure of the BlueCamMessages Table for your reference or if you need to install manually.
PostgreSQL
CREATE TABLE IF NOT EXISTS "BlueCamMessages" (
	"id" text PRIMARY KEY,
	"roomId" text not null,
	"type" text not null,
	"from" text,
	"to" text,
	"data" jsonb default '{"empty":1}',
	"when" timestamp default now(),
	"delivered" boolean default false,
	"_cBy" char(10) default '',
	"_lmBy" char(10) default '',
	"_cOn" timestamp NOT NULL,
	"_lm" timestamp NOT NULL
);
If you want a web based database admin tools, we suggest installing phppgadmin:
Javascript
sudo apt-get install phppgadmin

#Edit config file and comment out the directive: Require local 
sudo nano /etc/apache2/conf-available/phppgadmin.conf