Skip to content

Understanding JavaScript functions

jfarcand edited this page Apr 30, 2013 · 4 revisions

Functions definitions see for more information

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

  • onOpen:

    • atmosphere 1.0.x: For WebSocket and SSE, the onOpen will be called when the connection is fully established. For others transports like http-streaming, long-polling and jsonp, onOpen will be called 500 milliseconds after the connection has been sent to the server. When request.enableProtocol is set to true, onOpen will be called only when the connection is fully established.
    • atmosphere 1.1.x: 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 method will be called before the reconnect, with the fallbackTransport.

  • onReconnect:

    • atmosphere 1.0.x: Every time a reconnection happens. For long-polling, this method will be called everytime a response is received.
    • atmosphere 1.1.x: Everytime 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: Only in atmosphere-1.1.x, 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

Step by Step Tutorials

Concepts & Architecture

15 Minutes Tutorial

Advanced Topics

API

Known WebServer Issues

References

External Documentations

githalytics.com alpha

Clone this wiki locally