This repository was archived by the owner on Feb 20, 2026. It is now read-only.
Repository navigation
VIDCS-4092: Simple public sample for sender-side stats for subscribers in Android #554
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
72d7ae9
Sender Side statistics showcase added to Client Observability sample
goncalocostamendes 8a0c421
Add documentaiton on README
goncalocostamendes 1389123
Update senderStatsTrack function name
goncalocostamendes 40db07f
Merge branch 'main' into VIDCS-4092
goncalocostamendes 3735647
Update to new variable names
goncalocostamendes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 .. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
| 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); | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /build | ||
| config.gradle | ||
| *.jar | ||
| *.so |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
33
Client-Observability-Java/app/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo. containing