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
Examples
Create a Client to interact with the RELAY API.
Properties
Devices and Media Constraints
You can configure the devices your client will use by default with these properties and methods:
Examples
If present, use the first audio output device as default speaker.
Local and Remote Elements
It is usual, in a WebRTC application, to display the local and remote videos in a video-call. In the case of an audio-only call you will need at least the audio element to play the media.
Note: the client will attach the streams to the proper element but will not change the
styleattribute. You can decide if you would like to display or hide theHTMLMediaElementfollowing the application logic.
Use the callUpdate notification to detect call state changes and update the UI accordingly.
STUN/TURN Servers
Through the iceServers you can set/retrieve the default ICE server configuration for all subsequent calls.
Examples
Use both STUN and TURN for the client.
Methods
checkPermissions
The first time a user visits your page, before access his microphone or webcam, the browser display a notification to the user. Use this method if you want to check you already have the permission to access them.
Parameters
Returns
Promise<boolean> - A Promise object resolved with a boolean value.
Examples
Check both audio and video permissions.
connect
Activates the connection to RELAY. Make sure you have attached the listeners you need before connecting the client, or you might miss some events.
Returns
Promise<void>
Examples
disconnect
Disconnect the client from RELAY.
Returns
void
Examples
disableMicrophone
Disable the use of the microphone for the subsequent calls.
disableWebcam
Disable the use of the webcam for the subsequent calls.
enableMicrophone
Enable the use of the microphone for the subsequent calls.
enableWebcam
Enable the use of the webcam for the subsequent calls.
getAudioInDevices
Return all audioinput devices supported by the browser.
Parameters
None
Returns
Promise<MediaDeviceInfo[]> - A Promise object resolved with a list of MediaDeviceInfo.
Examples
List microphones.
getAudioOutDevices
Return all audiooutput devices supported by the browser.
Parameters
None
Returns
Promise<MediaDeviceInfo[]> - A Promise object resolved with a list of MediaDeviceInfo.
Examples
List speakers.
getDeviceResolutions
Return a list of supported resolutions for the given webcam (deviceId).
Parameters
Returns
Promise<Array> - A Promise object resolved with a list of supported resolutions.
Examples
Check both audio and video permissions.
getDevices
Return all devices supported by the browser.
Parameters
None
Returns
Promise<MediaDeviceInfo[]> - A Promise object resolved with a list of MediaDeviceInfo.
Examples
List all devices.
getVideoDevices
Return all videoinput devices supported by the browser.
Parameters
None
Returns
Promise<MediaDeviceInfo[]> - A Promise object resolved with a list of MediaDeviceInfo.
Examples
List webcams.
newCall
Make a new outbound call.
Parameters
Returns
Promise<Call> - A Promise fulfilled with the new outbound Call object or rejected with the error.
Examples
Make an outbound call to
+1 202-555-0122using default values from the Client.
on
Attach an event handler for a specific type of event.
Parameters
Returns
Relay - The client object itself.
Examples
Subscribe to the
signalwire.readyandsignalwire.errorevents.
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
Returns
Relay - The client object itself.
Examples
Subscribe to the
signalwire.errorand then, remove the event handler.
refreshDevices
DEPRECATED: Use
getDevicesinstead.
Refresh the devices and return a Promise fulfilled with the new devices.
Parameters
None
Returns
Promise<devices> - New devices object.
Examples
Refresh client’s devices with async/await syntax.
refreshToken
When the JWT is going to expire, the Client dispatch a notification with type refreshToken that allows you to refresh the token and keep your session alive.
Parameters
Returns
Promise<void>
Examples
Listen for all notifications and, on
refreshToken, fetch a new JWT from your backend and update the token on the client.
setAudioSettings
You can set the default audio constraints for your client. See here for further details.
Note: It’s a common behaviour, in WebRTC applications, to persist devices user’s selection to then reuse them across visits.
Due to a Webkit’s security protocols, Safari generates randomdeviceIdon each page load.
To avoid this issue you can specify two additional properties (micIdandmicLabel) in theconstraintsinput parameter.
The client will use these values to assure the microphone you want to use is available by matching bothidandlabelwith the device list retrieved from the browser.
Parameters
Returns
Promise<MediaTrackConstraints> - Audio constraints applied to the client.
Examples
Set microphone by
idandlabelwith theechoCancellationflag turned off.
setVideoSettings
You can set the default video constraints for your client. See here for further details.
Note: It’s a common behaviour, in WebRTC applications, to persist devices user’s selection to then reuse them across visits.
Due to a Webkit’s security protocols, Safari generates randomdeviceIdon each page load.
To avoid this issue you can specify two additional properties (camIdandcamLabel) in theconstraintsinput parameter.
The client will use these values to assure the webcam you want to use is available by matching bothidandlabelwith the device list retrieved from the browser.
Parameters
Returns
Promise<MediaTrackConstraints> - Video constraints applied to the client.
Examples
Set webcam by
idandlabelwith 720p resolution.
Events
All available events you can attach a listener on.