Skip to main content

Relay Client

Relay::Client is the basic connection to Relay, allowing you send commands to Relay and setup handlers for inbound events.

Constructor

Constructs a client object to interact with Relay.

Parameters

ParameterTypeRequiredDescription
projectStringYesProject ID from your SignalWire Space
tokenStringYesToken from your SignalWire Space

Examples

Create a Client to interact with the Relay API.

Signalwire::Relay::Client.new(project: "your-project-id", token: "your-project-token")

Properties

PropertyTypeDescription
connectedBooleanReturns true if the client has connected to Relay.
callingRelay::CallingReturns a Relay::Calling instance associated with the client.
messagingRelay::MessagingReturns a Relay::Messaging instance associated with the client.

Methods

connect!

Starts the connection to the Relay API. The connection to Relay does not happen automatically so that you can setup handlers to events that might occur before the connection is successfully established.

Returns

Promise<void>

Examples

# Make sure you have attached the listeners you need before connecting the client, or you might miss some events.
client.connect!

disconnect!

Disconnect the client from Relay.

Returns

nil

Examples

client.disconnect!

on

Attach an event handler for a specific type of event.

Parameters

ParameterTypeRequiredDescription
eventSymbolYesEvent name. Full list of events Relay Client Events
guardsArrayNoGuard clauses for the event.
handlerBlockNoBlock to call when the event is received. It will be passed in as an argument.

Returns

String - A low-level handler ID.

Examples

Subscribe to the ready event.

client.on :ready do
# do something on ready
end

Events

All available events you can attach a listener on.

EventDescription
:readyThe session has been established and all other methods can now be used.
:eventThe session has received a Relay event.