├── .github └── workflows │ └── codeql-analysis.yml ├── .gitignore ├── .gitmodules ├── README.md ├── api ├── config.php ├── create-room │ └── index.php ├── create-token │ └── index.php ├── error.php ├── get-room │ └── index.php ├── room │ └── multi │ │ └── index.php └── utils.php └── config.js /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '24 8 * * 4' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v1 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v1 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | api/.env 2 | vendor 3 | .DS_Store 4 | client/.DS_Store -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "client"] 2 | path = client 3 | url = https://github.com/EnableX/One-to-One-Video-Sample-Web-Application.git 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Building a 1-to-1 Real-Time Communication Web App with PHP and EnableX Web Toolkit 2 | 3 | 1-to-1 RTC Web App: PHP and EnableX Web Toolkit 4 | 5 | Experience a Sample Web App showcasing EnableX platform APIs, designed for building fundamental 1-to-1 RTC (Real-Time Communication) Applications. Develop your skills by hosting this app on your own devices, reducing the need for external servers. 6 | 7 | RTC Applications on the EnableX platform operate seamlessly on supported web browsers, eliminating the need for extra plugin downloads. 8 | 9 | This basic 1-to-1 Video Chat Application is crafted using HTML, CSS, Bootstrap, JavaScript, jQuery, PHP, and EnxRtc (EnableX Web Toolkit) 10 | 11 | >The details of the supported set of web browsers can be found here: 12 | https://developer.enablex.io/video/browser-compatibility-of-enablex-video/ 13 | 14 | ## 1. Important! 15 | 16 | When developing a Client Application with EnxRtc.js make sure to include the updated EnxRtc.js polyfills from https://developer.enablex.io/video-api/client-api/web-toolkit/ for RTCPeerConnection and getUserMedia. Otherwise your application will not work in web browsers. 17 | 18 | 19 | ## 2. Trial 20 | 21 | Sign up for a free trial https://portal.enablex.io/cpaas/trial-sign-up/ or try our multiparty video chat https://try.enablex.io/. 22 | 23 | 24 | ## 3. Installation 25 | 26 | ### 3.1 Pre-Requisites 27 | 28 | #### 3.1.1 App Id and App Key 29 | 30 | * Register with EnableX [https://portal.enablex.io/cpaas/trial-sign-up/] 31 | * Create your Application 32 | * Get your App ID and App Key 33 | * Clone this repository `git clone https://github.com/EnableX/One-to-One-Video-Calling-Open-Source-PHP-Application.git --recursive` 34 | ### ![#f03c15](https://via.placeholder.com/15/f03c15/000000?text=+) Please note `--recursive` option. Repo should be cloned recursively to download `client` app. 35 | * You can copy the app into any sub-directory of hosted website on Apache 36 | 37 | #### 3.1.2 SSL Certificates 38 | 39 | The Application needs to run on https. So, you need to use a valid SSL certificate for your domain and point your application to use them. 40 | 41 | However you may use self-signed Certificate to run this application locally. There are many Web Sites to get a Self-Signed Certificate generated for you, Google it. Few among them are: 42 | 43 | * https://letsencrypt.org/ 44 | * https://www.sslchecker.com/csr/self_signed 45 | * https://www.akadia.com/services/ssh_test_certificate.html 46 | 47 | Alternatively you can create your self-signed certificate as below 48 | ```javascript 49 | sudo openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.crt -days 10000 -nodes 50 | sudo mv server.crt /etc/ssl/certs/ssl.crt 51 | sudo mv server.key /etc/ssl/private/ssl.key 52 | ``` 53 | Enable mod ssl and turn on ssl server 54 | ```javascript 55 | sudo a2enmod ssl 56 | sudo a2ensite default-ssl 57 | sudo service apache2 restart 58 | ``` 59 | 60 | #### 3.1.3 Configure 61 | 62 | * Before you can run this application, configure the service by editing `api/config.php` file to use your app ID and app key 63 | 64 | ```javascript 65 | define("API_URL", "https://api.enablex.io/v1"); 66 | define("APP_ID", "YOUR_APP_ID"); 67 | define("APP_KEY", "YOUR_APP_KEY"); 68 | ``` 69 | 70 | * Configure your application base URL by editing `config.js` file 71 | 72 | ``` 73 | var baseUrl = 'Your Application Base URL'; 74 | ``` 75 | 76 | ### 3.2 Test video call 77 | 78 | * Open a browser and go to `https://localhost:443/path-to-sample-app/client/`. The browser should load the App. 79 | * Go to -> Advanced -> Proceed to localhost 80 | * `Don't have a Room ID? Create One` (it creates a new Room ID) and have it pre-filled 81 | * Store the `Room ID` for future use or share it 82 | * Enter a user `Name` (e.g. test0) 83 | * Select `Join as Moderator` 84 | * `Sign In` and allow access to camera and microphone when prompted to start your first webRTC call through EnableX 85 | * Open another browser tab and enter `https://localhost:443/path-to-sample-app/client/` 86 | * Enter the same `Room ID` previously created, add a different user `Name` (e.g. test1) and select `Join as Participant` and click `Sign In` 87 | * Now, you should see your own video in both the tabs! 88 | 89 | ### 3.3 Test screen share 90 | 91 | * Once video call started, click on 'Desktop' icon to start screen share. 92 | * Once screen share started, layout for the presenter remain same (side by side video). However screen which is shared by presentor, is displayed to the person on other side by hiding the previous layout (side by side video). 93 | * Click on 'Desktop' icon to again to stop screen share. 94 | 95 | 96 | ## 4 Server API 97 | 98 | EnableX Server API is a Rest API service meant to be called from Partners' Application Server to provision video enabled 99 | meeting rooms. API Access is given to each Application through the assigned App ID and App Key. So, the App ID and App Key 100 | are to be used as Username and Password respectively to pass as HTTP Basic Authentication header to access Server API. 101 | 102 | For this application, the following Server API calls are used: 103 | * https://developer.enablex.io/video-api/server-api/rooms-route/#create-room - To create room to carry out a video session 104 | * https://developer.enablex.io/video-api/server-api/rooms-route/#create-token - To create Token for the given Room to join a session 105 | 106 | To know more about Server API, go to: 107 | https://developer.enablex.io/video-api/server-api/ 108 | 109 | 110 | ## 5 Client API 111 | 112 | Client End Point Application uses Web Toolkit EnxRtc.js to communicate with EnableX Servers to initiate and manage RTC Communications. 113 | 114 | To know more about Client API, go to: 115 | https://developer.enablex.io/video-api/client-api/ 116 | -------------------------------------------------------------------------------- /api/config.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /api/create-room/index.php: -------------------------------------------------------------------------------- 1 | name && $data->role && $data->roomId) { 39 | // create a Token for a given data 40 | $ret = CreateToken($data); 41 | if ($ret) { 42 | print $ret; 43 | exit; 44 | } 45 | } else { 46 | $error = $appError['4004']; // Required JSON Key missing 47 | $error['desc'] = 'JSON keys missing: name, role or roomId'; 48 | print json_encode($error); 49 | exit; 50 | } 51 | -------------------------------------------------------------------------------- /api/error.php: -------------------------------------------------------------------------------- 1 | '4001', 'error' => 'Required parameter missing']; 6 | $appError['4002'] = ['result' => '4002', 'error' => 'Required JSON Body missing']; 7 | $appError['4003'] = ['result' => '4003', 'error' => 'JSON Body Error']; 8 | $appError['4004'] = ['result' => '4004', 'error' => 'Required Key missing in JSON Body']; 9 | $appError['4005'] = ['result' => '4005', 'error' => 'Invalid Key value JSON Body']; 10 | $appError['4006'] = ['result' => '4006', 'error' => 'Forbidden. Not privileged to access data']; 11 | 12 | $appError['1001'] = ['result' => '1001', 'error' => 'Authentication failed']; 13 | $appError['1002'] = ['result' => '1002', 'error' => 'Requested Data not found']; 14 | $appError['1003'] = ['result' => '1003', 'error' => 'Mailing Error']; 15 | $appError['1004'] = ['result' => '1004', 'error' => 'Data Error']; 16 | 17 | $appError['5001'] = ['result' =>'5001', 'error' => 'Invalid HTTP Request']; 18 | $appError['5002'] = ['result' =>'5002', 'error' => 'System Settings/DB Setup Issues']; 19 | -------------------------------------------------------------------------------- /api/get-room/index.php: -------------------------------------------------------------------------------- 1 | 'room for one to one video meeting: ' . $randomName, 18 | 'owner_ref' => $randomName, 19 | 'settings' => [ 20 | 'scheduled' => false, 21 | 'adhoc' => true, 22 | 'moderators' => '1', 23 | 'participants' => '1', 24 | 'duration' => '30', 25 | 'quality' => 'SD', 26 | 'auto_recording' => false, 27 | ], 28 | ]; 29 | 30 | /* CURL POST Request */ 31 | return httpPost(API_URL . '/rooms/', json_encode($room)); 32 | } 33 | 34 | /* 35 | * To create a Conference Room in EnableX - using contact room information. 36 | * @return: result in json format with room-meta of newly created room 37 | */ 38 | function createRoomMulti() 39 | { 40 | $randomName = rand(100000, 999999); 41 | 42 | /* Create Room Meta */ 43 | $room = [ 44 | 'name' => 'room for multi party video meeting: ' . $randomName, 45 | 'owner_ref' => $randomName, 46 | 'settings' => [ 47 | 'scheduled' => false, 48 | 'adhoc' => true, 49 | 'moderators' => '1', 50 | 'participants' => '5', 51 | 'duration' => '30', 52 | 'quality' => 'SD', 53 | 'auto_recording' => false, 54 | ], 55 | ]; 56 | 57 | /* CURL POST Request */ 58 | return httpPost(API_URL . '/rooms/', json_encode($room)); 59 | } 60 | 61 | /* 62 | * To get information of a given room 63 | * @param: string roomId 64 | * @return: Returns Room Meta 65 | */ 66 | function getRoom($roomId) 67 | { 68 | /* CURL GET Request */ 69 | return httpGet(API_URL . '/rooms/' . $roomId); 70 | } 71 | 72 | /* 73 | * To create a Token for a given room 74 | * @return: result in json format with created token 75 | */ 76 | function createToken($data) 77 | { 78 | /* Create Token Payload */ 79 | $token = [ 80 | 'name' => $data->name, 81 | 'role' => $data->role, 82 | 'user_ref' => $data->user_ref 83 | ]; 84 | 85 | /* CURL POST Request */ 86 | return httpPost(API_URL . '/rooms/' . $data->roomId . '/tokens', json_encode($token)); 87 | } 88 | 89 | /* 90 | * Utility function for creating API header 91 | * @return: API header 92 | */ 93 | function appHeader() 94 | { 95 | /* Prepare HTTP Post Request */ 96 | return [ 97 | 'Content-Type: application/json', 98 | 'Authorization: Basic '. base64_encode(APP_ID . ':' . APP_KEY) 99 | ]; 100 | } 101 | 102 | /* 103 | * Utility function for making curl POST request 104 | * @return: response of http request 105 | */ 106 | function httpPost($url, $params) 107 | { 108 | $ch = curl_init($url); 109 | curl_setopt($ch, CURLOPT_HTTPHEADER, appHeader()); 110 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 111 | curl_setopt($ch, CURLOPT_POST, true); 112 | curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 113 | $response = curl_exec($ch); 114 | 115 | curl_close($ch); 116 | 117 | return $response; 118 | } 119 | 120 | /* 121 | * Utility function for making curl GET request 122 | * @return: response of http request 123 | */ 124 | function httpGet($url) 125 | { 126 | $ch = curl_init($url); 127 | curl_setopt($ch, CURLOPT_HTTPHEADER, appHeader()); 128 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 129 | curl_setopt($ch, CURLOPT_POST, false); 130 | $response = curl_exec($ch); 131 | 132 | curl_close($ch); 133 | 134 | return $response; 135 | } 136 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | var baseUrl = 'https://localhost/web-1to1-conf-php'; 2 | --------------------------------------------------------------------------------