Understanding JavaScript functions - Atmosphere/atmosphere GitHub Wiki

Functions definitions see for more information

When using the jQuery.atmosphere.js or atmosphere.js Javascript client, you have several functions you can set in order to get notified when events occurs:

  • onOpen:

    • onOpen will be called for all transports when the connection is fully established.
  • onClose: The onClose is called when:

    1. an error occurs.
    2. when the server or a proxy closes the connection.
    3. when an expected exception occurs.
    4. when the specified transport is not supported or fail to connect.
  • onMessage: Everytime a new message is received

  • onError: The onError is called when:

    1. the request.maxReconnectOnClose re-connect try has failed
    2. an unexpected error occured.
  • onTransportFailure: if the specified transport fails to connect, this function will be called before the reconnect, with the fallbackTransport.

  • onClientTimeout: if the request.timeout expires, this function will be called, allowing an application to reconnect if needed.

  • onReconnect:

    • Every time an error happens and a reconnect needs to happens. This works for all transport, e.g for long-polling, onReconnect will only be called if an error happens and never before reconnecting.
  • onReopen: this function is called every time a re-connection successfully reconnected.

  • onMessagePublished: Except for websockets, the onMessagePublished will be invoked when a POST is made and the server side is sending a response using the 'polling' connection.

Possible workflow

onOpen -> onMessage -> onClose // Normal

onTransportFailure -> onOpen -> onMessage -> onClose // transport not supported

onOpen -> onMessage -> [connection closed] -> onReconnect -> onClose -> onError // maxReconnectOnClose

onOpen -> onMessage -> [connection closed] -> onReconnect -> onMessage

onOpen -> [request.timeout expires] -> onClientTimeout