WebSDK 2.0 Logging and Error Handling
This document provides an overview of logging, channel states, and error handling in WebSDK 2.0.
Logging
Logging levels and telemetry are controlled via programmatic API. If you don't use TypeScript, WebStorm can provide code completion based on the TypeScript mapping that comes with the WebSDK 2.0.
The SDK provides log messages from the set log level along with messages from the more severe levels. For example, if you have the "Warn" level set, logs will include Warn, Error, and Fatal messages.
Prior to using the phenix.Channels
APIs, use
phenix.SDK.init(initOptions)
. These include options for logging level
for both general logging and for console logging, and for telemetry.
Log level options, from lowest to highest severity, are:
-
Trace
-
Debug
-
Info
-
Warn
-
Error
-
Fatal
Other levels are "Off" to mute all log messages, and "All" to receive all log messages. Typically, there should be no issues that cause any issues above "Info"; that is, a typical run only has Info and less-severe log messages.
-
loggingLevel
: one of 'Off' | 'Trace' | 'Debug' | 'Info' | 'Warn' | 'Error' | 'Fatal' | 'All' -
consoleLoggingLevel
: one of 'Off' | 'Trace' | 'Debug' | 'Info' | 'Warn' | 'Error' | 'Fatal' | 'All' -
telemetryLevel
: one of 'Off' | 'Essential' | 'All'
An example is shown below.
phenix.SDK.init({telemetryLevel: 'All', consoleLoggingLevel: 'Off'});
Error Management
Error handling is different when using WebSDK2.0 as some of the errors
result from the token rather than from API calls such as joinChannel
.
Detect if Unauthorized
If a token is set to null or is unauthorized, joining a channel or room will fail. In this case, implementers should obtain a new token.
// Detect if the client failed to authorize
// This could happen if the token is not valid OR if the token expired
channel.authorized.subscribe(authorized => {
if (!authorized) reauthorize();
});
function reauthorize() {
let token = await acquireNewToken();
channel.token = token;
}
Detect if No Video in Channel
// Detect if the channel has no video
channel.standby.subscribe(standby => {
// If standby, no stream playing in channel, update UI accordingly
});
Detect if Unable to Connect
// Detect if the client is unable to connect
// This could happen if the DNS or network is changing or impaired
channel.online.subscribe((online) => {
if (!online) tryAgainOrFallbackToHls();
});
Handling Automatic Muting
// Browser may refuse video playback without video being muted
channel.autoMuted.subscribe(autoMuted => {
If (autoMuted) makeSureUnmuteButtonIsVisibleOnScreen();
});
unmuteButton.click = () => channel.unmute();
Handling Automatic Pausing
// Browser may completely refuse video playback, e.g. low battery
channel.autoPaused.subscribe((autoPaused) => {
if (autoPaused) makeSurePlayButtonIsVisibleOnScreen();
});
// Note on ios you need to use videoElement.onplay / no custom play button
playButton.click = () => channel.resume();