Sha256: e88b1752c37a15287d5978658c58a06ca8dbb2a2efd44b02762ccf74ca07a2ee

Contents?: true

Size: 818 Bytes

Versions: 3

Compression:

Stored size: 818 Bytes

Contents

###
WebSocket Interface for the WebSocketRails client.
###
class WebSocketRails.WebSocketConnection

  constructor: (@url,@dispatcher) ->
    @url             = "ws://#{@url}" unless @url.match(/^wss?:\/\//)
    @message_queue   = []
    @_conn           = new WebSocket(@url)
    @_conn.onmessage = @on_message
    @_conn.onclose   = @on_close

  trigger: (event) =>
    if @dispatcher.state != 'connected'
      @message_queue.push event
    else
      @_conn.send event.serialize()

  on_message: (event) =>
    data = JSON.parse event.data
    @dispatcher.new_message data

  on_close: (event) =>
    close_event = new WebSocketRails.Event(['connection_closed',{}])
    @dispatcher.dispatch close_event

  flush_queue: =>
    for event in @message_queue
      @_conn.send event.serialize()
    @message_queue = []

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
websocket-rails-0.1.8 lib/assets/javascripts/websocket_rails/websocket_connection.js.coffee
websocket-rails-0.1.7 lib/assets/javascripts/websocket_rails/websocket_connection.js.coffee
websocket-rails-0.1.6 lib/assets/javascripts/websocket_rails/websocket_connection.js.coffee