Index


Namespace wsc

The wsc namespace exposes the WebRTC Session Controller JavaScript API for extension by application and SPI (Service Provider Interface) developers.

Naming Conventions

Functions beginning with an uppercase character must be instantiated.

For example, wsc.Session should be instantiated in the following manner:

 session = new wsc.Session()

Functions beginning with a lowercase character may be invoked directly:

 
   wsc.setDebug

Constants are fully capitalized:

   wsc.ERRORCODE

Usage Example

An application which wants to use the Call feature can do something like this:

  1. Create a Session object:

    var wscSession,
    callPackage,
    wscSession = new wsc.Session(userId, wsUri, onSuccess, onFailure);
  2. Create an AuthHandler object for the wscSession object, and define the refresh callback function for the AuthHandler object:

    var authHandler = new wsc.AuthHandler(wscSession);
    authHandler.refresh = authCallbackFunc;
  3. In the onSuccess callback, create a CallPackage object:

    function onSuccess() {

    // Save the session ID to HTML5 storage if needed...
    callPackage = new wsc.CallPackage(wscSession);

    // Register callbacks for incoming calls and rehydrated calls...
    callPackage.onIncomingCall = handleIncomingCall;

    callPackage.onResurrect = handleRehydratedCall;

    Refer to wsc.CallPackage#event:onIncomingCall and wsc.CallPackage#event:onResurrect for more information.

  4. Create a CallConfig object and then create a Call object:

    var callConfig = new wsc.CallConfig(wsc.MEDIADIRECTION.SENDRECV, wsc.MEDIADIRECTION.NONE) 

    var call = callPackage.createCall(callee, callConfig, onError);

    // Register callbacks for call state and media state changes...
    call.onCallStateChange = handleCallStateChange;

    call.onMediaStreamEvent = handleMediaStateChange;

    Refer wsc.Call#event:onCallStateChange and wsc.Call#event:onMediaStreamEvent for more information.

  5. Start the call:

    call.start();
  6. End the call:

    call.endCall();

Extension Points

The following extension points are available:

  1. Methods supporting the parameter extHeaders can add extension headers to the message.

    For example, an extHeaders object like this:

    {'customerKey1':'value1','customerKey2':'value2'}

    will be added to the message in the following format:

    { "control" : {}, "header" :
    {...,'customerKey1':'value1','customerKey2':'value2'}, "payload" : {},
    }
  2. You can send custom messages within a sub-session using the wsc.ExtensibleSession#sendMessage method. That method takes a wsc.Message as an argument, and expects that the message has the control, header, and payload blocks.

    An example use case is to send INFO messages as part of an ongoing wsc.Call. That can be achieved by extending wsc.Call and wsc.CallPackage so that the extension will support sending and receiving INFO messages while delegating all other functionality to the existing wsc.Call and wsc.CallPackage.

    The method for extending an object is documented here wsc.extend. It shows sample code that extends wsc.Call and wsc.CallPackage to add support for sending INFO messages as part of a Call.

  3. You can develop a new package and register it with the wsc.Session. That new package may support a completely new feature. A package implements the callback functions onMessage and onRehydration, to receive messages from the wsc.Session and restore the data using rehydration. See wsc.CallPackage for an example. For more information, see wsc.CallPackage#event:onMessage, and wsc.CallPackage#event:onRehydration.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
wsc
Method Summary
Method Attributes Method Name and Description
<static>  
wsc.extend(child, parent)
Called to extend the objects exposed through the wsc namespace.
<static>  
wsc.getLogger()
Gets the logger.
<static>  
wsc.setLogger()
Sets the logger.
<static>  
wsc.setLogLevel(logLevel)
Set log level, default level is INFO.
Namespace Detail
wsc
Method Detail
<static> wsc.extend(child, parent)
Called to extend the objects exposed through the wsc namespace. This function copies all the members that are attached to the prototype object of the parent to the prototype object of the child. Those inherited members can be overridden in the child object without impacting the parent.
The following code snippet shows how to add support to handle INFO messages as part of a Call
by extending Call and CallPackage objects.

   // CallExtension is the child object which extends Call object and overrides a function.
   // The constructor of the child object calls the constructor of the parent so that the objects
   // initialized in the parent's constructor code are available to the child.

   function CallExtension() {
   // Chain constructor
   CallExtension.superclass.constructor.apply(this, arguments)
   }

   // The following statement makes the CallExtension object as a child of {@link wsc.Call}
   wsc.extend(CallExtension, wsc.Call);

   // Override the method onMessage to support handling INFO messages

   CallExtension.prototype.onMessage = function (message) {
   // Check if this is an INFO message, if so, handle it here
   if (this.isInfoMessage(message)) {
   handleInfoMessage(message);
   } else {
   // Delegate the handling to the base class
   CallExtension.superclass.onMessage.call(this, message)
   }
   };

   CallExtension.prototype.isInfoMessage = function (message) {
   var action = message.header.action,
   type = message.control.type;
   return action === "info" && type === "message";
   };

   // Extend and CallPackage object and override the prepareCall function such that
   // a CallExtension object is created instead of the default Call object
   function CallPackageExtension() {
   CallPackageExtension.superclass.constructor.apply(this, arguments)
   }

   wsc.extend(CallPackageExtension, wsc.CallPackage);

   // Override prepareCall function
   CallPackageExtension.prototype.prepareCall = function (session, callConfig, caller, callee) {
   return new CallExtension(session, callConfig, caller, callee);
   };
Parameters:
{Object} child
the child object
{Object} parent
the parent object

<static> wsc.getLogger()
Gets the logger.

<static> wsc.setLogger()
Sets the logger.

<static> wsc.setLogLevel(logLevel)
Set log level, default level is INFO.
Parameters:
{wsc.LOGLEVEL} logLevel
the log level

Copyright © 2005, 2013, Oracle and/or its affiliates. All rights reserved.