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

projectstringrequiredProject ID from your SignalWire Space
tokenstringrequiredToken from your SignalWire Space

Examples

Create a Client to interact with the Relay API.
<?php

$client = new SignalWire\Relay\Client([
'project' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'token' => 'PTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
]);

Properties

callingRelay.CallingReturns a Relay.Calling 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.

Available In:

Returns

void

Examples

<?php

$client->connect();

disconnect

Disconnect the client from Relay.

Available In:

Returns

void

Examples

<?php

$client->disconnect();

on

Attach an event handler for a specific type of event.

Available In:

Parameters

$eventstringrequiredEvent name. Full list of events Relay.Client Events
$callbackfunctionrequiredCallable to invoke when the event comes.

Returns

Relay.Client - The client object itself.

Examples

Subscribe to the 'signalwire.ready' and 'signalwire.error' events.
<?php

$client->on('signalwire.ready', function($client) {
// Your client is ready!
})->on('signalwire.error', function(\Exception $error) {
// Got an error...
});

off

Remove an event handler that were attached with .on(). If no handler parameter is passed, all listeners for that event will be removed.

Parameters

$eventstringrequiredEvent name. Full list of events Relay.Client Events
$callbackfunctionoptionalCallable to remove.
Note: $callback will be removed from the stack by reference so make sure to use the same reference in both .on() and .off() methods.

Returns

Relay.Client - The client object itself.

Examples

Subscribe to the 'signalwire.error' and then, remove the event handler.
<?php

$errorHandler = function($error) {
// Log the error..
};

$client->on('signalwire.error', $errorHandler);

// .. later
$client->off('signalwire.error', $errorHandler);

Events

All available events you can attach a listener on.

signalwire.readyThe session has been established and all other methods can now be used.
signalwire.errorThere is an error dispatch at the session level.
signalwire.socket.openThe websocket is open. However, you have not yet been authenticated.
signalwire.socket.errorThe websocket gave an error.
signalwire.socket.messageThe client has received a message from the websocket.
signalwire.socket.closeThe websocket is closing.