Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.
Merged
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
25 changes: 25 additions & 0 deletions .github/workflows/build-client-observability-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build Client-Observability-Java

on:
push:
branches: [main] # Just in case main was not up to date while merging PR
pull_request:
types: [opened, synchronize]

jobs:
run:
continue-on-error: true
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: checkout
uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17

- name: Build
run: cd Client-Observability-Java && ./gradlew app:assembleRelease && cd ..
15 changes: 15 additions & 0 deletions Client-Observability-Java/.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/
95 changes: 95 additions & 0 deletions Client-Observability-Java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Client Observability Java

This application, built on top of Basic Video Chat, showcases how to retriebe all statistics from the entire system, being they from session, publisher and/or subscriber level.

## Code sample - Subscriber Stats

The user can retrieve video stats, conatining information such as ```videoPacketsLost``` and ```videoPacketsReceived``` by implementing listener SubscriberKit.VideoStatsListener.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo. containing


It is also possible to access estimated sender stats (```currentBitrate``` and ```maxBitrate```). For this it is necessary making sure publisher enables sender statistics track. By default it is not enabled.


```java

publisher = new Publisher.Builder(MainActivity.this).senderStatsTrack(true).build();
session.publish(publisher);


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. too many empty lines?

...


subscriber = new Subscriber.Builder(MainActivity.this, stream).build();
subscriber.getRenderer().setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL);
subscriber.setSubscriberListener(subscriberListener);
subscriber.setVideoStatsListener(videoStatsListener);
session.subscribe(subscriber);

...

SubscriberKit.VideoStatsListener videoStatsListener = new SubscriberKit.VideoStatsListener() {
@Override
public void onVideoStats(SubscriberKit subscriber, SubscriberKit.SubscriberVideoStats stats) {
Log.d(TAG, "onVideoStats: Data received");
Log.d(TAG, "onVideoStats: Sender Stats connectionEstimatedBandwidth" + (stats.senderStats != null ? stats.senderStats.connectionEstimatedBandwidth : "NULL"));
Log.d(TAG, "onVideoStats: Sender Stats connectionMaxAllocatedBitrate" + (stats.senderStats != null ? stats.senderStats.connectionMaxAllocatedBitrate : "NULL"));
Log.d(TAG, "onVideoStats: videoBytesReceived" + stats.videoBytesReceived);
Log.d(TAG, "onVideoStats: timeStamp" + stats.timeStamp);
Log.d(TAG, "onVideoStats: videoPacketsLost" + stats.videoPacketsLost);
Log.d(TAG, "onVideoStats: videoPacketsReceived" + stats.videoPacketsReceived);
}
};
```

# 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 Client-Observability-Java/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build
config.gradle
*.jar
*.so
45 changes: 45 additions & 0 deletions Client-Observability-Java/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
plugins {
id 'com.android.application'
}

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

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

defaultConfig {
applicationId "com.tokbox.sample.clientobservability"
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}"
}
33 changes: 33 additions & 0 deletions Client-Observability-Java/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tokbox.sample.clientobservability" >

<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.BLUETOOTH" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<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=".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>
</application>

</manifest>
Loading
Loading