Usage Examples

Connect to a Nucleus Server with Dialog

import asyncio
from omni.kit.widget.nucleus_connector import get_nucleus_connector

# Initialize the NucleusConnectorExtension
connector = get_nucleus_connector()

# Define the success and failure callback functions
def on_connect_success(name, url):
    print(f"Successfully connected to {name} at {url}")

def on_connect_failure(name, url):
    print(f"Failed to connect to {name} at {url}")

# Use the connector extension to prompt for server details and connect
connector.connect_with_dialog(on_success_fn=on_connect_success, on_failed_fn=on_connect_failure)

Connect to a Nucleus Server Directly

import asyncio
from omni.kit.widget.nucleus_connector import get_nucleus_connector

# Initialize the NucleusConnectorExtension
connector = get_nucleus_connector()

# Define the success and failure callback functions
def on_connect_success(name, url):
    print(f"Successfully connected to {name} at {url}")

def on_connect_failure(name, url):
    print(f"Failed to connect to {name} at {url}")

# Use the connector extension to connect directly to a server with the given name and URL
connector.connect("My Server", "omniverse://my-server-url", on_success_fn=on_connect_success, on_failed_fn=on_connect_failure)

Reconnect to a Nucleus Server

import asyncio
from omni.kit.widget.nucleus_connector import get_nucleus_connector

# Initialize the NucleusConnectorExtension
connector = get_nucleus_connector()

# Define the success and failure callback functions
def on_reconnect_success(url):
    print(f"Successfully reconnected to {url}")

def on_reconnect_failure(url):
    print(f"Failed to reconnect to {url}")

# Use the connector extension to reconnect to a server with the given URL
connector.reconnect("omniverse://my-server-url", on_success_fn=on_reconnect_success, on_failed_fn=on_reconnect_failure)

Disconnect from a Nucleus Server

from omni.kit.widget.nucleus_connector import get_nucleus_connector

# Initialize the NucleusConnectorExtension
connector = get_nucleus_connector()

# Use the connector extension to disconnect from a server with the given URL
connector.disconnect("omniverse://my-server-url")

# The server is disconnected immediately, no need for an event loop here

Use Device Authentication Flow

import asyncio
from omni.kit.widget.nucleus_connector import get_nucleus_connector
# Initialize the NucleusConnectorExtension with device authentication enabled
carb.settings.get_settings().set("/exts/omni.kit.widget.nucleus_connector/device_auth_flow", True)
connector = get_nucleus_connector()

# Define the success and failure callback functions
def on_connect_success(name, url):
    print(f"Successfully connected to {name} at {url}")

def on_connect_failure(name, url):
    print(f"Failed to connect to {name} at {url}")

# Use the connector extension to connect to a server using the device authentication flow
connector.connect("My Server", "omniverse://my-server-url", on_success_fn=on_connect_success, on_failed_fn=on_connect_failure)

Please note that for the examples to work, you would need to have a running instance of the Omniverse environment with the omni.kit.widget.nucleus_connector extension installed and enabled. The examples here are designed for illustrative purposes and may require adaptation to work in specific Omniverse applications or environments.