UNAVI Docs unavi.xyz
Build · Scripting API

wired:portal

Portals between spaces and travel across them.

A two-way portal links two portal prims in separate spaces with the same link-id. Calling open emits a link-intent in the target space, where a receiving script completes the connection via pair.

Interface portals

Uses document-id, prim-id, error, document, link-id.

record

Unpaired portal link request originating from source-space.

source-space: document-id
link: link-id
enum

Resolved link status of a portal this frame.

noneNo destination set.
one-wayDestination set with no link-id (one-way).
pendingDestination space is still loading or resolving.
unpairedDestination space loaded, but no portal paired with this link.
pairedPaired with a matching portal in the destination space.

intent-subscription

resource

Queues up to 64 pairing intents.

drain

methoddrain: func(max: u32) -> list<link-intent>

dropped

methoddropped: func() -> u64

claim

methodclaim: func(intent: link-intent) -> bool

Claims intent for this script; returns true for the single winning subscriber in the space.

open

funcopen: func(document: borrow<document>, prim: prim-id, target-space: document-id) -> result<_, error>

Opens the portal on prim toward target-space as a shared session write, preserving its dimensions. Fails with invalid-argument if prim has no portal property.

The link-id is derived deterministically from prim and target-space so every peer produces the same link.

pair

funcpair: func(document: borrow<document>, prim: prim-id, intent: link-intent) -> result<_, error>

Pairs the portal on prim with an incoming intent as a shared write.

close

funcclose: func(document: borrow<document>, prim: prim-id) -> result<_, error>

Clears this peer's session destination on prim, exposing underlying layers. No-op if this peer did not open it; consumes no rate quota.

funclink-state: func(document: borrow<document>, prim: prim-id) -> result<link-status, error>

Returns the portal's resolved status this frame. Fails with not-ready if the portal is not placed yet.

travel

functravel: func(target-space: document-id) -> result<_, error>

Moves the local user into target-space, loading it if needed.

current-space

funccurrent-space: func() -> result<option<document-id>, error>

Returns the local user's current space, or none while transitioning.

intents

funcintents: func() -> result<intent-subscription, error>

Subscribes to incoming pairing intents for the calling script's space.

Source

/// Portals between spaces and travel across them.
///
/// A two-way portal links two portal prims in separate spaces with the same
/// `link-id`. Calling `open` emits a `link-intent` in the target space, where a
/// receiving script completes the connection via `pair`.
package wired:portal;

interface portals {
  use wired:core/ids.{document-id, prim-id};
  use wired:core/error.{error};
  use wired:scene/document.{document};
  use wired:scene/properties.{link-id};

  /// Unpaired portal link request originating from `source-space`.
  record link-intent {
    source-space: document-id,
    link:         link-id,
  }

  /// Opens the portal on `prim` toward `target-space` as a `shared` session
  /// write, preserving its dimensions. Fails with `invalid-argument` if `prim`
  /// has no portal property.
  ///
  /// The `link-id` is derived deterministically from `prim` and `target-space`
  /// so every peer produces the same link.
  open: func(document: borrow<document>, prim: prim-id, target-space: document-id) -> result<_, error>;

  /// Pairs the portal on `prim` with an incoming `intent` as a `shared` write.
  pair: func(document: borrow<document>, prim: prim-id, intent: link-intent) -> result<_, error>;

  /// Clears this peer's session destination on `prim`, exposing underlying
  /// layers. No-op if this peer did not open it; consumes no rate quota.
  close: func(document: borrow<document>, prim: prim-id) -> result<_, error>;

  /// Resolved link status of a portal this frame.
  enum link-status {
    /// No destination set.
    none,
    /// Destination set with no `link-id` (one-way).
    one-way,
    /// Destination space is still loading or resolving.
    pending,
    /// Destination space loaded, but no portal paired with this link.
    unpaired,
    /// Paired with a matching portal in the destination space.
    paired,
  }

  /// Returns the portal's resolved status this frame. Fails with `not-ready` if
  /// the portal is not placed yet.
  link-state: func(document: borrow<document>, prim: prim-id) -> result<link-status, error>;

  /// Moves the local user into `target-space`, loading it if needed.
  travel: func(target-space: document-id) -> result<_, error>;

  /// Returns the local user's current space, or `none` while transitioning.
  current-space: func() -> result<option<document-id>, error>;

  /// Subscribes to incoming pairing intents for the calling script's space.
  intents: func() -> result<intent-subscription, error>;

  /// Queues up to 64 pairing intents.
  resource intent-subscription {
    drain:   func(max: u32) -> list<link-intent>;
    dropped: func() -> u64;
    /// Claims `intent` for this script; returns `true` for the single winning
    /// subscriber in the space.
    claim:   func(intent: link-intent) -> bool;
  }
}