WebRTC Streaming Library#

Omniverse WebRTC Streaming Library v5.17.0

Use this library to manage Omniverse Kit application streams from GeForce Now (GFN), a local machine, or a container instance with a provided URL.

Usage#

The AppStreamer class is the main entry point into this library. Use it to connect to, pause, unpause, and terminate a streaming Omniverse Kit application session. You can also send and receive custom messages to and from the streaming Kit application. The Kit application can stream from GFN, NVIDIA Cloud Functions (NVCF), Omniverse on DGX Cloud, or an ad hoc development environment.

Configure NPM Scope#

The correct scope must be defined in your .npmrc file before installing.

@nvidia:registry=https://edge.urm.nvidia.com/artifactory/api/npm/omniverse-client-npm/

Installation#

npm install @nvidia/omniverse-webrtc-streaming-library

Importing#

import { AppStreamer } from '@nvidia/omniverse-webrtc-streaming-library'

GFN#

If connecting to an application running on GFN, you must import GFN separately. The recommended method to import GFN into a project is by sourcing the CDN in the project index.html file, as shown below:

<!DOCTYPE html>
<html lang="en">
   <body>
      <script src="https://sdk.nvidia.com/gfn/client-sdk/1.x/gfn-client-sdk.js"></script>
   </body>
</html>

Examples#

Connecting#

The following code examples illustrate how to manage streaming connections directly to a container, as well as infrastructure environments such as GFN and NVCF.

Set Up the Configuration#
Direct Configuration

Configuration for a Kit application running in a directly-accessible container, either local or remote:

// This example server is localhost, but can be a valid remote IP as well.

const streamParams: DirectConfig = {
   streamSource : StreamType.DIRECT,
   logLevel     : LogLevel.WARN,
   streamConfig : {
      server        : '<some ip address>',
      width         : 1920,
      height        : 1028,
      fps           : 60,
      onStart       : (message: StreamEvent) => {console.info('Stream started')},
      onStop        : (message: StreamEvent) => {console.info('Stream stopped')},
      onStreamStats : (message: StreamEvent) => {console.info('Stream stats')}
   }
};
Configure NVCF

Configuration for a Kit application running on NVCF:

// This example server is localhost, but can be a valid remote IP as well.

const streamParams: DirectConfig = {
   streamSource : StreamType.DIRECT,
   logLevel     : LogLevel.WARN,
   streamConfig : {
      server        : '<some ip address>',
      width         : 1920,
      height        : 1028,
      fps           : 60,
      onStart       : (message: StreamEvent) => {console.info('Stream started')},
      onStop        : (message: StreamEvent) => {console.info('Stream stopped')},
      onStreamStats : (message: StreamEvent) => {console.info('Stream stats')}
   }
};
Configure GFN

Configuration for a Kit application running on GFN:

const streamParams: GFNConfig = {
   streamSource : StreamType.GFN,
   logLevel     : LogLevel.WARN,
   streamConfig : {
      // GFN resolves from the script source discussed above.
      GFN             : GFN,
      catalogClientId : <your value>,
      clientId        : <your value>,
      cmsId           : <your value>,
      onStart         : (message: StreamEvent) => {console.info('Stream started')},
      onStop          : (message: StreamEvent) => {console.info('Stream stopped')},
      onStreamStats   : (message: StreamEvent) => {console.info('Stream stats')}
   }
};
Connect and Disconnect#
Connect Using Config Params

The library allows connection to Kit applications streaming from multiple infrastructure options. The options are of type StreamType. This allows you to change which infrastructure to connect to with only minor edits to the configuration. Below are examples of configurations for each streaming type.

Using the streamParams config:

AppStreamer.connect(streamParams)
   .then((result: StreamEvent) => {
      // The connection request was successful. The onStart
      // callback will fire when the stream is ready.
      console.info(result);
   })
   .catch((error: StreamEvent) => {
      // The connection request has failed.
      console.error(error);
   });
Disconnect
AppStreamer.terminate()
   .then((result: StreamEvent) => {
         // Request has been made successfully. The onStop
         // callback will fire when termination is complete.
         console.info(result));
   })
   .catch((error: StreamEvent) => {
         // The terminate request has failed.
         console.error(error));
   });

Callbacks#

All of the callbacks are optional, but there are a few that are very helpful.

onStart()#

Define your onStart callback passed with the streamParams to determine success of the connection request.

onStart(message: StreamEvent) : void {
      if ( message.status === eStatus.success ) {
         // The stream is connected and ready.
         console.info('onStart:', message));
      }
      else if ( message.status === eStatus.warning ) {
         // There may be an issue with the stream connection.
         console.warn('onStart:', message));
      }
      else if ( message.status === eStatus.error ) {
         // The connection has failed.
         console.info('onStart:', message));
      }
   }

onStop()#

Define your onStop callback message to determine unexpected and successful stream disconnections.

onStop(message: StreamEvent) : void {
      if ( message.action === eAction.terminate &&
            message.status === eStatus.error ) {
            // The connected stream has been disconnected unexpectedly.
            console.error('onStop:', message));
      }
      else if ( message.action === eAction.terminate &&
                  message.status === eStatus.success ) {
            // A request to disconnect the stream was successful -
            // the stream has been disconnected.
            console.info('onStop:', message));
      }
   }

onStreamStats()#

The onStreamStats callback, if passed, is called at regular intervals to provide information and performance metrics about the connected stream.

onStreamStats(message: StreamEvent) : void {
   console.info('Stream stats:', message.stats);
}