Class: WampClient::Transport::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/wamp_client/transport.rb

Direct Known Subclasses

WebSocketTransport

Instance Attribute Summary collapse

Instance Method Summary collapse

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

  • :protocol (String)

    The protocol

  • :headers (Hash)

    Custom headers to include during the connection

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

    The serializer to use



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/wamp_client/transport.rb', line 68

def initialize(options)

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

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

  # Initialize callbacks
  @on_open = nil
  @on_close = nil
  @on_message = nil
  @on_error = nil

end

Instance Attribute Details

#connectedObject

Returns the value of attribute connected.



60
61
62
# File 'lib/wamp_client/transport.rb', line 60

def connected
  @connected
end

#headersObject

Returns the value of attribute headers.



60
61
62
# File 'lib/wamp_client/transport.rb', line 60

def headers
  @headers
end

#protocolObject

Returns the value of attribute protocol.



60
61
62
# File 'lib/wamp_client/transport.rb', line 60

def protocol
  @protocol
end

#serializerObject

Returns the value of attribute serializer.



60
61
62
# File 'lib/wamp_client/transport.rb', line 60

def serializer
  @serializer
end

#typeObject

Returns the value of attribute type.



60
61
62
# File 'lib/wamp_client/transport.rb', line 60

def type
  @type
end

#uriObject

Returns the value of attribute uri.



60
61
62
# File 'lib/wamp_client/transport.rb', line 60

def uri
  @uri
end

Instance Method Details

#connectObject

Connects to the WAMP Server using the transport



89
90
91
# File 'lib/wamp_client/transport.rb', line 89

def connect
  # Implement in subclass
end

#connected?Boolean

Returns true if the transport it connected

Returns:

  • (Boolean)


99
100
101
# File 'lib/wamp_client/transport.rb', line 99

def connected?
  self.connected
end

#disconnectObject

Disconnects from the WAMP Server



94
95
96
# File 'lib/wamp_client/transport.rb', line 94

def disconnect
  # Implement in subclass
end

#on_close(&on_close) ⇒ Object



43
44
45
# File 'lib/wamp_client/transport.rb', line 43

def on_close(&on_close)
  @on_close = on_close
end

#on_error(&on_error) ⇒ Object



56
57
58
# File 'lib/wamp_client/transport.rb', line 56

def on_error(&on_error)
  @on_error = on_error
end

#on_message(&on_message) ⇒ Object



50
51
52
# File 'lib/wamp_client/transport.rb', line 50

def on_message(&on_message)
  @on_message = on_message
end

#on_open(&on_open) ⇒ Object



36
37
38
# File 'lib/wamp_client/transport.rb', line 36

def on_open(&on_open)
  @on_open = on_open
end

#send_message(msg) ⇒ Object

Sends a Message

Parameters:

  • msg (Array)
    • The message payload to send



105
106
107
# File 'lib/wamp_client/transport.rb', line 105

def send_message(msg)
  # Implement in subclass
end