Skip to content

Conversation

@vikramdattu
Copy link
Contributor

What was changed?

  • With this change, the application can start peer connection with single ICE server
  • This will allow peer connection to run IceAgent instantaneously without waiting for TURN servers
  • Once, the TURN servers available, application can call peerConnectionUpdateIceServers to update it

Why was it changed?

  • In most of the cases, peer connection will take place with local + STUN candidates immediately
  • With this change, we take out the time needed for TURN servers to be available using /v1/get-ice-server-config call

How was it changed?

  • Added a peerConnectionUpdateIceServers function which can help to dynamically add ICE servers when Ice Agent is already started

What testing was done for the changes?

Example code:

     RtcConfiguration configuration;

    // Set the  STUN server
    PCHAR pKinesisVideoStunUrlPostFix = KINESIS_VIDEO_STUN_URL_POSTFIX;
    // If region is in CN, add CN region uri postfix
    if (STRSTR(pSampleConfiguration->channelInfo.pRegion, "cn-")) {
        pKinesisVideoStunUrlPostFix = KINESIS_VIDEO_STUN_URL_POSTFIX_CN;
    }
    SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, pSampleConfiguration->channelInfo.pRegion,
             pKinesisVideoStunUrlPostFix);

// OR
     // Add a STUN server
     // SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, "stun:stun.l.google.com:19302");

    // Create the peer connection
    CHK_STATUS(createPeerConnection(&configuration, ppRtcPeerConnection));

After TURN servers are available, call update server API

            RtcIceServer* newTurnServers = NULL;
            // Allocate and add TURN servers to newTurnServers
            
            
            // Now update the ongoing peer connection with the new servers
            STATUS updateStatus = peerConnectionUpdateIceServers(session->peer_connection,
                                                               newTurnServers,
                                                               newTurnServerCount);

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

 - With this change, the application can start peer connection with single ICE server
 - This will allow peer connection to run IceAgent instantaneously without waiting for TURN servers
 - Once, the TURN servers available, application can call `peerConnectionUpdateIceServers` to update it

In most of the cases, peer connection will take place with local + STUN candidates immediately
@vikramdattu
Copy link
Contributor Author

cc @sirknightj @unicornss

*/
PUBLIC_API STATUS closePeerConnection(PRtcPeerConnection);

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Allows for pre-fetching of the host + stun candidates

Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if you can modify the sample to use the new function? (testing the code path)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sirknightj I'll modify the sample and check for if a test case can be added.

Copy link
Contributor Author

@vikramdattu vikramdattu Sep 11, 2025

Choose a reason for hiding this comment

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

@sirknightj added the commit which defers the ICE server fetch logic for testing purpose. (Test commit is not expected to be added in the upstream but temporary for testing, hence may not be clean.)
It fetches the ICE server after peerConnection is kicked off and adds the new servers later once the SDP answer is sent.
Tested with STUN/TURN and TURN only settings from the Test WebPage.

Please note that this test approach is not essentially better. It could only increase the connection time as the ICE server fetch is still blocking.
Only when this fetch is done asynchronuously and local+STUN cases (~80%?), this has the real benefit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, there is no way to check if refresh needed and trigger ICE refresh in async way. Adding few functions for this exact purpose, and add TURN servers once that's refreshed would make sense here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants