State changes that occur when using PushChannel are handled by creating a class that implements this protocol. The callback for handling received Push Channel notifications is also part of this protocol.
The following code snippets illustrate some common tasks.
The above snippet shows a simple onChannelOpen
handler. The following takes place when the Push Channel is opened:
sendPushToken
method is calledThe sendPushToken
method, which would be written by the application developer, would send the token to the application server. This could use a socket, an HTTP request, or another means of communication. From the Push Channel point of view, this is an out-of-band communication.
The server will use the token to address Push Channel notification messages back to the application. These would be received by the application's onChannelMessage handler.
The above snippet shows a simple onChannelMessage
handler.
The handler logs the received data to the system monitor, then calls the application processPush
method. The "payload" of the notification is passed as a parameter to the processPush
method.
The processPush
method, which would be written by the application developer, could initiate any of the following actions:
The above snippet shows a simple onChannelClose
handler. The following takes place when the Push Channel is closed:
discardPushToken
method is called. The token of the closed channel is passed as a parameter.The discardPushToken
method would delete the application's copy of the token, possibly after checking that it matches the whichWas
parameter. The method could also initiate connection of a new Push Channel, which would have a new token. See connect .
The above snippet shows a simple onChannelError
handler.
The handler logs the error code to the system monitor, flags the channel's state as not connected, records the error code in the application, then calls the application discardPushToken
method.
The discardPushToken
method could do any of the following:
The above snippet shows a simple onChannelPingFail
handler.
The handler logs the error code to the system monitor, then calls the application resendPushToken
method if the token was lost.
The resendPushToken
method, which would be written by the application developer, would send the application's stored token to the application server. This could use a socket, an HTTP request, or another means of communication. From the Push Channel point of view, this is an out-of-band communication.
The resendPushToken
method should expect that the server is not immediately available, perhaps employing a retry policy.