Skip to main content
Version: Dev (main)

Working with Peers

Language:

Every participant in the session — devices and applications alike — is a peer. The peer API lets your application answer "who is here?", present itself well, and react to arrivals and departures. (Concept: The QAROS World.)

info

The C# snippets on this page are illustrative — they track the Quaternar.Qaros binding surface but are not yet compiled from a published sample project.

Presenting your application​

Your own peer's metadata is set at onboarding time via QarPeerPresentation (display name, app version, custom info string) and can be updated live:

qar_peer_update_display_name(session, "My CAD Tool — Assembly B");

The app_custom_peer_info field is yours: put a JSON blob or tag there to coordinate between instances of your own application across the session.

Enumerating peers​

In C this is a count-then-fetch, like every enumeration in the API. The bindings run it for you: C# returns a ready-made array, Rust a Vec of owned snapshots.

size_t count = 0;
qar_result_log_if_error(qar_query_peer_specs_count(session, &count));

QarPeerSpec** specs = malloc(count * sizeof(*specs));
qar_result_log_if_error(
qar_query_peer_specs(session, specs, count, &count));

for (size_t i = 0; i < count; ++i)
{
char name[128];
qar_peer_spec_get_display_name(specs[i], name, sizeof(name));
/* also: _get_app_version, _get_app_custom_peer_info,
_get_presence, _get_version_id, _get_room_tag,
_get_id, _get_role, _get_category, _get_device_id,
_get_device_family, _get_device_name */
qar_peer_spec_handle_destroy(specs[i]);
}
free(specs);

Useful fields:

  • presence: qar_peer_spec_get_presence() (in C#, PeerSpec.Presence; in Rust, raw only, as the Rust tab above shows): whether the peer is here. Render for, wait for and count QAR_PEER_PRESENCE_ONLINE and QAR_PEER_PRESENCE_UNKNOWN peers; stop at OFFLINE, LEAVING or RETIRED.

    PresenceMeans
    ONLINEthe hub sees the peer in the session
    OFFLINEthe hub no longer sees it: a crash, a kill, a network loss or a short drop. It reads ONLINE again once it is back
    LEAVINGit announced a clean exit, and may come back under the same id
    RETIREDit left for good; query results no longer list it
    UNKNOWNthe hub has not reconciled it yet (an older hub that never reports presence, or one that just started); nothing says it is gone, so treat it like ONLINE
  • app state (deprecated): qar_peer_spec_get_app_state() / PeerSpec.AppState still work and are computed from the presence, but every peer reads QAR_APP_STATE_RUNNING from the moment it joins, so the value never tells "loading" from "ready". Read the presence instead.

  • room tag: which physical room the peer is in; lets multi-room deployments group peers.

  • qar_session_get_my_spec: your own peer's spec (e.g. to learn your assigned peer ID).

What a peer is: role, category and device​

Every peer describes itself with five values. Read them from any QarPeerSpec with the C getters. In C#, PeerSpec carries them as properties; in Rust, they are raw only, through library.raw_api().

ValueC getterC# propertyExampleMeaning
Roleqar_peer_spec_get_roleRoleQAR_PEER_ROLE_TARGETWhat the peer does: SOURCE (renders or captures), TARGET (shows rendered content), RUNTIME (a Hub), CONTROL (a visualizer's control session), INTERNAL (pipeline infrastructure such as the mixer)
Categoryqar_peer_spec_get_categoryCategoryQAR_DEVICE_CATEGORY_HEADSETThe kind of device: HEADSET, CAMERA, VISUALIZER, DESKTOP_PC, SERVER, or UNKNOWN
Device idqar_peer_spec_get_device_idDeviceId"MetaQuest3"The exact model, when known
Device familyqar_peer_spec_get_device_familyDeviceFamily"MetaQuest"The model's family
Device nameqar_peer_spec_get_device_nameDeviceName"Meta Quest 3"What to show the user
  • Render for peers whose role is TARGET; the category and device only say what the target is.
  • Ids and families are open strings, not an enum: new models appear without a new QAROS SDK. Today's families include HoloLens, MetaQuest, Metalens, Headset (a headset that has not reported a known model) and Zed; treat this list as examples, never as complete.
  • Pick a picture or model by device id, else by family, else by category. An unknown model of a known family still matches its family; an unknown family still matches its category.
  • A headset joins as itself and reports its exact model. The identity can still change while the peer runs: re-read it in your qar_peer_subscribe_updates callback instead of caching it.
  • The C string getters fill a caller buffer, like qar_peer_spec_get_display_name. Text is UTF-8.

Show the user what each target is​

QarPeerSpec* peers[64];
size_t written = 0;
qar_result_log_if_error(qar_query_peer_specs(session, peers, 64, &written));

for (size_t i = 0; i < written; ++i)
{
QarPeerRole role = QAR_PEER_ROLE_INTERNAL;
QarDeviceCategory category = QAR_DEVICE_CATEGORY_UNKNOWN;
char name[128] = "", family[64] = "";
if (qar_result_is_success(qar_peer_spec_get_role(peers[i], &role))
&& role == QAR_PEER_ROLE_TARGET)
{
qar_peer_spec_get_category(peers[i], &category);
qar_peer_spec_get_device_name(peers[i], name, sizeof(name)); /* "Meta Quest 3" */
qar_peer_spec_get_device_family(peers[i], family, sizeof(family)); /* "MetaQuest" */
show_target(name, icon_for(family, category)); /* your icon table, category as fallback */
}
qar_peer_spec_handle_destroy(peers[i]);
}

Pick a model for a headset in Unity​

GameObject PrefabFor(PeerSpec peer) =>
headsetPrefabs.TryGetValue(peer.DeviceId, out var byModel) ? byModel // "MetaQuest3"
: headsetPrefabs.TryGetValue(peer.DeviceFamily, out var byFamily) ? byFamily // "MetaQuest"
: peer.Category == DeviceCategory.Camera ? genericCamera
: genericHeadset;

Describing your own device​

An application is always a source (QAR_PEER_ROLE_SOURCE): it describes its device, never its role. By default QAROS publishes it as a desktop PC (DesktopWindows / DesktopLinux). To say more, chain a QarPeerDeviceIdentity on QarPeerPresentation::header.next when you onboard:

  • category must be QAR_DEVICE_CATEGORY_DESKTOP_PC, QAR_DEVICE_CATEGORY_SERVER or QAR_DEVICE_CATEGORY_CAMERA. Anything else fails with QAR_STATUS_PEER_DEVICE_CATEGORY_NOT_ALLOWED and changes nothing.
  • device_id is required. device_family and device_name are optional. An id the Hub's device catalog does not know is fine: the visualizer shows it by family or category, with your name.
  • Nothing is kept for you between starts: chain it on every onboard.

A source app that is a camera​

QarPeerDeviceIdentity identity = {
.header = { .type = QAR_STRUCTURE_TYPE_PEER_DEVICE_IDENTITY },
.category = QAR_DEVICE_CATEGORY_CAMERA,
.device_id = "LuxonisOakD", /* unknown ids are fine */
.device_family = "Luxonis",
.device_name = "Luxonis OAK-D",
};

QarOnboardInit init = qar_onboard_init_default();
QarOnboardLocalAppExt local = qar_onboard_local_app_ext_default();
init.header.next = &local.header;
init.presentation.display_name = "Lab camera 1";
init.presentation.header.next = &identity.header;

QarOnboardingId unused = qar_onboarding_id_default();
QarSession* session = NULL;
QarResult r = qar_runtime_onboard(runtime, &init, NULL, NULL,
cancel, &unused, &session);
/* Joins as Source + Camera + LuxonisOakD. */

Refine the identity later​

When the exact model is known only after your app opened the device, update it. Other peers see a normal peer update:

QarPeerDeviceIdentity refined = {
.header = { .type = QAR_STRUCTURE_TYPE_PEER_DEVICE_IDENTITY },
.category = QAR_DEVICE_CATEGORY_CAMERA,
.device_id = "LuxonisOakDPro",
.device_family = "Luxonis",
.device_name = "OAK-D Pro W",
};
qar_result_log_if_error(qar_peer_update_device_identity(session, &refined));

Declaring CAMERA changes how the visualizer lists and draws your peer. Streaming camera images and pose from a non-ZED camera needs a camera protocol QAROS does not offer yet.

Reacting to changes​

static void on_peer_update(QarPeerSpec* peer, void* user_state)
{
/* peer joined / left / changed presentation or presence */
}

/* token is required: cancelling or destroying it ends the subscription */
qar_peer_subscribe_updates(session, on_peer_update, NULL, token);

Typical uses: refresh a "participants" panel, start a render stream when a target device appears, or pause expensive rendering when the last viewer leaves. Callback threading rules apply as everywhere: see API Conventions.