user_event
user_event
Allows the user to set and send events to the connected client on the call. This is useful for triggering actions on the client side.
Commonly used with the browser-sdk.
Each user_event method sends one event, whose payload is the event object.
On an unanswered inbound call, user_event first attempts to answer the call before sending the event. Outbound calls and
calls that are already answered aren’t answered again.
user_event
An object that accepts the following properties.
Properties
user_event.event
The payload of one custom event: an object that can contain any JSON values. Instead of an object, you can pass a SWML
variable reference, such as ${my_event}, that resolves to an event object.
Event Object
The event object is sent to the client as the payload of a single event of type user_event. To send several events, use
several user_event methods.
Variable references in the payload’s string values, including strings inside nested objects and arrays, are expanded before the event is sent. Object keys aren’t expanded.
SignalWire adds call details such as call_id, node_id, and segment_id at the top level of the payload, so top-level
fields aren’t guaranteed to arrive unchanged. Put your custom data under your own key, as in the examples below, to avoid
name collisions.
The client can listen for these events using the on-method.
Examples
Send a custom event to the client
Send one event with multiple payload fields
The eventA and eventB fields below are both part of a single event’s payload.