My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Documentation  
Full documentation for CGP Client Library
Featured, Phase-Implementation
Updated Mar 10, 2010 by slon.vsapogah

Introduction

CGP Client Library provides a set of classes that allows to log into CommuniGate Pro server, send requests, receive responses and log out.

Logging in

Net.login():void

Starts log in process. Parameters:

  • host:String
  • user:String
  • password:String
  • failoverScheme:String = "socket 80, socket 11024, binding 80, binding 8100, sbinding 443" Optional. Specification of channels that should be used.

When log in process succeeds or fails, NetEvent.STATUS event is dispatched via Net.dispatcher.

Throws error if already logging in or logged in.

Example:

Net.dispatcher.addEventListener(NetEvent.STATUS, statusHandler);
Net.login(hostInput.text, loginInput.text, passwordInput.text);

function statusHandler(event:NetEvent):void
{
    if (event.status == NetStatus.LOGGED_IN)
    {
        // we're in
    }
    else if (event.status == NetStatus.RELAX && event.error)
    {
        // login failed - ex. password is incorrect or server is not available
    }
}

Net.dispatcher:IEventDispatcher

dispatcher is a static property of Net class. It dispatches NetEvent.STATUS event with the following properties:

  • newStatus:String - current status of the connection.
  • oldStatus:String - status of the connection before status change.
  • error:Error - if status change was caused by some error, it is provided here

Possible values of newStatus and oldStatus are specified in NetStatus class static constants:

  • RELAX:String = "relax"
  • LOGGING_IN:String = "loggingIn"
  • LOGGED_IN:String = "loggedIn"

Net.status:String

Current connection status. Possible values are specified in NetStatus class.

Net.loginData:Array

Array of XML-s that were received during login process. Can be used for example to determine session id.

Working with synchronous XIMSS requests

Net.ximss():void

Sends XML to the server. Parameters:

  • xml:XML - request XML without id attribute
  • dataCallback:Function - is called each time server returns data response for this request. Function signature is function(xml:XML).
  • responseCallback:Function - is called when server returns <response id="..."/> reponse or when we have failed to make request. Function signature is function(object:Object) because both XML and Error objects can be passed.

Example:

Net.ximss(<sendIM peer="maxim@communigate.com">Hello, how are you?</sendIM>, null, sendIM_responseCallback);

private function sendIM_responseCallback(object:Object):void
{
    // getErrorText() is a function in the library
    var errorText:String = getErrorText(object);
    if (errorText)
        trace("Failed to send instant message: " + errorText);
}

Working with asynchronous XIMSS messages

Net.dispatcher:IEventDispatcher

When asynchronous message arrived it is dispatched by dispatcher as an event with name ximss-asyncMessageName with properties:

  • xml:XML - message body

Example:

Net.dispatcher.addEventListener("ximss-readIM", readIMHandler);

private function readIMHandler(xml:XML):void
{
    trace("New incoming message: " + xml);
}

Logging out

Send <bye/> synchronous request to log out.


Sign in to add a comment
Powered by Google Project Hosting