Skip to main content
Version: Dev (main)

Session class

An active session, the entry point to peers, GUI panels, app volumes and senders. Only Runtime.Onboard (and the deprecated Runtime.Rejoin) produce one, and there is no getter for a "current" session: keep the instance.

Namespace: Quaternar.Qaros · Assembly: Quaternar.Qaros.dll

public sealed class Session : IDisposable

Implements: IDisposable

Remarks​

The caller owns the session. Session.Dispose tears the session down; the next start onboards again. Disposing ends every subscription of the session and waits for a handler running on another thread, and for the session calls other threads are making (see Session.Dispose): never dispose it from a QAROS callback or event handler, nor while holding a lock a handler or such a call takes.

Properties​

MemberDescription
Peers
GuiPanels
PanelContentWeb pages this session serves to served GUI panels, and their messages.
AppVolumes
RenderSenders
PrimarylessVideoSenders

Peers​

public PeerControl Peers { get; }

Value: PeerControl

GuiPanels​

public GuiPanelControl GuiPanels { get; }

Value: GuiPanelControl

PanelContent​

Web pages this session serves to served GUI panels, and their messages.

public PanelContentControl PanelContent { get; }

Value: PanelContentControl

AppVolumes​

public AppVolumeControl AppVolumes { get; }

Value: AppVolumeControl

RenderSenders​

public RenderSenderControl RenderSenders { get; }

Value: RenderSenderControl

PrimarylessVideoSenders​

public PrimarylessVideoSenderControl PrimarylessVideoSenders { get; }

Value: PrimarylessVideoSenderControl

Methods​

MemberDescription
GetId()
GetGraphicsDeviceId()The GPU adapter the session's graphics devices were created on, or null when it is not known. It is the one OnboardOptions.WithGraphicsDevice named, else the one QAROS selected for an app it launched, else the one the library picked. Create your own graphics device on it so the frames you render need no cross-GPU copy.
GetLifecycleState()The session's current lifecycle state: SessionLifecycleState.Connected in the session Session.GetId names, unless it is moving, cannot reach its hub, or has been refused for good. Its SessionLifecycleChangedEventArgs.Reason is empty.
OpenQarosView(QarosView, QarosDeviceKind)Opens a predefined view of the QAROS Visualizer in this session's QAROS: the Pair Headset QR code, the Room Origin marker or the setup of one device type. The app needs neither a qaros:// link nor a registered qaros:// handler, and never looks for QAROS itself.
SubscribeLifecycle()Starts delivering lifecycle states to Session.LifecycleChanged until the returned subscription is disposed.
SubscribeLifecycle(EventHandler<SessionLifecycleChangedEventArgs>)Calls handler with the session's lifecycle state, the current one first, then every change, until the returned subscription is disposed: how an app learns that its hub started a new session, joined another hub, or no longer admits it.
RequestOnboardingInvite(string, IProgress<ActionProgress>?, CancellationToken)Asks the hub for a co-process invite: one companion process on this PC (a C# helper of a native app, a plugin sandbox) joins with it, without a code, as the peer the hub remembers for this app's approval and appTag. Blocks until the hub answers.
RequestOnboardingInvite(RequestOnboardingInviteOptions, IProgress<ActionProgress>?, CancellationToken)Session.RequestOnboardingInvite with the full request options.
RequestOnboardingInviteAsync(string, IProgress<ActionProgress>?, CancellationToken)Async Session.RequestOnboardingInvite. Canceling cancellationToken cancels the task.
RequestOnboardingInviteAsync(RequestOnboardingInviteOptions, IProgress<ActionProgress>?, CancellationToken)Async Session.RequestOnboardingInvite. Canceling cancellationToken cancels the task.
FindRenderTarget(string)Finds an already-connected render target from its connection string.
InviteTargetApp(string, IProgress<ActionProgress>?, CancellationToken)Asks this machine's hub to start the target app for one AR device and returns the target app's peer id once its peer joined the session - the id a render sender renders for. Build connectionString with TargetAppConnectionString.HoloLens; a malformed one fails with StatusCode.ArgumentNotSupported. An Android headset (a TargetAppConnectionString.Quest or TargetAppConnectionString.Android string) is never invited and fails with StatusCode.HubTargetAppDeviceNotInvitable: it is paired by the operator, joins the session by itself, and Session.FindRenderTarget finds it.
InviteTargetAppAsync(string, IProgress<ActionProgress>?, CancellationToken)Async Session.InviteTargetApp.
KillTargetApp(PeerId, IProgress<ActionProgress>?, CancellationToken)Asks this machine's hub to stop a target app, whatever kind it is.
KillTargetAppAsync(PeerId, IProgress<ActionProgress>?, CancellationToken)Async Session.KillTargetApp.
Dispose()Tears the session down (a persisted slot of the deprecated slot paths stays for a later Runtime.Rejoin). Waits for the calls and subscription handlers running on other threads; do not call it from a callback of the session.

GetId​

public Result<SessionId> GetId()

Returns: Result<SessionId>

GetGraphicsDeviceId​

The GPU adapter the session's graphics devices were created on, or null when it is not known. It is the one OnboardOptions.WithGraphicsDevice named, else the one QAROS selected for an app it launched, else the one the library picked. Create your own graphics device on it so the frames you render need no cross-GPU copy.

public Result<GraphicsDeviceId?> GetGraphicsDeviceId()

Returns: Result<GraphicsDeviceId>

GetLifecycleState​

The session's current lifecycle state: SessionLifecycleState.Connected in the session Session.GetId names, unless it is moving, cannot reach its hub, or has been refused for good. Its SessionLifecycleChangedEventArgs.Reason is empty.

public Result<SessionLifecycleChangedEventArgs> GetLifecycleState()

Returns: Result<SessionLifecycleChangedEventArgs>

OpenQarosView​

Opens a predefined view of the QAROS Visualizer in this session's QAROS: the Pair Headset QR code, the Room Origin marker or the setup of one device type. The app needs neither a qaros:// link nor a registered qaros:// handler, and never looks for QAROS itself.

public Result<Unit> OpenQarosView(QarosView view, QarosDeviceKind deviceKind = QarosDeviceKind.None)

Parameters

NameTypeDescription
viewQarosViewThe view to open.
deviceKindQarosDeviceKindThe device type for QarosView.DeviceSetup; QarosDeviceKind.None for every other view.

Returns: Result<Unit>

Remarks

An installed QAROS opens the view through its own qaros.exe. In a developer setup (a QAROS run from a build folder, the app started with its QAR_INSTANCE) the qaros.exe of the instance's runtime folder does, else the one beside the loaded runtime; the registered qaros:// handler, which may belong to another build, is never used. That qaros.exe hands the view to its running QAROS, or starts it.

Only a session onboarded as a local app can open a view. Returns once the view was handed over, not when it shows. Windows only.

Failures: StatusCode.ArgumentNotSupported for an unknown view or kind, a deviceKind missing for QarosView.DeviceSetup or given for another view, or a session not onboarded as a local app; StatusCode.OnboardingHubUnreachable when this session's QAROS has no qaros.exe where it should be or it could not be started; StatusCode.NotImplemented off Windows or with a runtime older than this call.

SubscribeLifecycle()​

Starts delivering lifecycle states to Session.LifecycleChanged until the returned subscription is disposed.

public Result<IDisposable> SubscribeLifecycle()

Returns: Result<IDisposable>

SubscribeLifecycle(EventHandler<SessionLifecycleChangedEventArgs>)​

Calls handler with the session's lifecycle state, the current one first, then every change, until the returned subscription is disposed: how an app learns that its hub started a new session, joined another hub, or no longer admits it.

public Result<IDisposable> SubscribeLifecycle(EventHandler<SessionLifecycleChangedEventArgs> handler)

Parameters

NameTypeDescription
handlerEventHandler<SessionLifecycleChangedEventArgs>

Returns: Result<IDisposable>

Remarks

The session follows its hub by itself, in place: when the hub starts a new session or joins another hub as its member, this Session, every object obtained from it, the app volumes, GUI panels and rooms the app created or took over with GetOrCreate, its subscriptions and its peer id stay; senders created with reconnects renegotiate (frames stop for a few seconds), and objects of other peers come back once their owners have moved too. A move reports SessionLifecycleState.Migrating, then SessionLifecycleState.Connected with the new SessionLifecycleChangedEventArgs.SessionId, the previous one and the SessionLifecycleChangedEventArgs.Cause. A move whose new session answers late reports SessionLifecycleState.HubUnreachable first, so react to a change of the session id rather than to one state: re-read whatever the app keyed by it.

SessionLifecycleState.RePairRequired is terminal: nothing is retried. Dispose the session (not from the handler), onboard again and recreate what the app owns.

Recommended: on a new session id, and after onboarding again, call AppVolumeControl.GetOrCreate and GuiPanelControl.GetOrCreate again for every common name the app owns. Each call returns the same id, takes the object over when it is there and re-creates it when it is missing; after a re-pair it is the only way back.

The handler runs on a library thread: keep it short and do the reinitialization on a thread of your own. An exception it throws is swallowed. When Dispose of the subscription returns, a handler call running on another thread has finished and no further one starts; never dispose while holding a lock the handler takes.

RequestOnboardingInvite(string, IProgress<ActionProgress>?, CancellationToken)​

Asks the hub for a co-process invite: one companion process on this PC (a C# helper of a native app, a plugin sandbox) joins with it, without a code, as the peer the hub remembers for this app's approval and appTag. Blocks until the hub answers.

public Result<OnboardingInvite> RequestOnboardingInvite(string appTag, IProgress<ActionProgress>? progress = null, CancellationToken cancellationToken = default)

Parameters

NameTypeDescription
appTagstringThe co-process's app tag; rules in RequestOnboardingInviteOptions.AppTag.
progressIProgress<ActionProgress>Optional progress reports.
cancellationTokenCancellationTokenCancels the request; the call then returns a failure.

Returns: Result<OnboardingInvite>

Exceptions

ExceptionCondition
ArgumentNullExceptionappTag is null.
ArgumentExceptionappTag is not a valid app tag.

Remarks

Only a session that joined by OnboardOptions.UseLocalApp, or a process the QAROS launcher started, may ask; the hub refuses any other. The invite works for every start of the co-process while this session lives and only for this user on this PC (a named pipe on Windows, a Unix socket on Linux): onboarding with it asks this app for a fresh one-time hub invite on each attempt and keeps trying while this app or the hub is away (bound it with a cancellation token). The co-process gets the short local certificate under this app's approval; its certificate renews only while this app's peer is still in the session, and revoking the approval revokes both.

The caller owns and disposes the invite. Hand it to the co-process over a private channel (for example its stdin, never a command line) with OnboardingInvite.Serialize; the co-process creates its runtime with RuntimeOptions.EphemeralStorage, so it writes nothing to disk, and onboards with OnboardingInvite.Deserialize and OnboardOptions.UseInvite. Request it once per app session and hand the same bytes to every start of the co-process.

There is no invite for another PC or for a new device: pairing codes and unbound invites are minted by the hub's operators. Fails with StatusCode.ArgumentNotSupported for a tag the runtime refuses, or when the hub cannot be resolved from this session, for example while it is not connected. A runtime without app tags refuses the request; check RuntimeInfo.Version when you may load one.

RequestOnboardingInvite(RequestOnboardingInviteOptions, IProgress<ActionProgress>?, CancellationToken)​

Session.RequestOnboardingInvite with the full request options.

public Result<OnboardingInvite> RequestOnboardingInvite(RequestOnboardingInviteOptions options, IProgress<ActionProgress>? progress = null, CancellationToken cancellationToken = default)

Parameters

NameTypeDescription
optionsRequestOnboardingInviteOptions
progressIProgress<ActionProgress>
cancellationTokenCancellationToken

Returns: Result<OnboardingInvite>

Exceptions

ExceptionCondition
ArgumentNullExceptionoptions is null.

RequestOnboardingInviteAsync(string, IProgress<ActionProgress>?, CancellationToken)​

Async Session.RequestOnboardingInvite. Canceling cancellationToken cancels the task.

public Task<Result<OnboardingInvite>> RequestOnboardingInviteAsync(string appTag, IProgress<ActionProgress>? progress = null, CancellationToken cancellationToken = default)

Parameters

NameTypeDescription
appTagstring
progressIProgress<ActionProgress>
cancellationTokenCancellationToken

Returns: Task<Result<OnboardingInvite>>

Exceptions

ExceptionCondition
ArgumentNullExceptionappTag is null.
ArgumentExceptionappTag is not a valid app tag.

RequestOnboardingInviteAsync(RequestOnboardingInviteOptions, IProgress<ActionProgress>?, CancellationToken)​

Async Session.RequestOnboardingInvite. Canceling cancellationToken cancels the task.

public Task<Result<OnboardingInvite>> RequestOnboardingInviteAsync(RequestOnboardingInviteOptions options, IProgress<ActionProgress>? progress = null, CancellationToken cancellationToken = default)

Parameters

NameTypeDescription
optionsRequestOnboardingInviteOptions
progressIProgress<ActionProgress>
cancellationTokenCancellationToken

Returns: Task<Result<OnboardingInvite>>

Exceptions

ExceptionCondition
ArgumentNullExceptionoptions is null.

FindRenderTarget​

Finds an already-connected render target from its connection string.

public Result<PeerId> FindRenderTarget(string connection)

Parameters

NameTypeDescription
connectionstring

Returns: Result<PeerId>

Remarks

Takes the strings TargetAppConnectionString builds. It only looks at the peers this session knows now: it neither invites nor waits, and fails with StatusCode.ArgumentNotSupported when no peer matches. To start a target app, use Session.InviteTargetApp.

InviteTargetApp​

Asks this machine's hub to start the target app for one AR device and returns the target app's peer id once its peer joined the session - the id a render sender renders for. Build connectionString with TargetAppConnectionString.HoloLens; a malformed one fails with StatusCode.ArgumentNotSupported. An Android headset (a TargetAppConnectionString.Quest or TargetAppConnectionString.Android string) is never invited and fails with StatusCode.HubTargetAppDeviceNotInvitable: it is paired by the operator, joins the session by itself, and Session.FindRenderTarget finds it.

public Result<PeerId> InviteTargetApp(string connectionString, IProgress<ActionProgress>? progress = null, CancellationToken cancellationToken = default)

Parameters

NameTypeDescription
connectionStringstring
progressIProgress<ActionProgress>
cancellationTokenCancellationToken

Returns: Result<PeerId>

InviteTargetAppAsync​

Async Session.InviteTargetApp.

public Task<Result<PeerId>> InviteTargetAppAsync(string connectionString, IProgress<ActionProgress>? progress = null, CancellationToken cancellationToken = default)

Parameters

NameTypeDescription
connectionStringstring
progressIProgress<ActionProgress>
cancellationTokenCancellationToken

Returns: Task<Result<PeerId>>

KillTargetApp​

Asks this machine's hub to stop a target app, whatever kind it is.

  • A target app the hub started (an invited HoloLens, remoted through the HoloLens OpenXR desktop app on the PC): the desktop app and the whole pipeline feeding it are stopped.
  • A headset that joined the session itself (Meta Quest, other Android headsets): the player application on the headset is asked to quit, and the Android streamer the hub runs on this PC to relay video to it is stopped. A headset player of an older release cannot be asked to quit: its relay still stops, and the player keeps running without a stream.
  • A receiver of the QAROS Visualizer on this machine: the Visualizer stops the receiver so nothing streams into it. The receiver stays in the Visualizer and starts again from there.

A stop is not remembered: nothing is revoked, forgotten or hidden, and a target app that comes back (the receiver started again, the headset app relaunched, the HoloLens app restarted) is listed again. To forget or unpair a device use the Visualizer's Forget, or pair the device again with a new QR code. The call returns once the target app has stopped. A target app that is none of the above (another hub's, one started outside QAROS that is neither a headset player nor a Visualizer receiver, or one already gone) fails with StatusCode.HubTargetAppNotHosted and nothing is stopped. A Visualizer that refuses to stop its receiver fails with StatusCode.ArgumentNotSupported, and one that does not answer in time with StatusCode.Timeout; nothing changes then.

public Result<Unit> KillTargetApp(PeerId targetApp, IProgress<ActionProgress>? progress = null, CancellationToken cancellationToken = default)

Parameters

NameTypeDescription
targetAppPeerId
progressIProgress<ActionProgress>
cancellationTokenCancellationToken

Returns: Result<Unit>

KillTargetAppAsync​

Async Session.KillTargetApp.

public Task<Result<Unit>> KillTargetAppAsync(PeerId targetApp, IProgress<ActionProgress>? progress = null, CancellationToken cancellationToken = default)

Parameters

NameTypeDescription
targetAppPeerId
progressIProgress<ActionProgress>
cancellationTokenCancellationToken

Returns: Task<Result<Unit>>

Dispose​

Tears the session down (a persisted slot of the deprecated slot paths stays for a later Runtime.Rejoin). Waits for the calls and subscription handlers running on other threads; do not call it from a callback of the session.

public void Dispose()

Exceptions

ExceptionCondition
InvalidOperationExceptionCalled from a QAROS callback where it would have to wait (see remarks).

Remarks

Safe while another thread is inside a call on the session or one of its controls: the session refuses new calls at once (ObjectDisposedException), cancels the calls that wait (render-sender creation, target-app invite and kill, invite request, sync and async alike; they fail), waits until every running call returned and every async call's completion fired, and then tears the session down on the calling thread. When Dispose returns the session is gone and its subscriptions have ended: no handler runs and none starts, so a Runtime.Dispose or Library.Destroy may follow at once.

The wait is not bounded: a call that does not wait on the hub returns on its own, and the waiting ones are cancelled first. Never dispose while holding a lock a call or a handler on another thread needs. Called from inside one of the session's own callbacks (a subscription handler, a progress report of a session call) it would wait for itself, so it throws InvalidOperationException and changes nothing (uncaught in a handler, the exception is swallowed like any other); dispose from a thread of your own. From another QAROS callback it throws too while another thread is in a session call.

Events​

LifecycleChanged​

Raised for every lifecycle state, but only while a subscription from Session.SubscribeLifecycle is alive: attaching a handler alone delivers nothing.

public event EventHandler<SessionLifecycleChangedEventArgs>? LifecycleChanged

Event type: EventHandler<SessionLifecycleChangedEventArgs>

Remarks

Raised on a library thread, like every subscription handler.