What is Single Peer Connection (SPC) and How do I enable it? What is Single Peer Connection (SPC) and How do I enable it?

What is Single Peer Connection (SPC) and How do I enable it?

Vonage API Support

Objective

To provide an overview of Single Peer Connection (SPC), its benefits, and instructions on how to enable it in various client SDKs for Video API sessions.

Applies To

  • Video API
  • Single Peer Connection 

Procedure

Starting from version 2.28.0 of the client SDKs for iOS, Android, Windows, macOS, and Linux, routed sessions now support Single Peer Connection (SPC). SPC is not yet available in the JS Web SDK, but it is targeted to be included in version 2.29.0.

When SPC is enabled (disabled by default), all subscriber streams for a client are delivered through a single connection to the OpenTok Media Router. 

SPC offers several benefits, including reduced resource consumption on the client, enhanced rate control, and, for mobile native devices, the ability to support larger sessions.

Publishers (Sending Side): Each publisher (the sources of media streams) establishes 
its own PeerConnection to the OpenTok Media Router.

Subscriber (Receiving Side): The subscriber has a Single PeerConnection that receives
and handles the aggregated audio and video streams coming from the OpenTok Media Router.

You can enable SPC in the session using the following client SDK APIs in both Opentok and Unified environments. 

How-to-recognize-if-I-m-using-Vonage-Video-API-Unified-Environment-or-Vonage-Video-API-OpenTok-environment

Important: Please note that your App ID is your API key when using the unified environment.

Android SDK

Enable the SinglePeerConnection by calling the setSinglePeerConnection() method of the Session.Builder object you use to instantiate a Session object:

Vonage Video API Opentok Environment

Vonage Video API Unified Environment 

session = new Session.Builder(this, apiKey, sessionId)
.setSinglePeerConnection(true)
.build();

iOS SDK

Enable the SinglePeerConnection by setting the SinglePeerConnection property of the OTSessionSettings object you pass into the [OTSession initWithApiKey:sessionId:delegate:settings:] method:

Vonage Video API Opentok Environment

Vonage Video API Unified Environment 

Objective-C

OTSessionSettings *settings = [[OTSessionSettings alloc] init];
settings.singlePeerConnection = true;
session = [[OTSession alloc] initWithApiKey:kApiKey
sessionId:kSessionId
delegate:self
settings:settings];
Swift
lazy var session: OTSession = {
let sessionSettings = OTSessionSettings()
sessionSettings.singlePeerConnection = true
}
return OTSession(apiKey: kApiKey, sessionId: kSessionId, delegate: self, settings: sessionSettings)!
}()

Windows SDK

Enable the SinglePeerConnection by setting the SinglePeerConnection parameter of the Session() constructor:

Vonage Video API Opentok Environment 

Vonage Video API Unified Environment 

Session = new Session.Builder(Context.Instance, API_KEY, SESSION_ID)
{
SinglePeerConnection = true
}.Build();

Linux SDK

Enable the SinglePeerConnection by calling the otc_session_settings_set_single_peer_connection() function. 

The first parameter is the otc_session_settings instance you will pass into the otc_session_new_with_settings() function to initialize an otc_session instance. The second parameter is the SinglePeerConnection value.

Vonage Video API Opentok Environment 

Vonage Video API Unified Environment

otc_session_settings *session_settings = otc_session_settings_new();
otc_session_settings_set_single_peer_connection(session_settings,OTC_TRUE);
otc_session *session = otc_session_new_with_settings(API_KEY,
SESSION_ID,
&session_callbacks,
session_settings);

macOS SDK

Enable the SinglePeerConnection by calling the otc_session_settings_set_single_peer_connection() function.

The first parameter is the otc_session_settings instance you will pass into the otc_session_new_with_settings() function to initialize an otc_session instance. The second parameter is the SinglePeerConnection value.

Vonage Video API Opentok Environment

Vonage Video API Unified Environment

otc_session_settings *session_settings = otc_session_settings_new();
otc_session_settings_set_single_peer_connection(session_settings,OTC_TRUE);
otc_session *session = otc_session_new_with_settings(API_KEY,
SESSION_ID,
&session_callbacks,
session_settings);

Additional Information

For more information on the Single Peer Connection feature, please refer to our developer docs and Blog post:

Vonage Video API Opentok Environment

Vonage Video API Unified Environment

https://developer.vonage.com/en/blog/announcing-vonage-video-api-client-sdk-version-2-28