[AS3] Class r1.rpc.RPC

[AS3] Class r1.rpc.RPC

Client API
Packager1.rpc
Classpublic class RPC
InheritanceRPC Inheritance flash.events.EventDispatcher

An instance of this class represents a remote service end point, which is a configured servlet instance.

Usually an application needs just one service end point. This class has a singleton, defaultRPC, which is typically initialized by a call to initSingleRPC()).

See also



Public Properties
 PropertyDefined by
  authFailurePolicy : String = "as_usual"
[static] The policy for authorization failure.
RPC
  defaultRPC : RPC
[static] The singleton RPC object.
RPC
  passwordEncrypted : Boolean = true
If set to true, use CHAP login, where only dynamic digests are sent across the wire.
RPC
  pollingMaxDelaySeconds : int
[write-only] The longest delay between polling, in minutes.
RPC
  rpcEncoding : int = 1
The RPC data encoding.
RPC
  rpcUrl : String = "null"
The URL for this RPC interface.
RPC
Public Methods
 MethodDefined by
  
RPC(url:String, encoding:int, sessionNeverTimeout:Boolean = true)
Constructor.
RPC
  
changePassword(cb:Function, id:String, oldpw:String, newpw:String):void
To change a user's password.
RPC
  
digest(password:String):String
RPC
  
initSingleRPC(url:String, encoding:int, sessionNeverTimeout:Boolean = true):void
[static] Initializes the defaultRPC singleton instance.
RPC
  
login(receiver:*, id:String, password:String):void
Authenticates the user identified by id and password by invoking the login handler on the server-side (which is a Java class that extends the r1.rpc.LoginHandler class whose class name is specified by the loginHandlerClass init-parameter) to establish the server-side user session and returns an object representing the user.
RPC
  
logout(cb:Function = null):void
Clears the server session.
RPC
  
ping():void
To ping the server to keep session alive and fetch waiting messages, if any.
RPC
  
registerUser(cb:Function, id:String, password:String, userData:Object):void
To register a new user.
RPC
Events
 EventSummaryDefined by
   Dispatched when the server messages are received.RPC
   Dispatched in one of the three situations: (1) when a remote call to an authorized method failed authorization, for instance, the user has not logged on yet; (2) logging in failed; and (3) registering new user (using CHAP) failed.RPC
Public Constants
 ConstantDefined by
  AUTH_FAIL_AS_USUAL : String = "as_usual"
[static]
RPC
  AUTH_FAIL_SILIENCE : String = "silence"
[static]
RPC
  RPC_BINARY : int = 2
[static] A constant indicating to use binary message encoding.
RPC
  RPC_DEFAULT : int = 0
[static] A constant indicating to use the default message encoding.
RPC
  RPC_ENCRYPTED : int = 3
[static] A constant indicating to use encrypted binary message encoding.
RPC
  RPC_JSON : int = 1
[static] A constant indicating to use JSON textual message encoding.
RPC
Property detail
authFailurePolicyproperty
public static var authFailurePolicy:String = "as_usual"

The policy for authorization failure. By default it is AUTH_FAIL_AS_USUAL, which means an authentication failure is treated as a normal server-side exception. The other value is AUTH_FAIL_SILENCE, where the failure is simply ignored.

defaultRPCproperty 
public static var defaultRPC:RPC

The singleton RPC object. If a fa¸ade class is initialized with a null RPC, then this instance is used.

See also

passwordEncryptedproperty 
public var passwordEncrypted:Boolean = true

If set to true, use CHAP login, where only dynamic digests are sent across the wire. Otherwise, passwords are passed to server as plain text.

pollingMaxDelaySecondsproperty 
pollingMaxDelaySeconds:int  [write-only]

The longest delay between polling, in minutes. If this is set to be greater than 0, polling to server is started. A polling happens automatically during a remote method call, and the server message is piggybacked in the result. Therefore the actual server message polling can happen more frequently than this period.

Implementation
    public function set pollingMaxDelaySeconds(value:int):void
rpcEncodingproperty 
public var rpcEncoding:int = 1

The RPC data encoding.

rpcUrlproperty 
public var rpcUrl:String = "null"

The URL for this RPC interface. It can be absolute or relative.

Constructor detail
RPC()constructor
public function RPC(url:String, encoding:int, sessionNeverTimeout:Boolean = true)

Constructor.

Parameters
url:String — the URL for this RPC interface. It can be absolute or relative.
 
encoding:int — the RPC data encoding.
 
sessionNeverTimeout:Boolean (default = true) — when true, if the server initialization returns a session timeout value, the client-side will periodically connect to the server so that the server session never times out.
Method detail
call()method
r1_internal function call(encoding:int, facadeName:String, methodName:String, args:Array, receiver:*):void

Parameters
encoding:int — can be one of the following three possibilities:
  1. a callback function with this signature:
    function cb(retVal:ThatReturnType=null, rpcResult:RPCResult):void;
  2. an array of [ host, property ] to bind the returned value to.
  3. an array of [ host, property, errorCallback ], where the host/property is used to bind the returned value to, and errorCallback is a callback function when error happens; it has such a signature:
    function errorCallback(err:ErrorResult):void;
receiver can be null, indicating to use default error handling and ignore the success of the call and its return value, if any.
 
facadeName:String
 
methodName:String
 
args:Array
 
receiver:*
changePassword()method 
public function changePassword(cb:Function, id:String, oldpw:String, newpw:String):void

To change a user's password. This is usually used for systems using, CHAP login, where password digest is sent to the server.

Parameters
cb:Function — the new user's ID. It can be null, where the server should create one and return it.
 
id:String — a normal RPC callback, whose signature is: function cb(id:String, res:RPCResult):void;
 
oldpw:String — the old password, in plain-text.
 
newpw:String — the new password, in plain-text.
digest()method 
public function digest(password:String):StringParameters
password:String

Returns
String
initSingleRPC()method 
public static function initSingleRPC(url:String, encoding:int, sessionNeverTimeout:Boolean = true):void

Initializes the defaultRPC singleton instance. In most applications, a single RPC interface suffices, so a call to this function at the start of the application is all you need.

Parameters
url:String
 
encoding:int
 
sessionNeverTimeout:Boolean (default = true)
login()method 
public function login(receiver:*, id:String, password:String):void

Authenticates the user identified by id and password by invoking the login handler on the server-side (which is a Java class that extends the r1.rpc.LoginHandler class whose class name is specified by the loginHandlerClass init-parameter) to establish the server-side user session and returns an object representing the user.

Parameters
receiver:* — can be one of the following three possibilities:
  1. a normal RPC callback function with this signature:
    function cb(userVal:UserType=null, rpcResult:RPCResult=null):void;
  2. an array of [ host, property ] to bind the returned value to.
  3. an array of [ host, property, errorCallback ], where the host/property is used to bind the returned value to, and errorCallback is a callback function when error happens; it has such a signature:
    function errorCallback(err:ErrorResult):void;
 
id:String
 
password:String
logout()method 
public function logout(cb:Function = null):void

Clears the server session.

Parameters
cb:Function (default = null) — this usual RPC callback is used to clear the client-side state. If specified, it is called synchronously. Its signature is: callback(any:null, rpcResult:RPCResult):void {}
ping()method 
public function ping():void

To ping the server to keep session alive and fetch waiting messages, if any.

registerUser()method 
public function registerUser(cb:Function, id:String, password:String, userData:Object):void

To register a new user.

Parameters
cb:Function — the new user's ID. It can be null, where the server should create one and return it.
 
id:String — a normal RPC callback, whose signature is: function cb(id:String, res:RPCResult):void; The return value is the user ID. If the ID was sent the server, on successful registration, the same ID is returned; or an authentication error will occur if the same ID exists. If no ID was sent, the server should create one and return here; The client should save this ID.
 
password:String — user's password.
 
userData:Object — extra user information. This can be a generic Object or a VO object that the server side expects.
Event detail
messageevent 
Event object type: r1.rpc.RPCResult

Dispatched when the server messages are received.

SERVER_AUTH_FAILUREevent  
Event object type: r1.rpc.ErrorResult

Dispatched in one of the three situations: (1) when a remote call to an authorized method failed authorization, for instance, the user has not logged on yet; (2) logging in failed; and (3) registering new user (using CHAP) failed.

Constant detail
AUTH_FAIL_AS_USUALconstant
public static const AUTH_FAIL_AS_USUAL:String = "as_usual"

See also

AUTH_FAIL_SILIENCEconstant 
public static const AUTH_FAIL_SILIENCE:String = "silence"

See also

RPC_BINARYconstant 
public static const RPC_BINARY:int = 2

A constant indicating to use binary message encoding. (To be implemented)

RPC_DEFAULTconstant 
public static const RPC_DEFAULT:int = 0

A constant indicating to use the default message encoding.

RPC_ENCRYPTEDconstant 
public static const RPC_ENCRYPTED:int = 3

A constant indicating to use encrypted binary message encoding. (To be implemented)

RPC_JSONconstant 
public static const RPC_JSON:int = 1

A constant indicating to use JSON textual message encoding.