WebSocket realtime support

See also Swazoo WebSocket support with WebSocket workflow example, further read, link to protocol RFC etc.

Introduction

If enabled and browser supports it, a WebSocket realtime channel is open from the browser to the current session for each currently open web page. Now all communication will flow through this channel instead by Ajax. And because it is bidirectional it can flow from server to browser in any time, not just in response to some Ajax request. This makes web app realtime, because it can immediately react on some server event by refreshing portions of web page on browser.

Usage

Realtime (WebSocket) support can be enabled for entire site or just for selected pages:

(AIDASite named: 'aidademo') webSocketEnabled: true. "enables realtime support for entire site"

or:

MyApp>>viewSomething
...
self page enableRealtime.  "enables realtime support on for this view"
...

Implementation

Prerequisites

  • Swazoo 2.3+ web server with WebSocket support

New classes

  • WebRealtimeHandler handles all realtime (WebSocket and Comet) channels to browser on that session
  • WebRealtimeConnection  holds information about browser connection to send commands in realtime. It can be WebSocket or long-polling Comet (not yet finished, do we need it anymore?)

Modified classes

  • WebPage
    • enableRealtime
    • addWebSocketLoadScript "in page's onLoad event"
  • WebStlye
    • js141WebSocket "JavaScript for WebSockets - opening it, receiving messages etc."
  • WebSession
    • realtimeHandler "to handle realtime (WebSocket and Comet) channels on that session"
    • queueCommand:, notifyQueueAddition "will try to send commands over realtime channel if open"
    • aidaPresenterFor:on: "responds to websocket opening request on /aidasession/websocket"
    • streamHtmlTo:for:on: "same, actually upgrading connection to WebSocket one"