The AMFChannel class provides the AMF support for messaging. You can configure this Channel to poll the server at an interval to approximate server push. You can also use this Channel with polling disabled to send RPC messages to remote destinations to invoke their methods.

The AMFChannel relies on network services native to Flash Player and AIR, and exposed to ActionScript by the NetConnection class. This channel uses NetConnection exclusively, and creates a new NetConnection per instance.

Channels are created within the framework using the ServerConfig.getChannel() method. Channels can be constructed directly and assigned to a ChannelSet if desired.

Channels represent a physical connection to a remote endpoint. Channels are shared across destinations by default. This means that a client targetting different destinations may use the same Channel to communicate with these destinations.

When used in polling mode, this Channel polls the server for new messages based on the polling-interval-seconds property in the configuration file, and this can be changed by setting the pollingInterval property. The default value is 3 seconds. To enable polling, the channel must be connected and the polling-enabled property in the configuration file must be set to true, or the pollingEnabled property of the Channel must be set to true.

Constructor

@:value({ uri : null, id : null })new(?id:String, ?uri:String)

Constructor.

Parameters:

id

The id of this Channel.

uri

The uri for this Channel.

Variables

@:flash.propertypiggybackingEnabled:Bool

Indicates whether this channel will piggyback poll requests along with regular outbound messages when an outstanding poll is not in progress. This allows the server to piggyback data for the client along with its response to client's message.

@:flash.propertyread onlypolling:Bool

Reports whether the channel is actively polling.

@:flash.propertypollingEnabled:Bool

Indicates whether this channel is enabled to poll.

@:flash.propertypollingInterval:Float

Provides access to the polling interval for this Channel. The value is in milliseconds. This value determines how often this Channel requests messages from the server, to approximate server push.

Throws:

ArgumentError

If the pollingInterval is assigned a value of 0 or less.

Methods

AppendToGatewayUrl(value:String):Void

Overriding to be able to keep track of the fact that the Channel is in the process of reconnecting with the session id, so the initial NetConnection call can be discarded properly in the resultHandler.

applySettings(settings:Xml):Void

Processes polling related configuration settings.

Inherited Variables

Defined by NetConnectionChannel

@:flash.propertyread onlynetConnection:AMFNetConnection

Provides access to the associated NetConnection for this Channel.

Defined by Channel

@:flash.propertyread onlyauthenticated:Bool

Indicates if this channel is authenticated.

@:flash.propertyread onlychannelSets:Array<ChannelSet>

Provides access to the ChannelSets connected to the Channel.

@:flash.propertyconnectTimeout:Int

Provides access to the connect timeout in seconds for the channel. A value of 0 or below indicates that a connect attempt will never be timed out on the client. For channels that are configured to failover, this value is the total time to wait for a connection to be established. It is not reset for each failover URI that the channel may attempt to connect to.

@:flash.propertyread onlyconnected:Bool

Indicates whether this channel has established a connection to the remote destination.

@:flash.propertyread onlyendpoint:String

Provides access to the endpoint for this channel. This value is calculated based on the value of the uri property.

@:flash.propertyfailoverURIs:Array<String>

Provides access to the set of endpoint URIs that this channel can attempt to failover to if the endpoint is clustered.

This property is automatically populated when clustering is enabled. If you don't use clustering, you can set your own values.

@:flash.propertyid:String

Provides access to the id of this channel.

@:flash.propertyread onlyprotocol:String

Provides access to the protocol that the channel uses. Note: Subclasses of Channel must override this method and return a string that represents their supported protocol. Examples of supported protocol strings are "rtmp", "http" or "https".

@:flash.propertyread onlyreconnecting:Bool

Indicates whether this channel is in the process of reconnecting to an alternate endpoint.

@:flash.propertyread onlyrecordMessageSizes:Bool

Channel property determines the level of performance information injection - whether we inject message sizes or not.

@:flash.propertyread onlyrecordMessageTimes:Bool

Channel property determines the level of performance information injection - whether we inject timestamps or not.

@:flash.propertyrequestTimeout:Int

Provides access to the default request timeout in seconds for the channel. A value of 0 or below indicates that outbound requests will never be timed out on the client.

Request timeouts are most useful for RPC style messaging that requires a response from the remote destination.

@:flash.propertyuri:String

Provides access to the URI used to create the whole endpoint URI for this channel. The URI can be a partial path, in which case the full endpoint URI is computed as necessary.

Inherited Methods

Defined by NetConnectionChannel

receive(msg:IMessage, rest:Rest<Dynamic>):Void

Called by the player when the server pushes a message. Dispatches a MessageEvent to any MessageAgents that are listening. Any ...rest args passed via RTMP are ignored.

Parameters:

msg

The message pushed from the server.

Defined by PollingChannel

disablePolling():Void

Disables polling based on the number of times enablePolling() and disablePolling() have been invoked. If the net result is to disable polling the channel stops polling.

Invoked automatically based upon subscribing or unsubscribing from a remote destination over a PollingChannel.

enablePolling():Void

Enables polling based on the number of times enablePolling() and disablePolling() have been invoked. If the net result is to enable polling the channel will poll the server on behalf of connected MessageAgents.

Invoked automatically based upon subscribing or unsubscribing from a remote destination over a PollingChannel.

poll():Void

Initiates a poll operation if there are consumers subscribed to this channel, and polling is enabled for this channel.

Note that this method will not start a new poll if one is currently in progress.

send(agent:MessageAgent, message:IMessage):Void

Sends the specified message to its target destination. Subclasses must override the internalSend() method to perform the actual send. PollingChannel will wrap outbound messages in poll requests if a poll is not currently outstanding.

Parameters:

agent

The MessageAgent that is sending the message.

message

The Message to send.

Throws:

mx.messaging.errors.InvalidDestinationError

If neither the MessageAgent nor the message specify a destination.

Defined by Channel

finalconnect(channelSet:ChannelSet):Void

Connects the ChannelSet to the Channel. If the Channel has not yet connected to its endpoint, it attempts to do so. Channel subclasses must override the internalConnect() method, and call the connectSuccess() method once the underlying connection is established.

Parameters:

channelSet

The ChannelSet to connect to the Channel.

finaldisconnect(channelSet:ChannelSet):Void

Disconnects the ChannelSet from the Channel. If the Channel is connected to its endpoint and it has no more connected ChannelSets it will internally disconnect.

Channel subclasses need to override the internalDisconnect() method, and call the disconnectSuccess() method when the underlying connection has been terminated.

Parameters:

channelSet

The ChannelSet to disconnect from the Channel.

logout(agent:MessageAgent):Void

Sends a CommandMessage to the server to logout if the Channel is connected. Current credentials are cleared.

Parameters:

agent

The MessageAgent to logout.

@:value({ charset : null, agent : null })setCredentials(credentials:String, ?agent:MessageAgent, ?charset:String):Void

Sets the credentials to the specified value. If the credentials are non-null and the Channel is connected, this method also sends a CommandMessage to the server to login using the credentials.

Parameters:

credentials

The credentials string.

agent

The MessageAgent to login, that will handle the login result.

charset

The character set encoding used while encoding the credentials. The default is null, which implies the legacy charset of ISO-Latin-1.

Throws:

flash.errors.IllegalOperationError

in two situations; if credentials have already been set and an authentication is in progress with the remote detination, or if authenticated and the credentials specified don't match the currently authenticated credentials.