Skip to content

The world (GuiNode) ​

A GuiNode holds the part of the world (or of the agent) that the person using your view can see: its name, its data, the messages and the current state of its rules (now). It also holds the methods that send messages and choose actions on behalf of that person.

interface GuiNode

connectToHost resolves to it. In the view of an agent the same object describes that agent.

js
const world = await connectToHost();

world.subscribe((node) => {
  title.textContent = node.name;
  status.textContent = node.now?.text ?? '';
});

The object is a frozen snapshot of the world that never changes. On every change in the world the kit creates a new snapshot and passes it to your subscribe listener. get() always returns the newest one. Because the methods (send, act, ...) always act on the current world, they work from any snapshot including the first one.

Who it is ​

id ​

string. The id of the world. It is 32 characters long and uses digits and the letters a to f. Because it stays the same at every visit, use it as the key of the data you keep about this world.

js
localStorage.setItem(`draft:${world.id}`, text);

A fake world has a made-up id that starts with fa4e.

name ​

string | null. The name of the world as UNaIVERSE shows it. For an agent it can be null for a moment until its profile arrives.

js
document.title = world.name ?? 'Loading…';

type ​

'world' | 'agent' | 'person' | 'unknown'. The kind of node that your view shows ('world' in the view of a world and 'agent' in the view of an agent). It is 'unknown' until the profile arrives.

js
if (world.type === 'world') drawMembers(world.members);

address ​

string | null. The address of the world in UNaIVERSE written as owner/name (for example 'acme/Arena'). It is null until it is known.

js
footer.textContent = `World ${world.address}`;

profile ​

The public description of the world has these fields:

FieldTypeWhat it is
descriptionstring | nullIts description.
ownerstring | nullThe UNaIVERSE nickname of its owner.
placestring | nullIts place (for example 'Rome, Italy') when the owner chose to show it.
isVerifiedbooleantrue when UNaIVERSE verified it.
sincenumber | nullIts creation time in Unix milliseconds.
js
about.textContent = world.profile.description ?? '';
badge.hidden = !world.profile.isVerified;

status ​

'connecting' | 'online' | 'offline' | 'unreachable' | 'not-found' | 'ended'. It tells whether the world (or agent) is available to the person:

  • a world is 'online' while the person is in it and 'ended' when it has finished. An ended world keeps its messages but has a null now, an empty members and canSend: false.
  • an agent is 'connecting' while UNaIVERSE is trying to reach it and then 'online'. It is 'offline' when it has gone away, 'unreachable' when it could not be reached and 'not-found' when no node exists at its address.
js
if (node.status === 'ended') showGameOver();

isOnline ​

boolean. node.isOnline is a shorthand for node.status === 'online'.

js
dot.style.background = node.isOnline ? 'green' : 'gray';

What it shows ​

data ​

Record<string, unknown>. The named values shown by the world, already decoded into one of these forms: URLs or data URIs for img.src, numbers, text, arrays (a grid is an array of rows) and files ({ name, type, url }). A name appears in data once the world sends its first value.

js
img.src = node.data.camera;
score.textContent = node.data.score;

The world chooses its own names. Ask its owner for them or read Object.keys(world.data). onData follows one value as it changes and dataHistory returns its recent values.

messages ​

GuiMessage[]. The conversation between the world and the person, ordered from the oldest message to the newest. It holds the messages of the person, those of the world and of its members and the notes written by the rules. Each message keeps its text in text, its images, files, videos and charts in their own fields and its author in fromId.

js
for (const message of node.messages) addLine(`${message.from}: ${message.text ?? ''}`);

loadMore loads older messages. Two kinds of message also have a method of their own: (1) a question has message.answer and (2) every message of the person has message.retry to send it again when its delivery fails.

showsSenders ​

boolean, missing with an older webapp. It is false when the world asks views to hide who wrote each message and true in every other case (always for an agent). When it is false show only the content of the messages with no names or pictures next to them.

js
author.hidden = node.showsSenders === false;

Comparing it with false as above keeps the names in an older webapp that lacks the field. The owner of the world makes this choice. It is a request and not a filter. from, fromId and the members are still present and the UNaIVERSE view of the world keeps showing its list of members.

now ​

The current moment of the rules of the world. When the rules describe no moment (an agent with no rules, a world that has ended) now is null.

FieldTypeWhat it is
textstring | nullA text that describes the moment such as "Your move" or "Voting is open".
nextstring[]The names given by the rules to the moments that can come next.
actionsArray<{ ... }>The actions the rules offer the person now (in the next table).

Each action of now.actions has these fields:

FieldTypeWhat it is
namestringThe name to pass to act.
tostringThe name of the moment that follows it.
textstring | nullThe text given by the rules for the label of a button.
argsRecord<string, unknown>Its arguments as the rules give them.
canChooseboolean | nulltrue when the person may ask for it, false when it happens on its own and null when the world does not say.
isRequestedbooleantrue when somebody already asked for it.
js
status.textContent = node.now?.text ?? '';
const choices = (node.now?.actions ?? []).filter((action) => action.canChoose !== false);

What the person may do ​

canSend ​

boolean. true when the rules accept a message from the person now (for example on their turn). It is also false while a message of the person is pending.

js
sendButton.disabled = !node.canSend;

See send.

The person ​

me ​

GuiMe or missing. Describes the person using your view. It holds only the fields they chose to share when they accepted your view in the webapp. It always has their nickname and only the ticked public fields of their profile among name, surname, title, organization, city and country. me carries no signature.

js
greeting.textContent = `Welcome, ${node.me?.nickname ?? 'guest'}`;

In a fake world me is the object you wrote in its me field or only the nickname 'you' when you wrote none. In a webapp from before 6 November 2026 me is missing (Who the person is and identity()).

The webapp ​

webapp ​

GuiWebapp. In this object the webapp reports its theme and language, the safe areas of the phone (insets), the height of the on-screen keyboard (keyboard) and the browser features the person allowed your view (allowed). A change in any of them runs your subscribe listener again.

js
document.body.style.background = node.webapp.theme === 'dark' ? '#111' : '#fff';
box.style.paddingBottom = `${node.webapp.insets.bottom + node.webapp.keyboard}px`;

The people and roles of a world ​

Only a world has these three fields and in the view of an agent they are undefined.

members ​

GuiMember[]. Each item is one of the other agents and people in the world with its name, role and data. The list leaves out the person (whose role is in myRole) and is empty once the world has ended.

js
for (const member of node.members ?? []) addLine(`${member.name} (${member.role})`);

roles ​

Array<{ name: string; description: string | null; diagram: Record<string, unknown> | null }>. Each role of the world comes with its name, its description and a diagram (the rules of the role as the world describes them). Most views do not need the diagram.

js
const myRoleText = node.roles?.find((role) => role.name === node.myRole)?.description;

myRole ​

string | null. The name of the role of the person (one of the names in roles).

js
roleBadge.textContent = node.myRole ?? '';

Following the world ​

subscribe(listener) ​

Calls listener with the world immediately and after every change. It returns a function that stops the calls.

js
const stop = world.subscribe((node) => draw(node));

See world.subscribe(listener).

get() ​

Returns the newest world.

js
button.onclick = () => console.log(world.get().now?.text);

See world.get().

onData(name, listener) ​

Calls listener with each new value of data[name] and returns a function that stops the calls.

js
const stop = world.onData('camera', (frame) => { video.src = frame; });

See world.onData(name, listener).

dataHistory(name) ​

Returns the recent values of data[name] and their arrival times in order from the oldest to the newest. Always await the call.

js
const points = await world.dataHistory('score');

See world.dataHistory(name).

loadMore() ​

Adds older messages at the start of messages and resolves to the number it added.

js
const added = await world.loadMore();

See world.loadMore().

Acting for the person ​

send(value) ​

Sends on behalf of the person text, an image, a file of at most 20 MB or a question with a form. It resolves to 'sent', 'failed' or 'not-allowed'.

js
const result = await world.send('left');
await world.send({ file: picker.files[0], text: 'My CV' });

A file reaches the world but only the agents whose code takes files read it (world.send(value) and Send a file).

act(name, args?) ​

Asks the rules to perform one of the actions in now.actions on behalf of the person and resolves to 'requested', 'refused' or 'not-allowed'.

js
const result = await world.act('vote');

See world.act(name, args?).

What the webapp does for your view ​

setPath(path) ​

Writes a path of your view into the address of the webapp so that a link to that address opens your view at the same place. It resolves false when the webapp ignored the path.

js
await world.setPath('/rooms/3');

See world.setPath(path).

onBack(handler) ​

Lets your view handle the back button before the webapp. When the person presses back, handler runs and returns true if it handled the press. The function returned by onBack gives the button back to the webapp.

js
const stop = world.onBack(() => {
  if (panel.hidden) return false; // nothing to close: the webapp goes back
  panel.hidden = true;
  return true;
});

See world.onBack(handler).

askFor(features) ​

Asks the person to let your view use the camera, the microphone or another browser feature that needs their consent.

js
if (!world.webapp.allowed.includes('camera')) await world.askFor(['camera']);

See world.askFor(features).

identity() ​

Resolves at once to me without asking the person anything. It exists for views written for an earlier version of the kit.

js
const { nickname } = await world.identity();

See world.identity().

openProfile(id) ​

Asks the webapp to show the profile card of a member or of the world itself on top of your view. It resolves true when the card is shown and false for an id that belongs neither to the world nor to a member.

js
avatar.onclick = () => world.openProfile(member.id);

See world.openProfile(id).

See also ​

The UNaIVERSE GUI kit, released under the Apache License 2.0. Copyright 2024-2026 UNaIVERSE S.r.l.