Sha256: 611d0f2679a68314b1e86d9a03d5c66d1f13abf6fea0b871871aea0a10fba4cd

Contents?: true

Size: 995 Bytes

Versions: 4

Compression:

Stored size: 995 Bytes

Contents

###
The Event object stores all the relevant event information.
###

class WebSocketRails.Event

  constructor: (data, @success_callback, @failure_callback) ->
    @name    = data[0]
    attr     = data[1]
    if attr?
      @id      = if attr['id']? then attr['id'] else (((1+Math.random())*0x10000)|0)
      @channel = if attr.channel? then attr.channel
      @data    = if attr.data? then attr.data else attr
      @token   = if attr.token? then attr.token
      @connection_id = data[2]
      if attr.success?
        @result  = true
        @success = attr.success

  is_channel: ->
    @channel?

  is_result: ->
    typeof @result != 'undefined'

  is_ping: ->
    @name == 'websocket_rails.ping'

  serialize: ->
      JSON.stringify [@name, @attributes()]

  attributes: ->
    id: @id,
    channel: @channel,
    data: @data
    token: @token

  run_callbacks: (@success, @result) ->
    if @success == true
      @success_callback?(@result)
    else
      @failure_callback?(@result)

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
hkroger-websocket-rails-0.7.1 lib/assets/javascripts/websocket_rails/event.js.coffee
dial_a_device_node-0.0.154 app/assets/javascripts/dial_a_device_node/websocket_rails/event.js.coffee
dial_a_device_node-0.0.153 app/assets/javascripts/dial_a_device_node/websocket_rails/event.js.coffee
websocket-rails-0.7.0 lib/assets/javascripts/websocket_rails/event.js.coffee