WebRTC Auto Reconnect - ngmediaserver/NG-Media-Server GitHub Wiki
Warning: BETA FEATURE
the WebRTC API (ngmedia_rtc.js) enables to make and receive calls with NG Media SBC. With poor network conditions, the link with the NG Media SBC may disconnect.
Starting with ngmedia_rtc.js version 7.4 (BETA), the WebRTC API implements a comprehensive set of failover mechanisms to restore the link as fast as possible. This version of ngmedia_rtc.js is backward compatible with NG Media SBC 7.1.
Automatic Media reconnection (NEW)
the WebRTC API now attempts to automatically reconnect the media streams (ice restart).
Automatic WebSocket reconnection (NEW)
the WebRTC API now attempts to automatically reconnect to NG Media SBC when the signaling WebSocket gets disconnected. New callback functions must be set to enable the API to request for an updated authorization token.
To compute updated authorization token when a link is up again, set the onauthorization attribute (or onauthorizationasync for an async version) of the link attribute to a function taking a string representing the data for which an authorization must be generated:
function doRegister(authorization) {
...
let registration = ngmediaRTC.registerCall(
{
domain: "*",
to: "2001",
from: "2001",
authorization: authorizatio,
link: { onauthorizationasync: onLinkAuthorizationAsync },
},
function(incomingCall) {
registerCall_onNewCall(incomingCall);
}
);
}
async function onLinkAuthorizationAsync(data) {
const authorization = await GetClientAuthorization(data);
return authorization;
}
See WebRTC API Authorization for additional information.
Automatic RTC Reconnect (NEW)
the WebRTC API now attempts to automatically reconnect a call if the underlying WebSocket connection was lost. This requires to enable the RTC Reconnect feature. The WebRTC API will cache the ReconnectId sent by the server upon call connection. If the WebSocket link later disconnects, the WebRTC API still reports the call as connected, but behind the scene it will transparently attempt to reconnect the WebSocket and to initiate a RTC Reconnect. All this process is transparent for the WebRTC client application.
RTC Reconnect notifications are disabled by default.
To enable RTC Reconnect notifications, in general.json, set RTCReconnect to true:
{
...
"RTCReconnect": true,
...
},
Automatic RTC Reconnect is enabled by default.
To disable Automatic RTC Reconnect, in general.json, set RTCReconnect to true:
exported.config = {
link : {
...
reconnectCall : false,
...
},
...
},
WebSocket connection reuse (NEW)
when registering for incoming calls, it is now possible to keep the registration active (and the underlying WebSocket connected) once an incoming call was processed. It is no more necessary to register again.
WebSocket connection reuse is enabled by default.
To disable WebSocket connection reuse, set the persistent attribute of the link attribute to false:
let registration = ngmediaRTC.registerCall(
{
domain: "*",
to: "2001",
from: "2001",
authorization: myComputedAuthorization,
link: { persistent: false },
},
function(incomingCall) {
registerCall_onNewCall(incomingCall);
}
);
Upcoming
the upcoming release version should enable to:
- use User credentials based on existing NG Media SBC 7 user management. The computation of the authorization parameter will no more be needed. This feature will be available with NG Media SBC 7.4 and higher.
- makeCall over an existing registerCall. This will enable to make and receive calls over a single reusable WebSocket. This will also enable faster failover, as if several servers are configured, the call will be attempted on the first link up.
- report the state of each server link, in order to provide both a global and a detailed status of the links state.