Usage Examples#
Join Live Session with Session Link#
import omni.ui as ui
from omni.kit.widget.live_session_management_ui import JoinWithSessionLinkWindow
def on_join_session(session_link: str):
"""Callback function called when user confirms joining a session"""
print(f"Joining session with link: {session_link}")
# Add your session joining logic here
# Create and show the join session window
window = JoinWithSessionLinkWindow(on_ok_button_cb=on_join_session)
window.visible = True
# Set a session link programmatically
window.current_session_link = "omniverse://localhost/test/stage.usd?live_session_name=my_session"
# Focus the input field for user convenience
import asyncio
asyncio.ensure_future(window.focus_field())
Screenshot:#
Create Live Session Model and Start Window#
import omni.ui as ui
from omni.kit.widget.live_session_management_ui import LiveSessionStartWindow, LiveSessionComboBoxModel, LiveSessionInterface
# Mock implementation of LiveSessionInterface for demonstration
class MockLiveSession:
def __init__(self, name: str, url: str, owner: str):
self._name = name
self._url = url
self._owner = owner
@property
def name(self) -> str:
return self._name
@property
def url(self) -> str:
return self._url
@property
def owner(self) -> str:
return self._owner
@property
def channel_url(self) -> str:
return f"{self._url}/channel"
@property
def base_layer_identifier(self) -> str:
return "base_layer"
def get_last_modified_time(self) -> int:
return 1234567890
@property
def shared_link(self) -> str:
return f"omniverse://localhost/test/stage.usd?live_session_name={self._name}"
def get_current_session(layer_id: str) -> MockLiveSession:
return MockLiveSession("current_session", "omniverse://localhost/current", "user1")
def get_all_sessions(layer_id: str) -> list:
return [
MockLiveSession("session1", "omniverse://localhost/session1", "user1"),
MockLiveSession("session2", "omniverse://localhost/session2", "user2")
]
def join_session_callback(session, layer_id: str, prim_path: str) -> bool:
print(f"Joining session: {session.name} at {prim_path}")
return True
def create_session_callback(layer_id: str, session_name: str) -> MockLiveSession:
print(f"Creating new session: {session_name}")
return MockLiveSession(session_name, f"omniverse://localhost/{session_name}", "current_user")
# Create the session model
session_model = LiveSessionComboBoxModel(
layer_identifier="base_layer",
get_current_live_session_cb=get_current_session,
get_all_live_sessions_cb=get_all_sessions
)
# Create and show the start session window
start_window = LiveSessionStartWindow(
session_model=session_model,
prim_path="/World",
join_session_cb=join_session_callback,
create_live_session_cb=create_session_callback
)
start_window.visible = True
Screenshot:#
End Live Session with Merge Options#
import omni.ui as ui
from omni.kit.widget.live_session_management_ui import LiveSessionEndWindow
# Mock session object for demonstration
class MockSession:
def __init__(self, name: str):
self.name = name
@property
def shared_link(self) -> str:
return f"omniverse://localhost/test/stage.usd?live_session_name={self.name}"
def on_session_end():
"""Callback function called when user confirms ending the session"""
print("Session ended and changes merged")
# Create mock session
current_session = MockSession("my_session")
# Create and show the end session window
end_window = LiveSessionEndWindow(
current_session=current_session,
on_ok_button_cb=on_session_end,
warn_root_prims=True
)
end_window.visible = True
# Use as async context manager
import asyncio
async def handle_session_end():
async with end_window:
# Window will show and wait for user interaction
pass
print("Session end window closed")
asyncio.ensure_future(handle_session_end())
Screenshot:#