-
Notifications
You must be signed in to change notification settings - Fork 344
Quickstart Guide (Calling)
Caution
This documentation may no longer be current. Click here to view the updated content on our Developer Portal.
- Import the Calling SDK
- Initialize the Calling SDK
- Authorize with Webex Calling
- Place a Call
- Calling Configuration Details
Welcome to the Quick Start Guide for the Webex Calling SDK. This guide is designed to provide developers with a concise walkthrough to swiftly set up, authorize, and test the core calling functionalities within the Calling SDK. By following the sequential flow of this document and integrating the provided code snippets, you'll be able to authenticate your application and initiate your first calls. Whether you're new to Webex's Calling SDK or looking to brush up on the basics, this guide ensures a streamlined experience to get you up and running in no time. Let's dive in!
To import the latest stable version of the Calling SDK you can use NPM or CDN.
The Calling SDK is available as a nodejs
module via NPM. You can install it using either yarn
or npm
utilities:
npm install @webex/[email protected]
or
yarn add @webex/[email protected]
To import the Calling SDK:
import Calling from 'webex/calling';
A minified version of the Calling SDK is also provided via the unpkg.com
Content Delivery Network (CDN). To include the CDN Calling SDK:
<script src='https://unpkg.com/[email protected]/umd/calling.min.js'></script>
To initialize the Calling SDK, either a Webex object or Webex configuration is required.
- Initialize a Webex object.
- Register with Webex Device Manager (WDM) and establish a mercury connection.
- Pass the
webex
andcallingConfig
objects as arguments and create a newCalling
instance which initializes the different client modules. (Refer to the table in the Calling Configuration section to identify Calling Configuration attributes).
const calling = await Calling.init({ webex, callingConfig });
- Pass the
webex
andcallingConfig
objects as arguments and create a newCalling
instance. (Refer to the attribute section for Webex configuration attributes). - Wait for the Calling instance to be ready by listening for the
ready
event. - Once the
ready
event is received, call theregister()
method to trigger Webex Device Manager registration, which establishes a mercury connection and initializes the various client modules within the Calling object.
// Create the Webex configuration
const webexConfig = {
config: {
logger: {
level: 'debug' // Set the desired log level
},
meetings: {
reconnection: {
enabled: true
},
enableRtx: true
},
encryption: {
kmsInitialTimeout: 8000,
kmsMaxTimeout: 40000,
batcherMaxCalls: 30,
caroots: null
},
dss: {}
},
credentials: {
access_token: 'access_token'
}
};
// Create the calling configuration
const callingConfig = {
clientConfig: {
calling: true,
contact: true,
callHistory: true,
callSettings: true,
voicemail: true
},
callingClientConfig: {
logger: {
level: 'info'
}
},
logger: {
level: 'info'
}
};
// Create the Calling object
const calling = await Calling.init({ webexConfig, callingConfig });
let callingClient;
calling.on('ready', () => {
calling.register().then(() => {
callingClient = calling.callingClient;
});
});
Initiating the authorization process with Webex Calling is the first step to harness the communication capabilities of the SDK. Before diving into call operations, you must first obtain the Line
object from the CallingClient
. Once you have the Line
object in hand, you can invoke the line.register()
function to create a device, laying the groundwork for initiating and managing voice calls. Before triggering the register()
method, however, it's crucial to listen for the registered
event to ensure the device is successfully registered and ready for operations. This section will guide you through these steps.
// Get Line object from the callingClient. Currently, only a single
// line is supported in the Calling package
const line = Object.values(callingClient.getLines())[0];
// Listen for the registered event from the line
line.on('registered', (lineInfo) => {
console.log('Line information: ', lineInfo);
});
line.register();
Starting an outgoing call to a designated destination involves a sequence of steps. First, you need to capture the microphone stream, since this step ensures your application is set to transmit voice. Once the microphone stream is in place, you'll need to create the Call
object from the Line
.
const localAudioStream = await Calling.createMicrophoneStream({ audio: true });
const call = line.makeCall({
type: 'uri',
address: 'destination'
});
As you navigate through the intricacies of initiating and managing calls, it's vital to note that the Call
object is not just a static entity but a dynamic one, emitting various events during the course of a call. By actively listening for these events, developers can gain insights into the different transitions and states that a call might enter, be it ringing
, connected
, or ended
. Monitoring these events allows for a more responsive and intuitive user experience, as your application can adjust in real-time based on the call's status. For instance, you might update the user interface to reflect when a call is on hold or when the other party has picked up. Incorporating this event-driven approach will ensure a robust and interactive calling experience for your users.
call.on('progress', (correlationId) => {
console.log('Call is ringing at the remote end');
});
call.on('connect', (correlationId) => {
console.log('Call has been answered');
});
call.on('established', (correlationId) => {
console.log('Call is now established. Media flows both ways');
});
call.on('disconnect', (correlationId) => {
console.log('Call has been disconnected');
});
call.on('remote_media', (track) => {
// Remote media information received from the SDK. This is relayed to the
// application using the remote_media event
document.getElementById('remote-audio').srcObject = new MediaStream([track]);
});
With the Call
object ready, you can then utilize the dial
method, incorporating the previously acquired microphone stream. This method combines the audio input with the call initiation, facilitating a communication link to your desired destination. This guide elucidates each step, providing you with a clear path to efficiently manage and initiate outgoing calls.
await call.dial(localAudioStream);
Handling incoming calls requires a similar approach. The first step involves listening for the incoming_call
event on the Line
. This event signals the arrival of an incoming call and provides the initial alert to the application. Once this event is detected and an incoming call is acknowledged, the focus shifts to the Call
object. Here, similar to outgoing calls, developers should actively listen to the set of events emitted by the Call
object. These events provide real-time updates about the call's status, such as whether it's been answered, or disconnected. Once those listeners are ready, you can call the answer
method to answer the call.
let incomingCall;
line.on('incoming_call', (incomingCall) => {
console.log('Incoming call arrived. Call information', incomingCall);
});
incomingCall.on('disconnect', (correlationId) => {
console.log('Call has been disconnected');
});
incomingCall.on('remote_media', (track) => {
// Remote media information received on the SDK. This is relayed to the
// application using the remote_media event
document.getElementById('remote-audio').srcObject = new MediaStream([track]);
});
incomingCall.answer();
This is the definition for a callingConfig
object:
callingConfig: {
clientConfig: {
calling: boolean,
contact: boolean,
callHistory: boolean,
callSettings: boolean,
voicemail: boolean,
},
callingClientConfig: {
logger: {
level: string
},
discovery: {
country: string,
region: string,
},
serviceData: {
domain: string,
indicator: string,
}
},
logger: {
level: string
}
}
The following tables cover the different configuration attributes present inside the callingConfig
object.
S.no | Attribute | Description | Data Type | Default Attribute? | Public Attribute? |
---|---|---|---|---|---|
1. | calling |
Toggles the availability of the callingClient module. |
Boolean |
No | Yes |
2. | contact |
Toggles the availability of the contactClient module. |
Boolean |
No | Yes |
3. | callHistory |
Toggles the availability of the callHistory module. |
Boolean |
No | Yes |
4. | callSettings |
Toggles the availability of the callSettings module. |
Boolean |
No | Yes |
5. | voicemail |
Toggles the availability of the voicemailClient module. |
Boolean |
No | Yes |
S.no | Attribute | Description | Data Type | Default Attribute? | Public Attribute? |
---|---|---|---|---|---|
1. | discovery |
Object |
No | Yes | |
1.a. | country |
Country from where the device registration is triggered. It has to be an Alpha-2 code as per ISO 3166-1 standards. Here's the list of officially assigned Alpha-2 codes from Wikipedia. | String |
No | Yes |
1.b. | region |
Region from where the device registration is triggered. It should be one of the following: AP-SOUTHEAST , US-EAST , EU , or EU-CENTRAL . |
String |
No | Yes |
2. | serviceData |
it represents the service data of the SDK. | String |
No | Yes |
2.a. | domain |
Identifies which service is using the Calling SDK. | String |
Yes | Yes |
2.b. | indicator |
It indicates in the SDK the type of service being used. Its value should be either CALLING or CONTACT_CENTER . |
ServiceIndicator |
No | No |
3. | logger |
Logger configuration. | Object |
S.no | Attribute | Description | Data Type | Default Attribute? | Public Attribute? |
---|---|---|---|---|---|
1. | level |
Maximum log level that should be printed to the console. Possible values:silent , error , warn , log , info , debug , trace
|
String |
Yes |
Caution
- Introducing the Webex Web Calling SDK
- Core Concepts
- Quickstart guide
- Authorization
- Basic Features
- Advanced Features
- Introduction
- Quickstart Guide
- Basic Features
- Advanced Features
- Multistream
- Migrating SDK version 1 or 2 to version 3