{"id":20364361,"url":"https://github.com/bandwidth/webrtc_mobile","last_synced_at":"2025-07-04T04:38:25.761Z","repository":{"id":44736941,"uuid":"445254039","full_name":"Bandwidth/webrtc_mobile","owner":"Bandwidth","description":null,"archived":false,"fork":false,"pushed_at":"2022-01-27T21:18:49.000Z","size":17222,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-01-15T04:19:20.689Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bandwidth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-06T17:26:47.000Z","updated_at":"2022-02-23T20:33:48.000Z","dependencies_parsed_at":"2022-09-09T05:51:41.725Z","dependency_job_id":null,"html_url":"https://github.com/Bandwidth/webrtc_mobile","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bandwidth%2Fwebrtc_mobile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bandwidth%2Fwebrtc_mobile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bandwidth%2Fwebrtc_mobile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bandwidth%2Fwebrtc_mobile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bandwidth","download_url":"https://codeload.github.com/Bandwidth/webrtc_mobile/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241904683,"owners_count":20040021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T00:11:24.830Z","updated_at":"2025-03-04T18:44:26.189Z","avatar_url":"https://github.com/Bandwidth.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Native iOS/Android calling via Bandwidth WebRTC\n\n\u003e **NOTICE: SAMPLE CODE** This project is a rapid prototype it is meant as a sample app not production code!\n\n- [x] AWS Amplify project setup instructions\n- [x] AWS Lambda sample back-end code\n- [x] Android sample native app\n- [ ] AWS CDK deployment scripts\n- [ ] iOS sample native app\n\n## Contents:\n- [Android: Setup Firebase Project](https://firebase.google.com/docs/cloud-messaging/android/first-message?authuser=0#create_a_firebase_project)\n- [Android: WebRTC Sample App README](https://github.com/Bandwidth/webrtc_mobile/tree/main/android#readme)\n- iOS README -- TODO\n- [Backend: AWS Amplify Install \u0026 Configure](https://github.com/Bandwidth/webrtc_mobile#backend--installation--building)\n\n## Sample Message Flow\n\n![Sample Message Flow](/WebRTC-Mobile-App-Ladder-Diagram.png)\n\n## Backend : Installation \u0026 Building\n\n\u003e The included CDK project to deploy the backend does not currently work due to some CDK vs Amplify versioning issues which should be resolved in a few weeks.  We appologize for the inconvenience - we have documented the complete sequence to create and deploy a working Amplify backend using the AWS Console and AWS CLI below.\n\n### Login to the AWS console:\n   aws.amazon.com\n\n### Go to Amplify:\n   https://console.aws.amazon.com/amplify/home\n\n### Amplify -\u003e New App -\u003e Build an App\n  - Enter name for the app (eg: bturner-webrtc-mobile)\n  - Wait for Amplify console to complete deployment\n  - Click \"Launch Studio\"\n  - Wait for Amplify Studio to launch\n  - In upper-right, click \"Local setup instructions\"\n  - Small window displays a CLI command like this:\n       ```console\n       (EXAMPLE) amplify pull --appId \u003c\u003cAPP_ID\u003e\u003e --envName staging\n       ```\n  - Copy the CLI command\n\n### Install AWS CLI:\n   https://aws.amazon.com/cli/\n\n### Open new Terminal window\n\n  - You will need your AWS credentials (API Key and Token) from an [AWS IAM](https://console.aws.amazon.com/iamv2/home#/users) user\n  - **Configure AWS credentials:**\n    ```console\n    aws configure\n    ```\n\n  - **Install AWS Amplify CLI:**\n    ```console\n    curl -sL https://aws-amplify.github.io/amplify-cli/install | bash \u0026\u0026 $SHELL\n    ```\n    - NOTE: The command above is different when installing on Windows\n\n  - **Create a new directory to hold your Amplify project**\n    ```console\n    mkdir my-amplify-project\n    cd my-amplify-project\n    ```\n  - **Pull the Amplify project (copied CLI command from earlier)**\n    ```console\n    amplify pull --appId \u003c\u003cAPP_ID\u003e\u003e --envName staging\n    ```\n    - Browser will open and request access for Amplify CLI\n      - NOTE: You MUST already have launched Amplify Studio before this step!\n    - choose 'javascript' for 'type of app'\n    - choose 'none' for 'javascript framework'\n    - choose defaults for the directories\n    - choose defaults for build/start commands\n    - choose YES for 'modify this backend'\n\n  - **Add Authentication**\n    ```console\n    amplify auth add\n    ```\n    - Default configuration\n    - Username\n    - No additional capabilities\n\n  - **Add Analytics**\n    ```console\n    amplify analytics add\n    ```\n    - Amazon Pinpoint\n    - Select default options\n\n  - **Add GraphQL API**\n    ```console\n    amplify api add\n    ```\n    - GraphQL\n    - Blank Schema\n    - Edit Schema: YES\n    - Replace defaults in editor with schema below, then save:\n\n```\ntype Person @model @auth(rules: [{ allow: public }]) {\n  id: ID!\n  firstName: String!\n  lastName: String!\n  clientId: String!\n}\n\ntype DeviceInfo @model @auth(rules: [{ allow: public }]) {\n  id: ID!\n  notifyType: String!\n  deviceToken: String!\n\n  sessionId: String\n  participantId: String\n  participantToken: String\n}\n```\n\n  - **Add Function**\n    ```console\n    amplify function add\n    ```\n    - choose \"Lambda function\"\n    - choose \"NodeJS\"\n    - choose \"Hello World\"\n    - choose YES to \"advanced settings\"\n      - choose \"Yes\" to \"other resources\"\n      - Add API, Analytics, Storage\n         - Allow ALL operations for all resources\n      - No recurring invocations\n      - No Lambda layers\n      - YES environment variables:\n      ```\n          PINPOINT_APP_ID -- Use placeholder value\n          GRAPH_QL_KEY -- Use placeholder value\n          GRAPH_QL_API_URL  -- Use placeholder values\n          BW_ACCOUNT_ID -- Enter your Bandwidth account ID\n          BW_USERNAME -- Enter your Bandwidth username\n          BW_PASSWORD -- Enter your Bandwidth password\n      ```\n      - No secret values\n      - Yes edit lambda function\n        - Replace hello-world Lambda function with code from the following file, then save:\n\n         [Lambda Function: index.js](https://github.com/Bandwidth/webrtc_mobile/blob/main/backend/index.js)\n         \n      - Now change directory into the Lambda's src (location of \"index.js\")\n         - eg: my-amplify-project/amplify/backend/function/\u003c\u003cLAMBDA_NAME\u003e\u003e/src\n      - Edit the \"package.json\" file located here\n         - eg: my-amplify-project/amplify/backend/function/\u003c\u003cLAMBDA_NAME\u003e\u003e/src/package.json\n         - Add a line, then save:\n         ```console\n         {\n         ...\n            \"type\":\"module\",\n         ...\n         }\n         ```\n      - Install additional NPM packages:\n         ```console\n         npm i @bandwidth/webrtc aws-sdk axios graphql-tag graphql uuid\n         ```\n      \n  - **Add REST API**\n    ```console\n    amplify api add\n    ```\n    - REST\n    - Accept the default label\n    - Path:  ``` /api ```\n    - Use existing lambda function\n    - No restrictions\n    - No more APIs\n\n  - **Push project**\n    ```console\n    amplify push\n    ```\n    - select defaults to generate code, compile schemas, etc.\n    - wait for project to finish deploying\n    - Copy the output values:\n    ```\n       GraphQL endpoint: (EXAMPLE) https://7bEXAMPLEfyu.appsync-api.us-east-1.amazonaws.com/graphql\n       GraphQL API KEY: (EXAMPLE) da2-egolfEXAMPLEdv37wjtm\n       REST API endpoint: (EXAMPLE) https://jmEXAMPLE4i.execute-api.us-east-1.amazonaws.com/staging\n    ```\n\n  - **Configure Amazon Pinpoint**\n    https://console.aws.amazon.com/pinpoint/home\n    - Choose the newly made Pinpoint project\n    - Copy the ProjectID\n      eg: ``` (EXAMPLE) 4d8065387dexample9f1d680b399 ```\n    - Settings -\u003e Push Notifications -\u003e Edit\n    - ANDROID:\n      - Add [FCM Server Key](https://firebase.google.com/docs/cloud-messaging/server)\n         - This requires creating an account and application with FCM.\n         - Configure the [Firebase Channel](https://docs.aws.amazon.com/pinpoint/latest/userguide/channels-push-manage.html) of Pinpoint with the server key you have acquired in the AWS Console.\n    - iOS:\n      - **TODO:** Similar steps will be performed to upload a `.p12` certificate to enable iOS notifications when an iOS version is available.\n\n\n   - **Update GraphQL with AutoMerge**\n      ```console\n      amplify api update\n      ```\n      - GraphQL\n      - Enable conflict detection\n      - Auto Merge\n      - YES override default per-model\n      - Select ALL models\n      - Select Auto Merge for each model\n\n  - **Update Environment Variables for the Lambda** ([docs here](https://aws.amazon.com/blogs/mobile/configure-environment-variables-and-secrets-for-your-lambda-functions-with-amplify-cli/))\n      ```console\n      amplify function update\n          PINPOINT_APP_ID   -- from Pinpoint ProjectID\n          GRAPH_QL_KEY      -- from Amplify push output\n          GRAPH_QL_API_URL  -- from Amplify push output\n      ```\n\n  - **Push final project**\n    ```console\n    amplify push\n    ```\n    - Back end should now be up \u0026 configured to run!\n\n\n### Testing\n\n- Using curl or Postman, etc. you can invoke the Lambda API to see if it is running correctly\n- POST to the REST API endpoint returned by ``` amplify status ```\n- NOTE: be sure to add ``` /api ``` to the end of the REST endpoint\n\n   ``` (EXAMPLE) https://jmEXAMPLE4i.execute-api.us-east-1.amazonaws.com/staging/api ```\n- **Register a new user (POST):**\n    ```\n    {\n        \"action\":\"register\",\n        \"notifyType\": \"GCM\",\n        \"deviceToken\": \"....\",\n    }\n    ```\n    - Returns a clientId:\n    ```\n    {\n        \"id\": \"c1aae098-7da1-4361-812f-91eea97a1f17\",\n        ...\n    }\n    ```\n    \n- **Delete clients (POST):**\n    ```\n    {\n        \"action\":\"deleteClientIds\",\n        \"clientIds\":[\"c1aae098-7da1-4361-812f-91eea97a1f17\"]\n    }\n    ```\n    - Returns:\n    ```\n    {\n      \"deletedIds\": [{\"id\": \"c1aae098-7da1-4361-812f-91eea97a1f17\"}]\n    }\n    ```\n\n## Resources Used\n\nThe backend is hosted on AWS with the following resources:\n\n| Resource | Description                                                                                                                                                                                                                                                                                                                                                                                                      |\n| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| Amplify  | Wrapper for entire project, acts like git to host all resources and code                                                                                                                                                                                                                                                                                                                                         |\n| Pinpoint | Notification service for push notifications. This service itself invokes Firebase Cloud Management (FCM) for Android and APNS for iOS devices                                                                                                                                                                                                                                                                    |\n| Lambda   | Two Lambdas are used in this project. One invokes Pinpoint to send push notifications and the other acts as a REST endpoint to manage calls, register users, and invoke the Pinpoint Lambda. Both are written in Node.                                                                                                                                                                                           |\n| AppSync  | Wrapped by Amplify; AppSync manages the app state and synchronizes said state with the frontends. Data is held in a DynamoDB table and transferred through generated GraphQL wrappers.                                                                                                                                                                                                                           |\n| Cognito  | Cognito handles user registration. Upon first entering the app, users can create an account. Cognito requires a username, password, and email                                                                                                                                                                                                                                                                    |\n| DynamoDB | Never actually directly accessed - wrapped by AppSync and Amplify. Two entry tables are hosted here, 1) Person table detailing each user and 2) DeviceInfo detailing sensitive device tokens and webRTC session/participation information. A full implementation would likely decouple the DeviceInfo table entirely from the Amplify project, as not doing so provides all of this information to the front end |\n\n## Front-End / Back-End Flow\n\nRough API call flow between front end and back end\n\n### Native iOS/Android app launches\n\n- Request user's first \u0026 last name\n- Load Device Token for push notifications from native OS\n- Call API with:\n  ```\n  {\n      \"action\":\"register\",\n      \"notifyType\": \"GCM\",\n      \"deviceToken\": \"....\",\n  }\n  ```\n\n- Receive clientId in return:\n  ```\n  {\n      \"id\": \"d44bece7-4eee-4587-8682-a50a974bacde\",\n      ....\n  }\n  ```\n\n- Insert or Update Person record in GraphQL database\n  ```\n  type Person @model @auth(rules: [{ allow: public }]) {\n      id: ID!\n      firstName: String!\n      lastName: String!\n      clientId: String!\n  }\n  ```\n\n- Query for list of People from GraphQL\n- Display list for user to choose from\n\n### User chooses a Person to call:\n\n- When the user clicks on one of the People, use self-clientId and target-clientId to invoke \"initiateCall\":\n  ```\n  {\n      \"action\":\"initiateCall\",\n      \"calleeId\":\"... clientId of callee ...\",\n      \"callerId\":\"... clientId of caller ...\"\n  }\n  ```\n  \n- Receive \"participantToken\" in reply:\n  ```\n  {\n    \"token\": \"eyJhbGcEXAMPLEiIsInR5cCI6IkpXVCJ9.eyJhIEXAMPLEiOiIxODY1ZTVkYy1mY2I5LTRhOTUtOTA1Ny1jNjNmEXAMPLEEXAMPLEEXAMPENDI4MzEwMDksImlzcyI6InByZDowMCJ9.hl4VFBB-apesVgaEPEXAMPLENjAmwt9J9Zok\"\n  }\n  ```\n  \n- Use token to join WebRTC session\n\n### When the call ends, each user hangs up:\n\n- Each user cleans up their own call leg:\n  ```\n  {\n      \"action\":\"endCall\",\n      \"clientId\":\"... clientId of self ...\"\n  }\n  ```\n  \n- User can now make or receive another call\n\n### Bulk cleanup option:\n\n- Delete a list of clientIds, closing down WebRTC sessions, participants, etc.\n- Does not delete Person records\n  ```\n  {\n      \"action\":\"deleteClientIds\",\n      \"clientIds\":[\"..clientId A..\", \"..clientId B..\", \"..clientId C..\"]\n  }\n  ```\n\n## Recommended Reading\n\n\u003cul\u003e\n    \u003cli\u003eThe Code in this project is based on several example projects:\n        \u003cul\u003e\n            \u003cli\u003ehttps://docs.aws.amazon.com/pinpoint/latest/developerguide/send-messages-push.html\u003c/li\u003e\n            \u003cli\u003ehttps://docs.amplify.aws/lib/graphqlapi/graphql-from-nodejs/q/platform/js/\u003c/li\u003e\n            \u003cli\u003ehttps://github.com/Bandwidth-Samples/webrtc-hello-world-js\u003c/li\u003e\n        \u003c/ul\u003e\n    \u003c/li\u003e\n\u003c/ul\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbandwidth%2Fwebrtc_mobile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbandwidth%2Fwebrtc_mobile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbandwidth%2Fwebrtc_mobile/lists"}