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
Parameter | Type | Required | Description |
---|---|---|---|
project | String | Yes | Project ID from your SignalWire Space |
token | String | Yes | Token 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
Property | Type | Description |
---|---|---|
connected | Boolean | Returns true if the client has connected to Relay. |
calling | Relay::Calling | Returns a Relay::Calling instance associated with the client. |
messaging | Relay::Messaging | Returns 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
Parameter | Type | Required | Description |
---|---|---|---|
event | Symbol | Yes | Event name. Full list of events Relay Client Events |
guards | Array | No | Guard clauses for the event. |
handler | Block | No | Block 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.
Event | Description |
---|---|
:ready | The session has been established and all other methods can now be used. |
:event | The session has received a Relay event. |