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 | required | Project ID from your SignalWire Space |
Token | string | required | Token from your SignalWire Space |
Host | string | optional | The endpoint URI to send requests to. The SignalWire Space URL, should be a string similar {your-space}.signalwire.com . |
signalwireContexts | string | optional | List of Contexts for inbound |
Examples
Create a Client to interact with the Relay API.
signalwireContexts := []string{DefaultContext}
client := signalwire.Client(PProjectID, PTokenID, "" /*host, empty for default*/, signalwireContexts)
Properties
Property | Type | Description |
---|---|---|
calling | Relay.Calling | Returns a Relay.Calling instance associated with the client. |
messaging | Relay.Messaging | Returns a Relay.Messaging instance associated with the client. |
tasking | Relay.Tasking | Returns a Relay.Tasking instance associated with the client. |
Methods
Connect()
Activates 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
error
Examples
signalwireContexts := []string{DefaultContext}
client := signalwire.Client(PProjectID, PTokenID, "" /*host, empty for default*/, signalwireContexts)
// register callback, anonymous function
client.OnReady = func (client *signalwire.ClientSession) {
signalwire.Log.Info("Client connected\n")
}
// start
err := client.Connect()
if err != nil {
signalwire.Log.Error("Error occurred while starting Signalwire Client\n")
}
Disconnect()
Disconnect the client from Relay.
Returns
error
Examples
if err := client.Disconnect(); err != nil {
signalwire.Log.Error("Error occurred while trying to disconnect Client\n")
}
Events
All available events you can attach a listener on.
Property | Description |
---|---|
OnReady | The session has been established and all other methods can now be used. |