Class: WAMP::Server

Inherits:
Object
  • Object
show all
Includes:
Bindable
Defined in:
lib/wamp/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Bindable

#bind, #trigger

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



10
11
12
13
14
15
16
17
18
19
# File 'lib/wamp/server.rb', line 10

def initialize(options = {})
  @options   = options
  @options[:engine] ||= {}
  @options[:engine][:type] ||= :memory

  @topics    = {}
  @callbacks = {}
  @engine    = WAMP::Engines.const_get(camelize(@options[:engine][:type])).new(@options[:engine])
  @protocol  = WAMP::Protocols::Version1.new
end

Instance Attribute Details

#callbacksObject

Returns the value of attribute callbacks.



8
9
10
# File 'lib/wamp/server.rb', line 8

def callbacks
  @callbacks
end

#engineObject

Returns the value of attribute engine.



8
9
10
# File 'lib/wamp/server.rb', line 8

def engine
  @engine
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/wamp/server.rb', line 8

def options
  @options
end

#topicsObject

Returns the value of attribute topics.



8
9
10
# File 'lib/wamp/server.rb', line 8

def topics
  @topics
end

Instance Method Details

#available_bindingsObject



21
22
23
# File 'lib/wamp/server.rb', line 21

def available_bindings
  [:subscribe, :unsubscribe, :publish, :call, :prefix, :connect, :disconnect]
end

#startObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wamp/server.rb', line 25

def start
  lambda do |env|
    Faye::WebSocket.load_adapter('thin')
    if Faye::WebSocket.websocket?(env)
      ws = Faye::WebSocket.new(env, ['wamp'], ping: 25)

      ws.onopen    = lambda { |event| handle_open(ws, event) }
      ws.onmessage = lambda { |event| handle_message(ws, event) }
      ws.onclose   = lambda { |event| handle_close(ws, event) }

      ws.rack_response
    else
      # Normal HTTP request
      [200, {'Content-Type' => 'text/plain'}, ['Hello']]
    end
  end
end