Notify client event handlers

Notify Client event handlers allow you to define scripted behavior for responding to events from a telephony provider such as the Twilio service.

Event handlers

A communication between the Notify WebRTC Client and a telephony provider is asynchronous. The client function calls, such as notifyClient.call() do not wait for a response from the telephony provider. Instead, event handler methods define how to respond to certain events from the telephony provider.

You can create event handler implementations when creating the Notify Client configuration object. Fully define the handlers in the configuration object before instantiating a Notify Client object.

onReady

The onReady function runs after you call the init function on the client object. The onReady function indicates that the WebRTC session is ready.

onOffline

The onOffline function runs if the WebRTC session is not active.

onError

The onError function runs if the client encounters an error.

This function exposes one parameter. Use this parameter when implementing the event handler function.
Table 1. Parameters
Parameter Type Description
message String The error message text.

onConnect

The onConnect function runs when the client receives a call connection event for an incoming or outgoing call.

This function exposes one parameter. Use this parameter when implementing the event handler function.
Table 2. Parameters
Parameter Type Description
status String The call status, as a string constant.
Note: When evaluating call status, use the constants provided by SNC.Notify.Status.
onConnect: function(status) { // webRTC receives a call connection event (incoming or outgoing).
    if (status == SNC.Notify.Status.OPEN) {
        setStatus(getTimeStamp() + " -- Successfully established call");
        showHangupButton(); //update the UI
    }
},

onDisconnect

The onDisconnect function runs when a call disconnects.


    

onIncoming

The onIncoming function runs when a call is made to the client and the telephony provider returns the parent call ID.

This function exposes these parameters as a single JSON object. Use these parameters when implementing the event handler function.
Table 3. Parameters
Parameter Type Description
callInfo.from String The caller's phone number.
callInfo.to String The called phone number.
callInfo.callSid String The SID of the call from the telephony provider.
onIncoming: function(callInfo) {
   gs.log('incomming call from : ' + callInfo.from);
   var gru = new GlideRecord('sys_user');
   gru.addQuery('phone', callInfo.from);
   gru.query(function() {
      while (gru.next()) { // there may be more than one person with same number?
         // fetch caller's info
         gs.log('caller : ' + gru.name);
      }
   });
},

onOutgoing

The onOutgoing function runs when an outgoing call is made from the client.

This function exposes one parameter. Use this parameter when implementing the event handler function.
Table 4. Parameters
Parameter Type Description
callSid String The SID of the call from the telephony provider.

onAccept

The onAccept function when the client accepts an incoming call.


      
    

onMute

The onMute function runs when the client is muted.

onUnmute

The onUnmute function runs when the client is unmuted.

onCancel

The onCancel function runs if the caller cancels the call.