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:
-
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.
-
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; -
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.
-
Start the call:
call.start();
-
End the call:
call.end();
Extension Points
The following extension points are available:
-
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" : {},
} -
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.
- 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 SERVICEString The type of authentication required by the application.
TURNString The type of authentication required by the TURN server.
-
<static> CALLSTATE :String
-
Enum for call state.
Type:
- String
Properties:
Name Type Description NONEString call is merely created.
STARTEDString call has started.
RESPONDEDString 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.
ESTABLISHEDString call has been established.
UPDATINGString call is updating its capabilities, for example, adding video to the call.
UPDATE_FAILEDString the update action failed.
UPDATEDString call update action succeed.
FAILEDString call met with some exception and has been closed abnormally.
ENDEDString call has been closed normally.
-
<static> ConnectionStateEnum :String
-
Enum for Session state of wsc.Chat and wsc.FileTransfer.
Type:
- String
Properties:
Name Type Description INITString The connection is not established.
ESTABLISHEDString The connection has established.
ERRORString The connection met error.
CLOSEDString The connection has closed.
-
<static> ERRORCODE :Number
-
Enum for error code.
Type:
- Number
Properties:
Name Type Description UNAUTHORIZEDNumber The request requires user authentication. This response is issued by servers and registrars.
FORBIDDENNumber The server understood the request, but is refusing to fulfill it.
RESOURCE_UNAVAILABLENumber The server has definitive information that the user does not exist at the domain specified in the Request-URI.
PROXYAUTH_REQUIREDNumber This code is similar to 401 (UNAUTHORIZED), but indicates that the client MUST first authenticate itself with the proxy.
TEMPORARILY_UNAVAILABLENumber The callee's end system was contacted successfully but the callee is currently unavailable.
BUSY_HERENumber 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_TERMINATEDNumber The request was terminated.
SYSTEM_ERRORNumber The server encountered an unexpected condition that prevented it from fulfilling the request.
BUSY_EVERYWHERENumber The callee's end system was contacted successfully but the callee is busy and does not wish to take the call at this time.
DECLINEDNumber The callee's machine was successfully contacted but the user explicitly does not wish to or cannot participate.
WEBSOCKET_ERRORNumber The error code for WebSocket.
PEERCONNECTION_ERRORNumber The error code for peerConnection.
MEDIA_ERRORNumber The error code for media stream.
RESTORE_FAILEDNumber The error code for reloading session state.
SAVE_FAILEDNumber 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 DEBUGNumber record DEBUG or higher level logs.
INFONumber record INFO or higher level logs.
WARNNumber record WARN or higher level logs.
ERRORNumber record ERROR or higher level logs.
OFFNumber do not record logs.
-
<static> MEDIADIRECTION :String
-
Enum for media direction.
Type:
- String
Properties:
Name Type Description SENDONLYString the media direction is send only.
RECVONLYString the media direction is receive only.
SENDRECVString the media direction is both send and receive.
NONEString no media
-
<static> MEDIASTREAMEVENT :String
-
Enum for media stream event.
Type:
- String
Properties:
Name Type Description LOCAL_STREAM_ADDEDString local media stream added to the call.
LOCAL_STREAM_REMOVEDString local media stream removed from the call.
LOCAL_STREAM_ERRORString there is an error with the local media stream.
REMOTE_STREAM_ADDEDString remote media stream added to the call.
REMOTE_STREAM_REMOVEDString remote media stream removed from the call.
REMOTE_STREAM_ERRORString there is an error with the remote media stream.
-
<static> SESSIONSTATE :String
-
Enum for session state.
Type:
- String
Properties:
Name Type Description NONEString session is merely created.
CONNECTEDString session has connected with server.
RECONNECTINGString session's connection with server is broken; client is reconnecting to server.
RELOADINGString client is reloading the session data from browser local cache.
FAILEDString session met some exception and has been abnormally closed.
CLOSEDString 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 childObject the child object
parentObject 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 logLevelwsc.LOGLEVEL the log level.
-
<static> setLogLevel(logLevel)
-
Set log level, default level is INFO.
Parameters:
Name Type Description logLevelwsc.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 tokenString The OAuth token, which application has obtained.
redirectPageString The web page URI to which the browser will be redirected after login.
loginWindowTypeString 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".
oauthUriString 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/facebookwscAppUriString 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 stateString The call state value.
statusObject the status value.
Properties
Name Type Description codeString The code of the status.
reasonString The reason of the status.
-
ErrorInfo
-
An object that contains information about a specific error.
Type:
- Object
Properties:
Name Type Description codeNumber the code for the error.
reasonString the reason of the error.