Class: Wamp::Client::Connection

Inherits:
Object
  • Object
show all
Includes:
Event
Defined in:
lib/wamp/client/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Event

included

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.

Parameters:

  • options (Hash)

    The different options to pass to the connection

Options Hash (options):

  • :uri (String)

    The uri of the WAMP router to connect to

  • :proxy (String)

    The proxy to get to the router

  • :realm (String)

    The realm to connect to

  • :protocol (String, nil)

    The protocol (default if wamp.2.json)

  • :authid (String, nil)

    The id to authenticate with

  • :authmethods (Array, nil)

    The different auth methods that the client supports

  • :headers (Hash)

    Custom headers to include during the connection

  • :serializer (WampClient::Serializer::Base)

    The serializer to use (default is json)



24
25
26
27
28
29
30
31
32
# File 'lib/wamp/client/connection.rb', line 24

def initialize(options)
  self.transport_class = options.delete(:transport) || Wamp::Client::Transport::WebSocketEventMachine
  self.options = options || {}

  @reconnect = true
  @open = false

  logger.info("#{self.class.name} using version #{Wamp::Client::VERSION}")
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/wamp/client/connection.rb', line 11

def options
  @options
end

#sessionObject

Returns the value of attribute session.



11
12
13
# File 'lib/wamp/client/connection.rb', line 11

def session
  @session
end

#transportObject

Returns the value of attribute transport.



11
12
13
# File 'lib/wamp/client/connection.rb', line 11

def transport
  @transport
end

#transport_classObject

Returns the value of attribute transport_class.



11
12
13
# File 'lib/wamp/client/connection.rb', line 11

def transport_class
  @transport_class
end

Instance Method Details

#closeObject

Closes the connection

Raises:

  • (RuntimeError)


51
52
53
54
55
56
57
58
59
60
# File 'lib/wamp/client/connection.rb', line 51

def close

  raise RuntimeError, 'connection is already closed' unless self.is_open?

  # Leave the session
  @reconnect = false
  @retrying = false
  session.leave

end

#is_open?Boolean

Returns true if the connection is open

Returns:

  • (Boolean)


64
65
66
# File 'lib/wamp/client/connection.rb', line 64

def is_open?
  @open
end

#openObject

Opens the connection

Raises:

  • (RuntimeError)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/wamp/client/connection.rb', line 35

def open

  raise RuntimeError, 'connection is already open' if self.is_open?

  @reconnect = true
  @retry_timer = 1
  @retrying = false

  self.transport_class.start_event_machine do
    # Create the transport
    create_transport
  end

end