application.onConnect()
application.onConnect = function (clientObj [, p1, ..., pN]){}
Invoked when NetConnection.connect() is called from the client. This handler is passed a Client object representing the connecting client. Use the Client object to perform actions on the client in the handler. For example, use this function to accept, reject, or redirect a client connection, perform authentication, define methods on the Client object to be called remotely from NetConnection.call(), and set the Client.readAccess and Client.writeAccess properties to determine client access rights to server-side objects.
When performing authentication, all of the information required for authentication should be sent from the NetConnection.connect() method to the onConnect() handler as parameters (p1..., pN).
If you don't define an onConnect() handler, connections are accepted by default.
If there are several simultaneous connection requests for an application, the server serializes the requests so that only one application.onConnect() handler is executed at a time. It's a good idea to write code for the application.onConnect() function that is executed quickly to prevent a long connection time for clients.
Flash Communication Server 1
clientObj A Client object. This object contains information about the client that is connecting to the application.
p1 ..., pN Optional parameters passed to the application.onConnect() handler from the client-side NetConnection.connect() method when a client connects to the application.
A boolean value; true causes the server to accept the connection; false causes the server to reject the connection.
When true is returned, NetConnection.onStatus() is invoked on the client with info.code set to "NetConnection.Connect.Success". When false is returned, NetConnection.onStatus() is invoked on the client with info.code set to "NetConnection.Connect.Rejected".
If null or no value is returned, the server puts the client in a pending state and the client can't receive or send messages. If the client is put in a pending state, you must call application.acceptConnection() or application.rejectConnection() at a later time to accept or reject the connection. For example, you can perform external authentication by making a NetConnection call in your application.onConnect() event handler to an application server and having the reply handler call application.acceptConnection() or application.rejectConnection(), depending on the information received by the reply handler.
You can also call application.acceptConnection() or application.rejectConnection() in the application.onConnect() event handler. If you do, any value returned by the function is ignored.
A. Client-side ActionScript B. Server-Side ActionScript
The following examples show three ways to accept or reject a connection in the onConnect() handler:
application.onConnect = function (clientObj [, p1, ..., pN]){
// Insert code here to call methods that do authentication.
// Returning null puts the client in a pending state.
return null;
};
(Usage 2)
application.onConnect = function (clientObj [, p1, ..., pN]){
// Insert code here to call methods that do authentication.
// The following code accepts the connection:
application.acceptConnection(clientObj);
};
(Usage 3)
application.onConnect = function (clientObj [, p1, ..., pN])
{
// Insert code here to call methods that do authentication.
// The following code accepts the connection by returning true:
return true;
};
The following example verifies that the user has sent the password "XXXX". If the password is sent, the user's access rights are modified and the user can complete the connection. In this case, the user can create or write to streams and shared objects in the user's own directory and can read or view any shared object or stream in this application instance.
application.onConnect = function (newClient, userName, password){
// Do all the application-specific connect logic.
if (password == "XXXX"){
newClient.writeAccess = "/" + userName;
this.acceptConnection(newClient);
} else {
var err = new Object();
err.message = "Invalid password";
this.rejectConnection(newClient, err);
}
};
If the password is incorrect, the user is rejected and an information object with a message property set to "Invalid password" is returned to the client side. The object is assigned to infoObject.application. To access the message property, use the following code on the client side:
trace(info.application.message);
// Prints "Invalid password"
// in the Output panel on the client side.
};
출처: http://livedocs.adobe.com/flashmediaserver/3.0/hpdocs/help.html?content=00000244.html
'Media > WOWZA' 카테고리의 다른 글
[FMS] Best practices for real-time collaboration using Flash Media Server (0) | 2012.09.26 |
---|---|
[FMS] RTMP, RTMFP (0) | 2012.09.13 |
[FMS] Buying guide (0) | 2012.08.23 |
Comparison between the three flash servers Flash Media Server, Wowza and Red5 (0) | 2012.08.23 |
[FMS] Calculating bandwidth needs for Flash Media Server 3 (0) | 2012.08.22 |