Skip to content

VIDCS-3685: Connection Service integration with FCM for notifications push #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Basic-Video-Chat-ConnectionService_FCM/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# intellij
*.iml

.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
app/build

.settings/
app/jniLibs/
62 changes: 62 additions & 0 deletions Basic-Video-Chat-ConnectionService_FCM/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Basic Video Chat ConnectionService FCM Java

This application provides a completed version of the OpenTok [Basic Video Chat tutorial](https://tokbox.com/developer/tutorials/android/) for Android (differing only in some additional validation checks). Upon deploying this sample application, you should be able to have two-way audio and video communication using OpenTok.

Main features:
* Connect to an OpenTok session
* Publish an audio-video stream to the session
* Subscribe to another client's audio-video stream

# Configure the app
Open the `OpenTokConfig` file and configure the `API_KEY`, `SESSION_ID`, and `TOKEN` variables. You can obtain these values from your [TokBox account](https://tokbox.com/account/#/).

### (Optional) Deploy a back end web service

For a production application, the `SESSION_ID` and `TOKEN` values must be generated by your app server application and passed to the client, because:
- credentials would expire after a certain amount of time
- credentials are lined to given session (all users would be connected to the same room)

To quickly deploy a pre-built server click at one of the Heroku buttons below. You'll be sent to Heroku's website and prompted for your OpenTok `API Key` and `API Secret` — you can obtain these values on your project page in your [TokBox account](https://tokbox.com/account/user/signup). If you don't have a Heroku account, you'll need to sign up (it's free).

| PHP server | Node.js server|
| ------------- | ------------- |
| <a href="https://heroku.com/deploy?template=https://github.com/opentok/learning-opentok-php" target="_blank"> <img src="https://www.herokucdn.com/deploy/button.png" alt="Deploy"></a> | <a href="https://heroku.com/deploy?template=https://github.com/opentok/learning-opentok-node" target="_blank"> <img src="https://www.herokucdn.com/deploy/button.png" alt="Deploy"></a> |
| [Repository](https://github.com/opentok/learning-opentok-php) | [Repository](https://github.com/opentok/learning-opentok-node) |

> Note: You can also build your server from scratch using one of the [server SDKs](https://tokbox.com/developer/sdks/server/).

After deploying the server open the `ServerConfig` file in this project and configure the `CHAT_SERVER_URL` with your domain to fetch credentials from the server:

```java
public static final String CHAT_SERVER_URL = "https://YOURAPPNAME.herokuapp.com";
```

> Note that this application will ignore credentials in the `OpenTokConfig` file when `CHAT_SERVER_URL` contains a valid URL.

This is the code responsible for retrieving the credentials from web server:

```java
private void getSession() {
Log.i(TAG, "getSession");

Call<GetSessionResponse> call = apiService.getSession();

call.enqueue(new Callback<GetSessionResponse>() {
@Override
public void onResponse(Call<GetSessionResponse> call, Response<GetSessionResponse> response) {
GetSessionResponse body = response.body();
initializeSession(body.apiKey, body.sessionId, body.token);
}

@Override
public void onFailure(Call<GetSessionResponse> call, Throwable t) {
throw new RuntimeException(t.getMessage());
}
});
}
```

## Further Reading

* Review [other sample projects](../)
* Read more about [OpenTok Android SDK](https://tokbox.com/developer/sdks/android/)
4 changes: 4 additions & 0 deletions Basic-Video-Chat-ConnectionService_FCM/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build
config.gradle
*.jar
*.so
49 changes: 49 additions & 0 deletions Basic-Video-Chat-ConnectionService_FCM/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
id 'com.android.application'
}

apply {
from '../../commons.gradle'
}

android {
namespace "com.tokbox.sample.basicvideochat_connectionservice"
compileSdkVersion extCompileSdkVersion

defaultConfig {
applicationId "com.tokbox.sample.basicvideochat_connectionservice"
minSdkVersion extMinSdkVersion
targetSdkVersion extTargetSdkVersion
versionCode extVersionCode
versionName extVersionName
}

buildTypes {
release {
minifyEnabled extMinifyEnabled
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

dependencies {
// Dependency versions are defined in the ../../commons.gradle file
implementation "com.opentok.android:opentok-android-sdk:${extOpentokSdkVersion}"
implementation "androidx.appcompat:appcompat:${extAppCompatVersion}"
implementation "pub.devrel:easypermissions:${extEasyPermissionsVersion}"
implementation "androidx.constraintlayout:constraintlayout:${extConstraintLyoutVersion}"

implementation "com.squareup.retrofit2:retrofit:${extRetrofitVersion}"
implementation "com.squareup.okhttp3:okhttp:${extOkHttpVersion}"
implementation "com.squareup.retrofit2:converter-moshi:${extRetrofit2ConverterMoshi}"
implementation "com.squareup.okhttp3:logging-interceptor:${extOkHttpLoggingInterceptor}"
implementation 'com.google.firebase:firebase-messaging:24.1.1'
implementation 'org.json:json:20250107'
}

apply plugin: 'com.google.gms.google-services'
67 changes: 67 additions & 0 deletions Basic-Video-Chat-ConnectionService_FCM/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"project_info": {
"project_number": "292924425678",
"project_id": "vonageconnectionservice",
"storage_bucket": "vonageconnectionservice.firebasestorage.app"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:292924425678:android:48518cc8cb40a7c1ad579f",
"android_client_info": {
"package_name": "com.tokbox.android.vonagemeet"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyCvXYcWVJDs8aXZZEEy4KmBM4OXtbqK-S0"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:292924425678:android:63250fc79cd2e76fad579f",
"android_client_info": {
"package_name": "com.tokbox.sample.basicvideochat_connectionservice"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyCvXYcWVJDs8aXZZEEy4KmBM4OXtbqK-S0"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:292924425678:android:9fddbf141f47cc67ad579f",
"android_client_info": {
"package_name": "com.vonage.vonagemeet"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyCvXYcWVJDs8aXZZEEy4KmBM4OXtbqK-S0"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tokbox.sample.basicvideochat_connectionservice" >

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
<uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE" />


<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.tokbox.sample.basicvideochat_connectionservice.MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name="com.tokbox.sample.basicvideochat_connectionservice.MyFirebaseMessagingService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<meta-data
android:name="android.telecom.connectionService"
android:value="com.tokbox.sample.basicvideochat_connectionservice.VonageConnectionService" >
</meta-data>

<service
android:name="com.tokbox.sample.basicvideochat_connectionservice.VonageConnectionService"
android:exported="true"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE" >
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tokbox.sample.basicvideochat_connectionservice;

public interface CallEventListener {
void onIncomingCall(String callerName, String callStatus);
}
Loading
Loading