class

Arcana::Client

Inherits Reference < Object

WebSocket client for connecting to an Arcana bus server.

Connects to ws://host:port/bus, joins with an address, then becomes a full bus participant — send, publish, subscribe, and receive pushed envelopes in real time via the on_message handler.

client = Arcana::Client.new( url: "ws://localhost:19118/bus", address: "shoppe:storefront", # services: owner:capability name: "Shoppe", description: "Print-on-demand storefront generator", tags: ["storefront", "print-on-demand"], )

client.on_message do |envelope| # handle the envelope; reply via client.send(envelope.reply(...)) end

client.connect # blocks: runs the receive loop

For pure consumers (code that uses services but doesn't expose any), pass listed: false so the directory doesn't show an entry that's never meant to be addressed:

client = Arcana::Client.new( url: "ws://localhost:19118/bus", address: "wow-io", # plain agent name listed: false, # mailbox only, no directory entry )

With owner_token, the join claims the address under it, as POST /register does: no other client can then claim it, and a join showing another token is refused. The address stays listed, its mailbox collecting, when the client disconnects. A project's token is the one in its .ai/arcana.token.

With key, the project's Key (its .ai/arcana.key), the client proves the address is its own: the join offers the public key, the bus answers with a challenge, and the client signs it (see Signing). The bus then holds the address for that key and stamps what the client sends verified; verified? turns true once it has. Each envelope the client sends also carries its signature, so the receiver can check it too. A bus that doesn't check keys sends no challenge, and the client works as one without a key.

Constructors

new(url : String, address : String, name : String | Nil = nil, description : String | Nil = nil, kind : Directory::Kind | Nil = nil, guide : String | Nil = nil, schema : JSON::Any | Nil = nil, tags : Array(String) = [] of String, listed : Bool = true, owner_token : String | Nil = nil, key : Key | Nil = nil)
Source

Instance methods

address

Identity readers (Toolset reads these when constructed over Client).

Source
close

Close the connection.

Source
connect

Open the WebSocket, send the join frame, and run the receive loop. Blocks until the connection closes. Run in a fiber (spawn { client.connect }) if you need to do other work concurrently.

Source
connected?

Is the client currently connected?

Source
description
Source
guide
Source
kind
Source
last_error

The last error the bus sent, such as a refused join.

Source
name
Source
on_message

Register a handler for incoming envelopes. Set before calling connect.

Source
publish(topic : String, envelope : Envelope)

Publish an envelope to all subscribers of topic. Its to becomes the topic, as the bus stores it, so a signature still matches.

Source
request(envelope : Envelope, timeout : Time::Span = 30.seconds) : Envelope | Nil

Send an envelope and block until a reply with the same correlation_id arrives or the timeout expires. Returns nil on timeout.

Source
send(envelope : Envelope)

Send an envelope to its to address (signed, with a key).

Source
service?

Is this client registered as a service (vs. an agent)? If kind was set explicitly at construction, use that; otherwise fall back to the address-syntax guess.

Source
subscribe(topic : String)

Subscribe this address to a topic.

Source
unsubscribe(topic : String)

Unsubscribe this address from a topic.

Source
verified?

Has the bus accepted this client's proof that the address is its own? (Only with a key.)

Source