Sha256: 4ef04ab69b0a5be1c645c2e377961a9cfdadfd4b6b3fa7c3678dc58272019618

Contents?: true

Size: 747 Bytes

Versions: 3

Compression:

Stored size: 747 Bytes

Contents

class FayeWebSocketClientStub
  class Event
    attr_accessor :data, :reason
  end

  attr_accessor :last_message

  def initialize
    EM.add_timer(1) {
      @on_open.call(Event.new) if @on_open != nil
    }
  end

  @on_open
  @on_message
  @on_close
  def on(event, &block)
    if event == :open
      @on_open = block
    elsif event == :close
      @on_close = block
    elsif event == :message
      @on_message = block
    end
  end

  def close
    event = Event.new
    event.reason = 'closed'
    @on_close.call(event) if @on_close != nil
  end

  def send(message)
    self.last_message = message
  end

  def receive(message)
    event = Event.new
    event.data = message
    @on_message.call(event) if @on_message != nil
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wamp_client-0.2.2 spec/support/faye_web_socket_client_stub.rb
wamp_client-0.2.1 spec/support/faye_web_socket_client_stub.rb
wamp_client-0.2.0 spec/support/faye_web_socket_client_stub.rb