Namespace: wsc

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.setLogLevel 

Constants are fully capitalized:

 wsc.ERRORCODE 

Usage Example

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

  1. Create Session and CallPackage object:

    var wscSession, callPackage;
          
    wscSession = new wsc.Session(userId, wsUri, onSuccess, onFailure);
    callPackage = new wsc.CallPackage(wscSession);
    callPackage.onIncomingCall = handleIncomingCall;
    callPackage.onResurrect = handleResurrectCall;

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

  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 = onAuthenticaiton;
  3. 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, callErrorCallback);
    // Register callbacks for call state and media state changes...
    call.onCallStateChange = handleCallStateChange;
    call.onMediaStreamEvent = handleMediaStreamEvent;

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

  4. Start the call:

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

    call.end();

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#onMessage, and wsc.CallPackage#onRehydration.

Classes

AuthHandler
Call
CallConfig
CallPackage
CapabilityExchange
CapabilityPackage
Chat
ChatPackage
DataReceiver
DataSender
DataTransfer
ExtensibleSession
FileTransfer
FileTransferPackage
FlashCall
FlashCallPackage
Map
Message
MessageAlertPackage
MessageCounts
MessageSummary
Messaging
Messaging
MessagingPackage
Notification
Session
Subscription

Members

<static> AUTHTYPE :String

Enum for authentication type.

Type:
  • String
Properties:
Name Type Description
SERVICE String

The type of authentication required by the application.

TURN String

The type of authentication required by the TURN server.

<static> CALLSTATE :String

Enum for call state.

Type:
  • String
Properties:
Name Type Description
NONE String

call is merely created.

STARTED String

call has started.

RESPONDED String

for call initiator. This state means the call request has been responded to by remote side; for the call receiver, this state means the receiver has responded to the incoming request.

ESTABLISHED String

call has been established.

UPDATING String

call is updating its capabilities, for example, adding video to the call.

UPDATE_FAILED String

the update action failed.

UPDATED String

call update action succeed.

FAILED String

call met with some exception and has been closed abnormally.

ENDED String

call has been closed normally.

<static> ConnectionStateEnum :String

Enum for Session state of wsc.Chat and wsc.FileTransfer.

Type:
  • String
Properties:
Name Type Description
INIT String

The connection is not established.

ESTABLISHED String

The connection has established.

ERROR String

The connection met error.

CLOSED String

The connection has closed.

<static> ERRORCODE :Number

Enum for error code.

Type:
  • Number
Properties:
Name Type Description
UNAUTHORIZED Number

The request requires user authentication. This response is issued by servers and registrars.

FORBIDDEN Number

The server understood the request, but is refusing to fulfill it.

RESOURCE_UNAVAILABLE Number

The server has definitive information that the user does not exist at the domain specified in the Request-URI.

PROXYAUTH_REQUIRED Number

This code is similar to 401 (UNAUTHORIZED), but indicates that the client MUST first authenticate itself with the proxy.

TEMPORARILY_UNAVAILABLE Number

The callee's end system was contacted successfully but the callee is currently unavailable.

BUSY_HERE Number

The callee's end system was contacted successfully, but the callee is currently not willing or able to take additional calls at this end system.

REQUEST_TERMINATED Number

The request was terminated.

SYSTEM_ERROR Number

The server encountered an unexpected condition that prevented it from fulfilling the request.

BUSY_EVERYWHERE Number

The callee's end system was contacted successfully but the callee is busy and does not wish to take the call at this time.

DECLINED Number

The callee's machine was successfully contacted but the user explicitly does not wish to or cannot participate.

WEBSOCKET_ERROR Number

The error code for WebSocket.

PEERCONNECTION_ERROR Number

The error code for peerConnection.

MEDIA_ERROR Number

The error code for media stream.

RESTORE_FAILED Number

The error code for reloading session state.

SAVE_FAILED Number

The error code for saving session state.

<static> LOGLEVEL :Number

Enum for log level. DEBUG < INFO < WARN < ERROR < OFF

Type:
  • Number
Properties:
Name Type Description
DEBUG Number

record DEBUG or higher level logs.

INFO Number

record INFO or higher level logs.

WARN Number

record WARN or higher level logs.

ERROR Number

record ERROR or higher level logs.

OFF Number

do not record logs.

<static> MEDIADIRECTION :String

Enum for media direction.

Type:
  • String
Properties:
Name Type Description
SENDONLY String

the media direction is send only.

RECVONLY String

the media direction is receive only.

SENDRECV String

the media direction is both send and receive.

NONE String

no media

<static> MEDIASTREAMEVENT :String

Enum for media stream event.

Type:
  • String
Properties:
Name Type Description
LOCAL_STREAM_ADDED String

local media stream added to the call.

LOCAL_STREAM_REMOVED String

local media stream removed from the call.

LOCAL_STREAM_ERROR String

there is an error with the local media stream.

REMOTE_STREAM_ADDED String

remote media stream added to the call.

REMOTE_STREAM_REMOVED String

remote media stream removed from the call.

REMOTE_STREAM_ERROR String

there is an error with the remote media stream.

<static> SESSIONSTATE :String

Enum for session state.

Type:
  • String
Properties:
Name Type Description
NONE String

session is merely created.

CONNECTED String

session has connected with server.

RECONNECTING String

session's connection with server is broken; client is reconnecting to server.

RELOADING String

client is reloading the session data from browser local cache.

FAILED String

session met some exception and has been abnormally closed.

CLOSED String

session has been normally closed.

Methods

<static> 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.

Parameters:
Name Type Description
child Object

the child object

parent Object

the parent object

Example
// 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)
}

// Make the CallExtension object as a child of 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);
};

<static> getLogger()

Gets the logger.

<static> getLogger()

Gets the logger.

<static> setLogger()

Sets the logger.

<static> setLogger()

Sets the logger.

<static> setLogLevel(logLevel)

Set log level, default level is INFO.

Parameters:
Name Type Description
logLevel wsc.LOGLEVEL

the log level.

<static> setLogLevel(logLevel)

Set log level, default level is INFO.

Parameters:
Name Type Description
logLevel wsc.LOGLEVEL

the log level.

wscLoginWithOAuthToken(token, redirectPage, loginWindowType, oauthUri, wscAppUri)

Login WebRTC Session Controller server by OAuth token, which is obtained and maintained by web application.

Parameters:
Name Type Description
token String

The OAuth token, which application has obtained.

redirectPage String

The web page URI to which the browser will be redirected after login.

loginWindowType String

What type of window application would like to perform the WebRTC Session Controller login with token. This value should be "current_window" or "new_window".

oauthUri String

The full URI, which should be same as the OAuth request Uri of Wsc Servlet Authenticator configured in security realm of Weblogic console, including host name and port.
For example: http://demoapp.com:7001/login/facebook

wscAppUri String

The request URI of the application, which is configured in the WebRTC Session Controller console for OAuth login.

Example
var redirectPage = "http://demoapp.com/wscdemopage.html";
var loginWindowType = "current_window";
var oauthUri = "http://demoapp.com:7001/login/facebook";
var wscAppUri = "/ws/webrtc/facebook";
wsc.wscLoginWithOAuthToken(oauthToken, redirectPage, loginWindowType,  oauthUri, wscAppUri);

Type Definitions

CallState

An object that represents the signalling state of wsc.Call, wsc.Chat and wsc.FileTransfer.

Type:
  • Object
Properties:
Name Type Description
state String

The call state value.

status Object

the status value.

Properties
Name Type Description
code String

The code of the status.

reason String

The reason of the status.

ErrorInfo

An object that contains information about a specific error.

Type:
  • Object
Properties:
Name Type Description
code Number

the code for the error.

reason String

the reason of the error.

Oracle® Communications WebRTC Session Controller JavaScript API Reference, E55131-03
Copyright © 2013, 2015, Oracle and/or its affiliates. All rights reserved.