Class: Wamp::Client::Transport::Base

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

Direct Known Subclasses

EventMachineBase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Event

included

Constructor Details

#initialize(options) ⇒ Base

Constructor for the transport

Parameters:

  • options (Hash)

    The connection options. the different options are as follows

Options Hash (options):

  • :uri (String)

    The url to connect to

  • :proxy (String)

    The proxy to use

  • :protocol (String)

    The protocol

  • :headers (Hash)

    Custom headers to include during the connection

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

    The serializer to use



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wamp/client/transport/base.rb', line 21

def initialize(options)

  # Initialize the parameters
  self.connected = false
  self.uri = options[:uri]
  self.proxy = options[:proxy]
  self.headers = options[:headers] || {}
  self.protocol = options[:protocol] || 'wamp.2.json'
  self.serializer = options[:serializer] || Wamp::Client::Serializer::JSONSerializer.new

  # Add the wamp.2.json protocol header
  self.headers['Sec-WebSocket-Protocol'] = self.protocol
end

Instance Attribute Details

#connectedObject

Returns the value of attribute connected.



10
11
12
# File 'lib/wamp/client/transport/base.rb', line 10

def connected
  @connected
end

#headersObject

Returns the value of attribute headers.



10
11
12
# File 'lib/wamp/client/transport/base.rb', line 10

def headers
  @headers
end

#protocolObject

Returns the value of attribute protocol.



10
11
12
# File 'lib/wamp/client/transport/base.rb', line 10

def protocol
  @protocol
end

#proxyObject

Returns the value of attribute proxy.



10
11
12
# File 'lib/wamp/client/transport/base.rb', line 10

def proxy
  @proxy
end

#serializerObject

Returns the value of attribute serializer.



10
11
12
# File 'lib/wamp/client/transport/base.rb', line 10

def serializer
  @serializer
end

#uriObject

Returns the value of attribute uri.



10
11
12
# File 'lib/wamp/client/transport/base.rb', line 10

def uri
  @uri
end

Class Method Details

.add_tick_loop(&block) ⇒ Object

Method to add a tick loop to the event machine



77
78
79
# File 'lib/wamp/client/transport/base.rb', line 77

def self.add_tick_loop(&block)
  # Implement in subclass
end

.add_timer(milliseconds, &callback) ⇒ Object

Process the callback when the timer expires

Parameters:

  • milliseconds (Integer)
    • The number

  • callback (block)
    • The callback that is fired when the timer expires



59
60
61
# File 'lib/wamp/client/transport/base.rb', line 59

def self.add_timer(milliseconds, &callback)
  # Implement in subclass
end

.start_event_machine(&block) ⇒ Object

Method to start the event machine for the socket



67
68
69
# File 'lib/wamp/client/transport/base.rb', line 67

def self.start_event_machine(&block)
  # Implement in subclass
end

.stop_event_machineObject

Method to stop the vent machine



72
73
74
# File 'lib/wamp/client/transport/base.rb', line 72

def self.stop_event_machine
  # Implement in subclass
end

Instance Method Details

#add_timer(milliseconds, &callback) ⇒ Object

Implement in subclass



62
63
64
# File 'lib/wamp/client/transport/base.rb', line 62

def add_timer(milliseconds, &callback)
  self.class.add_timer(milliseconds, &callback)
end

#connectObject

Connects to the WAMP Server using the transport



36
37
38
# File 'lib/wamp/client/transport/base.rb', line 36

def connect
  # Implement in subclass
end

#connected?Boolean

Returns true if the transport it connected

Returns:

  • (Boolean)


46
47
48
# File 'lib/wamp/client/transport/base.rb', line 46

def connected?
  self.connected
end

#disconnectObject

Disconnects from the WAMP Server



41
42
43
# File 'lib/wamp/client/transport/base.rb', line 41

def disconnect
  # Implement in subclass
end

#send_message(msg) ⇒ Object

Sends a Message

Parameters:

  • msg (Array)
    • The message payload to send



52
53
54
# File 'lib/wamp/client/transport/base.rb', line 52

def send_message(msg)
  # Implement in subclass
end