Sha256: f7268b9a24408f031957316675f267e271ba669427ccd8d2f430f0b64eb5a5d8

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

module Faye::WebSocket::API

  class Event
    attr_reader   :type, :bubbles, :cancelable
    attr_accessor :target, :current_target, :event_phase

    CAPTURING_PHASE = 1
    AT_TARGET       = 2
    BUBBLING_PHASE  = 3

    def initialize(event_type, options)
      @type = event_type
      options.each { |key, value| instance_variable_set("@#{ key }", value) }
    end

    def init_event(event_type, can_bubble, cancelable)
      @type       = event_type
      @bubbles    = can_bubble
      @cancelable = cancelable
    end

    def stop_propagation
    end

    def prevent_default
    end
  end

  class OpenEvent < Event
  end

  class MessageEvent < Event
    attr_reader :data
  end

  class CloseEvent < Event
    attr_reader :code, :reason
  end

  class ErrorEvent < Event
    attr_reader :message
  end

  TYPES = {
    'open'    => OpenEvent,
    'message' => MessageEvent,
    'close'   => CloseEvent,
    'error'   => ErrorEvent
  }

  def Event.create(type, options = {})
    TYPES[type].new(type, options)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
faye-websocket-0.11.3 lib/faye/websocket/api/event.rb
faye-websocket-0.11.2 lib/faye/websocket/api/event.rb
faye-websocket-0.11.1 lib/faye/websocket/api/event.rb
faye-websocket-0.11.0 lib/faye/websocket/api/event.rb
faye-websocket-0.10.9 lib/faye/websocket/api/event.rb