Build an experience

The Vaznor Experiences SDK

An experience is a web page people use together inside a channel: a game, a quiz, a shared tool. You host the page. Vaznor gives it a session, the people in it, and state they all share.

How it's kept safe

  • Your page runs in a sandboxed frame with its own blank origin. It can't touch the Vaznor page, its cookies, its storage or its API.
  • No token or session is ever handed to your page. All it can do is send the few messages listed here, about the one session it's in.
  • It only learns names and avatars if you ask for them, and spaces see what you asked for before adding you.
  • Pages must be served over https. Only someone who can manage a space can add your experience to it. Who may start one is a role permission.

Get started

  1. Open Settings, then Developers in Vaznor and create an experience, with the address of your page.
  2. Include the SDK and connect, as in the example below.
  3. Copy your experience's ID. In a space you manage, open its settings, go to Experiences and add it. Your own experience also shows for you to test in DMs and your own channels.

A whole experience

<script src="https://vaznor.com/sdk/vaznor-experiences.js"></script>
<script>
  VaznorExperience.connect().then((vaznor) => {
    const show = (shared) => render(shared.value);
    show(vaznor.shared);
    vaznor.onState(show);
    button.onclick = () => vaznor.set("value", 1 + Math.floor(Math.random() * 6));
  });
</script>

Here's that as a working page. It only does anything inside a session.

What you can call

  • VaznorExperience.connect() resolves when Vaznor answers. Call it once.
  • vaznor.session is { id, name, host }. host says whether this person started it.
  • vaznor.me is { id }, plus name and avatar with the identity scope.
  • vaznor.participants lists who's in the session, with the participants scope. Empty otherwise.
  • vaznor.shared is the state everyone shares.
  • vaznor.set(key, value) changes it for everyone. null removes the key. It stays until the session ends. Resolves when saved, rejects if refused.
  • vaznor.send(name, data) tells everyone something that isn't worth keeping, such as a cursor or a reaction.
  • vaznor.onState(fn), vaznor.onEvent(fn) and vaznor.onParticipants(fn) call you when those change. Each returns a function that stops it.

Limits

  • Keys are letters, numbers, _, . and -, up to 64 characters.
  • Shared state is limited to 128 KB per session, and each event to 8 KB.
  • About 20 actions a second for each person. Past that, calls are refused for a moment.
  • Up to 10 experiences for each developer.

Scopes

  • identity: names and avatars rather than just IDs.
  • participants: the list of who else is in the session.

What it can't do yet

There's no server-side API for experiences, no payments and no public directory. Scores you keep in shared state don't reach a space's leaderboard. Experiences are added by ID.