NotifyClient - Client
The NotifyClient API provides methods that enable you to use Notify telephony functionality, such as making and receiving calls from a web browser.
Several NotifyClient methods take a callback function as a parameter. Because NotifyClient method calls are made asynchronously, these methods can't return a value directly. Use the callback function to parse the returned data, such as by assigning variables or making other API calls.
NotifyClient - Client(Object notifyConfig, Boolean initializeVendorClientLazily)
Instantiates a new Notify WebRTC Client object.
| Name | Type | Description |
|---|---|---|
| initializeVendorClientLazily | Boolean | Flag that indicates whether to use the autoSelectVendorCallback function passed
in the setCallerId() method to automatically set the caller's
associated vendor (notifyConfig.vendor does not need to be
defined in the constructor).
|
| notifyConfig | Object | JSON object that contains the configuration settings for the Notify WebRTC Client. |
| notifyConfig.autoLoadScriptResources | Boolean | Flag that indicates how to load the core JS library needed by the vendor
client.
|
| notifyConfig.callerId | Number | Registered Notify number to use. Do not directly set this value. Use the method notifyClient.setCallerID() to set this value. |
| notifyConfig.forceRefreshToken | Boolean | Flag that indicates whether to auto-renew expired client tokens.
|
| notifyConfig.skipParentId | Boolean | Flag that indicates whether to immediately invoke the onIncoming caller for
incoming calls.
|
| notifyConfig.vendor | Constant | Vendor to which the caller belongs.
|
The following example shows how to create the NotifyClient constructor, register various event listeners, and initialize the client driver.
jQuery(function () {
var notifyConfig = {
autoLoadScriptResources: true // This will take care of auto loading the JS resources needed by the client (if any)
};
var client = new SNC.Notify.Client(notifyConfig, true); // The second argument ensures that the proper vendor for the given number is auto determined
client.setCallerId('valid_notify_long_number', function () {
// This is called after the vendor has been determined.
if (!notifyConfig.vendor) // Means this number has no compatible vendor
return;
client.addEventListener(SNC.Notify.STD_EVENTS.ONLINE, function () {
// Ability to call is available
});
client.addEventListener(SNC.Notify.STD_EVENTS.OFFLINE, function () {
// Ability to call is _not_ available right now
});
client.addEventListener(SNC.Notify.STD_EVENTS.ERROR, function (msg, code) {
// Some error happened
});
//... register other event handlers here
//Show UI elements which can be used to invoke client.call() and other APIs
client.init(); // This is important to call this.
});
});
NotifyClient - addEventListener(String event, Function fn)
Registers an event handler to listen for changes in a Notify client.
Using this method you can register multiple listeners. Each listener must be a separate method call.
| Name | Type | Description |
|---|---|---|
| event | String | Name of the event to listen for. Instead of passing strings, use the
constants defined in
|
| Type | Description |
|---|---|
| Function | Function to use to de-register a listener. |
This example shows how to register multiple listeners.
jQuery(function () {
var notifyConfig = {
autoLoadScriptResources: true // This will take care of auto loading the JS resources needed by the client (if any)
};
var client = new SNC.Notify.Client(notifyConfig, true); // The second argument ensures that the proper client for the given number is auto determined
client.setCallerId('valid_notify_long_number', function () {
// This is called after the client has been determined.
if (!notifyConfig.vendor) // Means this number has no compatible client
return;
client.addEventListener(SNC.Notify.STD_EVENTS.ONLINE, function () {
// Ability to call is available
});
client.addEventListener(SNC.Notify.STD_EVENTS.OFFLINE, function () {
// Ability to call is _not_ available right now
});
client.addEventListener(SNC.Notify.STD_EVENTS.ERROR, function (msg, code) {
// Some error happened
});
//... register other event handlers here
client.init(); // This is important to call this.
});
});
This example shows how to de-register a listener.
var dereg = notifyClient.addEventListener(SNC.Notify.STD_EVENTS.ONLINE, function () {
...
});
dereg();
// The event listener function is no longer triggered.
NotifyClient - call(Object identifier)
Calls the specified phone number or the phone number associated with a specified user.
SNC.Notify.Status.| Name | Type | Description |
|---|---|---|
| identifier | Object | JSON object that contains either a phone number to call or the sys_id of a
WebRTC user. Passing a user sys_id causes the call to be made through
browser-to-browser communication. You can obtain the user sys_id from the Notify WebRTC Session table. 注: If you provide both a phone number and user sys_id,
the method only uses the phone number. |
| Type | Description |
|---|---|
| void |
This example demonstrates passing a phone number as the function parameter.
notifyClient.call({
phoneNumber: "+18001112223"
});
This example demonstrates passing a user record sys_id as the function parameter.
notifyClient.call({
userId: "6816f79cc0a8016401c5a33be04be441"
});
This example shows a button click handler.
$j("#pickupCallBtn").on("click", function() {
notifyClient.hangupCall();
});
This example shows an event handler.
onConnect: function(status) {
// webRTC receives a call connection event (incoming or outgoing).
if (status == SNC.Notify.Status.OPEN) {
setStatus(getTimeStamp() + " -- Successfully established call");
showHangupButton();
}
},
NotifyClient - destroy()
Kills the current Notify client, rendering it unusable.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| void |
NotifyClient - forwardCall(Object argument)
Forwards an ongoing incoming or outgoing phone call to either a different phone number or a different WebRTC client.
| Name | Type | Description |
|---|---|---|
| argument | Object | JSON object that contains the necessary information for forwarding the call to either a phone number or a WebRTC client (user sys_id). You can obtain this sys_id from the Notify WebRTC Session table. |
| Type | Description |
|---|---|
| void |
This example demonstrates forwarding a call to a different phone number. The dtmf attribute allows you to send DTMF dial tones to the receiving number.
var arg = {
type: "number",
id: "+17012345678",
dtmf: "1234"
}
client.forwardCall(arg);
This example demonstrates forwarding a call to a different Notify client.
var arg = {
type: "userId",
id: "6816f79cc0a8016401c5a33be04be441"
}
client.forwardCall(arg);
NotifyClient - getAvailableClients(Function callback)
Returns a list of clients available to accept calls.
This method excludes the current client from the list. The equivalent Notify-getAvailableClients() method does not filter any user.
| Name | Type | Description |
|---|---|---|
| callback | Function | Function to use to parse the list of clients. This function accepts a single
parameter, an array of JSON objects with the following
format: |
| Type | Description |
|---|---|
| void |
NotifyClient - getParentId(String callId, Function callback)
Returns the parent call identifier for a specified call identifier, if one exists.
Depending on the telephony provider, there may be a delay before the parent call identifier is returned; therefore you must provide a callback function.
| Name | Type | Description |
|---|---|---|
| callId | String | Unique identifier of the call for which to return the parent call identifier. |
| callback | Function | Function that obtains the JSON object that contains either the parent call identifier or an error message if the identifier could not be obtained after several tries. |
| Type | Description |
|---|---|
| String | Parent call identifier. |
This example shows how to use this method to obtain the parent call identifier.
notifyClient.getParentId( callId, function(jsonObj) {} );
This example shows the contents of the jsonObj parameter.
{
parentId: "xyz",
error: "msg"
}
NotifyClient - getStatus()
Returns the normalized status of the current call.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| String | Current status of the call. The values returned by the telephony provider API are normalized by replacing the returned driver value with its equivalent value as defined in SNC.Notify.Status. |
This example shows how to obtain the status of the current Notify client.
clientStatus = notifyClient.getStatus();
NotifyClient - hangupCall()
End the current call.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| void |
This example how to hang up a call.
$j("#pickupCallBtn").on("click", function() {
notifyClient.hangupCall();
});
NotifyClient - init()
Initializes the client driver.
For example, when using the Twilio client, it invokes the method Twilio.Device.setup(). Call this method after the user has interacted with the page. This initialization process is asynchronous, therefore, you must provide an ONLINE event handler. This handler is called when the setup process is complete and the system is ready to take or make calls.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| void |
This example shows how to initialize the Notify client.
$j(function() {
notifyClient = new SNC.Notify.Client( notifyConfig );
notifyClient.setCallerId( '+31858889170' );
notifyClient.init();
});
NotifyClient - mute(Boolean muted)
Mute or unmute the current client.
| Name | Type | Description |
|---|---|---|
| muted | Boolean | Mutes or unmutes the current call.
|
| Type | Description |
|---|---|
| void |
This example shows how to send mute the current call.
notifyClient.mute( "true" );
NotifyClient - pickupCall()
Answers and connects to an incoming call from a WebRTC client.
Call this method when there is a notification of an incoming call.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| void |
This example shows how to pickup a call.
$j("#pickupCallBtn").on("click", function() {
notifyClient.pickupCall();
});
NotifyClient - sendDtmf(String digits)
Send one or more DTMF-valid digits over the current call.
| Name | Type | Description |
|---|---|---|
| digits | String | One or more DTMF-valid digits. |
| Type | Description |
|---|---|
| void |
This example shows how to send DTMF signals to the current call.
notifyClient.SendDtmf( "1246AF" ) {} );
NotifyClient - setCallerId(String value, Function autoSelectVendorCallback)
Sets the caller ID for the current client session.
You can change or update the caller ID at any time however, the caller ID must belong to the same vendor.
| Name | Type | Description |
|---|---|---|
| value | String | Phone number to use to make and receive calls. |
| autoSelectVendorCallback | Function | Optional.
initializeVendorClientLazily must be set
to "true" in the constructor to use this function, otherwise an error is thrown.
Name of the callback function to call once the vendor is automatically set for the specified phone number. With this option, the vendor does not need to be specified in the constructor (notifyConfig.vendor). Auto vendor selection is an asynchronous operation. Therefore, this callback is required to indicate when it is safe to call notifyConfig.init(), as this method requires that the vendor be set before it is called. In addition, you must also check if notifyConfig.vendor has been set in the callback to ensure that a vendor has been specified. |
| Type | Description |
|---|---|
| void |
This example shows how to set the caller ID. This example assumes that the vendor is set in the constructor.
$j(function() {
notifyClient = new SNC.Notify.Client( notifyConfig );
notifyClient.setCallerId( '+31858889170' );
notifyClient.init();
});
NotifyClient - setClientAvailable(Boolean available)
Sets the availability of an active WebRTC client agent.
This type of availability is different than an agent being in a call. In this case, an active WebRTC client may be connected and not on a call, but may not want to receive calls.
Calling this method updates the Available field value on the Notify Client Connected Session [notify_client_session] record associated with this client session. You can get a list of available clients using the getAvailableClients() method.
| Name | Type | Description |
|---|---|---|
| available | boolean | Flag that indicates whether an active WebRTC client wants to receive calls.
|
| Type | Description |
|---|---|
| void |