Technical reference
This page provides a comprehensive reference for Click-to-Call, including all available configuration parameters and their usage.
Snippet structure
The Click-to-Call snippet consists of two main parts that work together to create a fully functional Click-to-Call widget on your website:
Async loader (IIFE)
The first part is an Immediately Invoked Function Expression (IIFE) that handles:
- Loading the required JavaScript resources
- Authentication with SignalWire services
- Setting up the necessary namespaces and methods
Only modify the API key if necessary
- Never modify the Async Loader code except for the API key if necessary
- The API key is linked to your SignalWire account and specific permissions
- If you need to change the API key, ensure the new key has permissions for the destinations you plan to use
- If your key doesn’t have access to the destination resources, calls will fail to connect
The loader initializes a global sw namespace in your browser window, with a nested c2c namespace that contains
all the methods needed to work with the Click-to-Call widget.
Component initialization
The second part calls the spawn method to configure and render the widget:
When you create a Click-to-Call widget in the SignalWire Dashboard, both parts are generated together as a single code snippet. You can copy this entire snippet into your website’s HTML, and the Click-to-Call widget will be initialized immediately when the page loads.
In some cases, you might want to delay the initialization of the Click-to-Call widget until a specific user action or page event. You can achieve this by:
- Including only the Async Loader part of the script in your page’s head or early in the body
- Calling the component initialization method later when you want to initialize the widget
Methods
spawn
The spawn method is used to initialize the C2C widget. It will use the CSS selectors provided in buttonParentSelector and
callParentSelector to render the call button and widget.
Syntax
Parameters
The component to initialize. Currently only 'C2CButton' is supported.
An object of configuration options that control the behavior and appearance of the C2C widget.
The destination address to call, using SignalWire Address format. Bound to the destination(s) selected when the snippet was created in the dashboard — if the destination is not valid, the call will not connect.
The destination must reference a valid destination that was selected when creating the C2C widget in the dashboard. If the destination is not valid, the call will not connect.
CSS selector for the HTML element where the call button will be rendered. This element must exist in the DOM when sw.c2c.spawn is called.
CSS selector for the HTML element where the call widget will be displayed when a call is active. This element must exist in the DOM when sw.c2c.spawn is called.
Optional HTML markup to render a custom call button. If not provided, a default button will be used. Allows you to fully customize the button appearance to match your website’s design.
Called when the user clicks to start a call, before call setup begins. Return true to proceed with the call or false to cancel.
Common uses: validating form data, performing business hours checks, showing loading indicators, confirming with the user.
Called after call setup completes and the connection is established. Useful for updating UI elements or tracking call start events.
Common uses: hiding the call button, updating UI to reflect active call state, triggering analytics events.
Called when the user or system initiates call end, before teardown begins. Return true to proceed with hanging up or false to cancel.
Common uses: showing confirmation dialogs, performing cleanup operations.
Called after the call has fully ended and the widget is removed from view.
Common uses: restoring UI elements to their pre-call state, showing feedback forms, triggering analytics events.
Called if any error occurs during the call setup process. Receives the error object as a parameter.
Common uses: displaying user-friendly error messages, logging errors, hiding loading indicators, implementing retry logic.
Complete example
Here’s a complete example that demonstrates all available configuration parameters: