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
ProjectstringrequiredProject ID from your SignalWire Space
TokenstringrequiredToken from your SignalWire Space
HoststringoptionalThe endpoint URI to send requests to. The SignalWire Space URL, should be a string similar {your-space}.signalwire.com.
signalwireContextsstringoptionalList 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

PropertyTypeDescription
callingRelay.CallingReturns a Relay.Calling instance associated with the client.
messagingRelay.MessagingReturns a Relay.Messaging instance associated with the client.
taskingRelay.TaskingReturns 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.

PropertyDescription
OnReadyThe session has been established and all other methods can now be used.