• Stars
    star
    111
  • Rank 313,380 (Top 7 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sample app to test network connectivity and statistics (bps, packet-lost)

OpenTok Network Test

This repository contains sample code that shows how to diagnose if the client's call (publishing a stream to an OpenTok session) will be successful or not, given their network conditions. The network test can be implemented as a step the client runs before joining the session. Based on the test results, the app can decide if the client should be allowed to publish a stream to the session and whether that stream should publish video or use audio-only mode. The test is intended to be used in a session that connects two clients in a one-to-one call.

The network test is supported in:

JavaScript clients should use the sample code found here: https://github.com/opentok/opentok-network-test-js.

How does it work

The sample apps each do the following:

  1. Connect to an OpenTok session and publish a test stream to a test session.

    Note that the published test stream would be visible to all clients connected to the session. For this reason, you should use a separate test session (with a unique session ID) for the network test. Do not use the test session for your actual call. Use a separate OpenTok session (and session ID) to share audio-video streams between clients.

  2. Subscribe to your own test stream for a test period.

    During the test period, the video quality will stabilize, based on the available network connection quality.

  3. Collect the bitrate and packet loss statistics using the Network Stats API (see below).

  4. Compare the network stats against thresholds (see below) to determine the outcome of the test.

Please see the sample code for details.

Network Stats API

This API lets you dynamically monitor the following statistics for a subscriber's stream:

  • Audio and video bytes received

  • Audio and video packets lost

  • Audio and video packets received

This API is only available in sessions that use the OpenTok Media Router.

Thresholds and interpreting network statistics

You can use the network statistics to determine the ability to send and receive streams, and as a result have a quality experience during the OpenTok call.

Please keep in mind, every application's use case and every user's perception of the call quality is different. Therefore, you should adjust the default thresholds and timeframe in accordance with your use case and expectations. For example, the 720p, 30 fps video call requires a much better network connection than 320x480-pixel, 15 fps video. So, in that case, you need to set much higher threshold values in order to qualify a viable end user connection. Also, the longer you run the test, the more accurate the values you will receive will be. At the same time, you might want to switch between publishing video and audio-only, based on your specific use case.

The OpenTok Network Test is implemented as sample code to make it easier for developers to customize their application logic.

Below are examples of the thresholds for popular video resolution-frame rate combinations. The following tables interpret results (for audio-video sessions and audio-only sessions), with the following quality designations:

  • Excellent - None or imperceptible impairments in media

  • Acceptable - Some impairments in media, leading to some momentary disruptions

Audio-video streams

For the given qualities and resolutions, all the following conditions must met.

Quality Video resolution @ fps Video kbps Packet loss
Excellent 1280x720 @ 30 > 1000 < 0.5%
Excellent 640x480 @ 30 > 600 < 0.5%
Excellent 352x288 @ 30 > 300 < 0.5%
Excellent 320x240 @ 30 > 300 < 0.5%
Acceptable 1280x720 @ 30 > 350 < 3%
Acceptable 640x480 @ 30 > 250 < 3%
Acceptable 352x288 @ 30 > 150 < 3%
Acceptable 320x240 @ 30 > 150 < 3%

Note that the default publish settings for video are 640x480 pixels @ 30 fps in the OpenTok iOS SDK. The default is 352x288 @ 30 fps in the OpenTok Android SDK.

You can calculate the video kbps and packet loss based on the video bytes received and video packets received statistics provided by the Network Statistics API. See the sample app for code.

The video resolutions listed are representative of common resolutions. You can determine support for other resolutions by interpolating the results with the closest resolutions listed.

Audio-only streams

For the given qualities, the following conditions must met.

Quality Audio kbps Packet loss
Excellent > 30 < 0.5%
Acceptable > 25 < 5%

Note that you can calculate the audio kbps and packet loss based on the audio bytes received and audio packets received statistics provided by the API. See the sample apps for code.

Sample code

This repo includes sample code showing how to build a network test using the OpenTok Android and iOS client SDKs. Sample code for the OpenTok JavaScript SDK can be found here: https://github.com/opentok/opentok-network-test-js. Each sample shows how to determine the the appropriate audio and video settings to use in publishing a stream to an OpenTok session. To do this, each sample app publishes a stream to a test session and then uses the Network Stats API to check the quality of that stream. Based on the quality, the app determines what the client can successfully publish:

  • The client can publish an audio-video stream at the specified resolution.

  • The client can publish an audio-only stream.

  • The client is unable to publish.

Each sample subdirectory includes a README file that describes how the app uses the network stats API.

Frequently Asked Questions (FAQ)

  • Why does the OpenTok Network Stats API values are different from my Speedtest.net results?

    Speedtest.net tests your network connection, while the Network Stats API shows how the WebRTC engine (and OpenTok) will perform on your connection.

  • Why are the Network Stats API results inconsistent?

    The WebRTC requires some time to stabilize the quality of the call for the specific connection. If you will allow the network test to run longer, you should receive more consistent results. Also, please, make sure that you're using routed OpenTok session instead of a relayed on. For more information, see The OpenTok Media Router and media modes

  • Why the output values are really low even though my user is streaming Netflix movies?

    WebRTC is conservative in choosing the allowed bandwidth. For example, if there is another high-bandwidth consumer on the network, WebRTC will try to set its own usage to the minimum.

  • The network test shows the "Excellent" (or "Acceptable") result, but the video still gets pixilated during the call.

    You can increase the required thresholds to better qualify the end user connection. Please keep in mind, the network connection can change overtime, especially on mobile devices with changing network conditions.

  • Why do I get compilation errors on iOS or Android.

    You need to be using a recent and supported version of the OpenTok iOS SDK or OpenTok Android SDK.

More Repositories

1

opentok-android-sdk-samples

Sample applications illustrating best practices using OpenTok Android SDK.
Java
211
star
2

opentok-react-native

OpenTok React Native - a library for OpenTok iOS and Android SDKs
Swift
211
star
3

opentok-ios-sdk-samples

Example applications that use the OpenTok iOS SDK
Objective-C
200
star
4

opentok-web-samples

Sample applications for using OpenTok.js
JavaScript
196
star
5

opentok-node

OpenTok Server SDK for node.js
JavaScript
165
star
6

OpenTok-PHP-SDK

OpenTok PHP Server SDK
PHP
140
star
7

opentok-ios-sdk-samples-swift

Sample applications using the OpenTok iOS SDK in Swift
Swift
136
star
8

CallKit

A sample app to demonstrate how to integrate Apple CallKit into OpenTok iOS SDK
Objective-C
110
star
9

OpenTok-Ruby-SDK

OpenTok Server SDK for Ruby
Ruby
110
star
10

opentok-react

React components for OpenTok.js
JavaScript
107
star
11

opentok-rtc

OpenTok demo application
JavaScript
106
star
12

one-to-one-sample-apps

DEPRECATED: OpenTok One-to-One Communication Sample App
JavaScript
99
star
13

screensharing-extensions

Sample code for developing an OpenTok screen-sharing extension for Google Chrome and Firefox
HTML
80
star
14

Opentok-Python-SDK

OpenTok Python SDK
Python
73
star
15

Opentok-.NET-SDK

Official .NET Server SDK for OpenTok
C#
57
star
16

opentok-network-test-js

A node module that lets you check network connectivity to resources and services required to use OpenTok
TypeScript
57
star
17

broadcast-sample-app

OpenTok Broadcast Sample Application
JavaScript
54
star
18

opentok-react-native-samples

Sample applications using OpenTok and React Native
Java
52
star
19

accelerator-sample-apps-js

CSS
35
star
20

archiving-composer

Sample apps for using OpenTok archiving building blocks API and ffmpeg to generate composed files from individual archives
JavaScript
31
star
21

accelerator-core-ios

Syntax sugar of OpenTok iOS SDK with Audio/Video communication including screen sharing
Objective-C
31
star
22

learning-opentok-web

JavaScript
27
star
23

Opentok-Java-SDK

OpenTok Server SDK for Java
Java
26
star
24

learning-opentok-ios

Sample code for learning how to use the OpenTok iOS SDK
Objective-C
26
star
25

accelerator-core-js

Accelerator Core provides a simple way to integrate real-time audio/video into your web application using the OpenTok Platform
JavaScript
25
star
26

learning-opentok-php

PHP
25
star
27

learning-opentok-android

Java
25
star
28

opentok-video-call-center

Sample code for building a basic agent queuing system
Vue
20
star
29

opentok-elearning-samples

Sample applications highlighting integrations between OpenTok and Learning Management Systems (LMS)
JavaScript
19
star
30

opentok-linux-sdk-samples

OpenTok Linux SDK Samples
C++
16
star
31

web-components

Web Components to be used with OpenTok video
JavaScript
16
star
32

ARKitSample

Sample App using ARKit Apple framework
Swift
16
star
33

accelerator-screen-sharing-js

Accelerator Screen Sharing JS provides an easy way to get started in implementing interoperable screen sharing using the OpenTok platform.
JavaScript
16
star
34

opentok-hardware-setup.js

JavaScript
14
star
35

interactive-broadcast-js

JavaScript
13
star
36

accelerator-textchat-ios

OpenTok Text Chat Accelerator Pack enables text messages between mobile or browser-based devices.
Objective-C
13
star
37

learning-opentok-node

A sample app of OpenTok Node Server SDK
JavaScript
13
star
38

opentok-flutter-basic-video-chat

Kotlin
11
star
39

ARFrameMetadata

Sample application using the Frame Meta Data API on iOS with ARKit
Swift
10
star
40

opentok-webinar

Simple Webinar (1 to many broadcast) application powered by OpenTok WebRTC SDKs https://tokinar.herokuapp.com/
JavaScript
10
star
41

accelerator-sample-apps-ios

A comprehensive sample app built by OpenTok Accelerator Packs
Objective-C
10
star
42

json2code

Code generator for JSON serialization and deserialization on iOS and Android based on json schema
Java
9
star
43

opentok-windows-sdk-samples

Sample applications illustrating best practices using OpenTok Windows SDK
C#
9
star
44

accelerator-core-android

An easy way to integrate OpenTok SDK to any Android applications
Java
8
star
45

opentok-reconnection

Sample app to illustrate how reconnection feature works.
Java
7
star
46

insights-dashboard-sample

Sample React app utilizing the OpenTok Insights GraphQL API
JavaScript
6
star
47

accelerator-textchat-js

Accelerator Text Chat JS provides functionality you can add to your OpenTok applications that enables users to exchange text messages between mobile or browser-based devices.
JavaScript
6
star
48

opentok-nexmo-sip

OpenTok SIP Interconnect samples with Nexmo Voice API
JavaScript
5
star
49

opentok-archive-transcription-demo

Sample code for transcribing OpenTok video archives to text
JavaScript
5
star
50

interactive-broadcast-api

JavaScript
5
star
51

ux-components

Reusable React Components for TokBox
TypeScript
5
star
52

accelerator-sample-apps-android

A sample app built by OpenTok Accelerator Packs
Kotlin
4
star
53

accelerator-annotation-android

Java
4
star
54

interactive-broadcast-android

Java
3
star
55

accelerator-annotation-js

JavaScript
2
star
56

misc-opentok-accelerators

DEPRECATED: Old versions of the OpenTok Accelerator packs
JavaScript
2
star
57

accelerator-textchat-android

Accelerator Text Chat Android provides functionality you can add to your OpenTok applications that enables users to exchange text messages between mobile or browser-based devices.
Java
2
star
58

opentok-macos-sdk-samples

Objective-C
2
star
59

token-encoder

Generates tokens for `X-TB-TOKEN-AUTH` header when using OpenTok REST API.
JavaScript
2
star
60

opentok-swiftui-basic-video-chat

Swift
1
star
61

opentok-jwt

Node module to generate a JWT token given an apiKey and secret.
JavaScript
1
star
62

opentok-embed-appointment

A simple demo for setting up appointments with the OpenTok Embed
JavaScript
1
star