The SignalWire Client

View as Markdown

The SignalWire Client provides access to SignalWire’s services on the browser. It provides methods to handle incoming calls, dial to addresses, and register devices for notifications.

Instantiation

The SignalWire client is instantiated using the SignalWire function.

If you’re including the @signalwire/js dependency as a script in HTML, the SignalWire function is a property of the SignalWire global variable that the script sets:

1<script type="text/javascript" src="https://cdn.signalwire.com/@signalwire/js"></script>
2<script>
3 async function main() {
4 const client = await SignalWire.SignalWire({
5 token: "<TOKEN>",
6 });
7 }
8</script>

If you installed @signalwire/js from npm:

1import { SignalWire } from "@signalwire/js";
2
3async function main() {
4 const client = await SignalWire({
5 token: "<TOKEN>",
6 });
7}

For React or React Native projects, use the community library:

1import { useSignalWire } from "@signalwire-community/react";
2
3export default function App() {
4 const client = useSignalWire({
5 token: "<TOKEN>",
6 });
7}

Parameters

token
stringRequired

The access token for the subscriber.

rootElement
HTMLElement

The HTML container element where the SDK will display the video stream.

incomingCallHandlers
IncomingCallHandlers

Callback functions for when a call is received. See IncomingCallHandlers.

userVariables
Record<string, any>

Arbitrary variables that are transparent to FreeSWITCH.

You can manage the DOM yourself by not specifying a rootElement here and using the buildVideoElement function instead.

Example

1<html>
2 <body>
3 <script type="text/javascript" src="https://cdn.signalwire.com/@signalwire/js"></script>
4
5 <script>
6 async function main() {
7 const client = await SignalWire.SignalWire({
8 token: "<TOKEN>",
9 });
10
11 const conversations = await client.conversation.getConversations();
12 console.log(conversations);
13
14 const addresses = await client.address.getAddresses();
15 console.log(addresses);
16 }
17 main();
18 </script>
19 </body>
20</html>

Properties

httpHost
string

Returns the URL of the host that the client will use to make HTTP requests (like querying the list of addresses or conversations). Read-only.

1console.log(client.httpHost());
2// fabric.signalwire.com

Methods

Namespaces

Certain methods and properties are organized into namespaces for clarity. They can be accessed as follows:

1client.address.getAddresses();
2client.chat.getMessages();
3client.conversation.getConversations();

Type aliases

IncomingCallHandlers

Use this object to assign callback functions which get invoked when a call is received.

NameTypeRequired?Description
all(IncomingCallNotification) => voidOptionalSince push support has been removed, identical to websocket
websocket(IncomingCallNotification) => voidOptionalCallback for calls received via websocket (overrides all)

IncomingCallNotification

The object passed into the IncomingCallHandlers callback with the call description and controls.

NameTypeDescription
inviteobject-
invite.detailsIncomingInviteThe details of the invite.
invite.accept(CallOptions) => Promise<CallFabricRoomSession>Invoke this function to accept the incoming call
invite.reject() => Promise<void>Invoke this function to reject the incoming call

IncomingInvite

NameTypeDescription
source"websocket"
callIDstringUnique ID of the incoming call
sdpstringDeprecated
caller_id_namestringName of the caller
caller_id_numberstringID or number of the caller
callee_id_namestringName of the callee
callee_id_numberstringID or number of the callee
display_directionstringDirection of the call
nodeIdstringThe node from where the call was received

CallOptions

NameTypeRequired?Description
rootElementHTMLElementOptionalThe HTML container element where the SDK will display the video stream.
audioboolean | MediaTrackConstraintsOptionalMedia track constraints for audio. Passing true uses browser defaults, and false disables audio.
videoboolean | MediaTrackConstraintsOptionalMedia track constraints for video. Passing true uses browser defaults, and false disables video.
disableUdpIceServersbooleanOptionalDisables the ICE UDP transport policy.
userVariablesRecord<string, any>OptionalArbitrary variables that are transparent to FreeSWITCH.

MediaStreamConstraints

NameTypeRequired?Description
audioboolean | MediaTrackConstraintsOptionalMedia track constraints for audio. Passing true uses browser defaults, and false disables audio.
videoboolean | MediaTrackConstraintsOptionalMedia track constraints for video. Passing true uses browser defaults, and false disables video.
peerIdentitystringOptionalPeer identity.
preferCurrentTabbooleanOptionalWhether to prefer current tab for the call.

CallFabricRoomSession

Extends RoomSession.

NameTypeDescription
start() => voidStarts the call.
answerboolean | MediaTrackConstraintsAnswers the call (only works if the CallFabricRoomSession was a result of an incoming call).
hangup(id?) => voidEnds the ongoing call by default. If the id of an RTCPeer is passed, hangs up that RTCPeer.