Class: WAMP::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/wamp/socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, websocket) ⇒ Socket

Returns a new instance of Socket.



7
8
9
10
11
12
13
14
# File 'lib/wamp/socket.rb', line 7

def initialize(id, websocket)
  @id        = id
  @topics    = []
  @prefixes  = {}
  @websocket = websocket

  send_welcome_message
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/wamp/socket.rb', line 5

def id
  @id
end

#prefixesObject

Returns the value of attribute prefixes.



5
6
7
# File 'lib/wamp/socket.rb', line 5

def prefixes
  @prefixes
end

#topicsObject

Returns the value of attribute topics.



5
6
7
# File 'lib/wamp/socket.rb', line 5

def topics
  @topics
end

#websocketObject

Returns the value of attribute websocket.



5
6
7
# File 'lib/wamp/socket.rb', line 5

def websocket
  @websocket
end

Instance Method Details

#add_prefix(prefix, uri) ⇒ Object



24
25
26
# File 'lib/wamp/socket.rb', line 24

def add_prefix(prefix, uri)
  prefixes[prefix] = uri
end

#add_topic(topic) ⇒ Object



16
17
18
# File 'lib/wamp/socket.rb', line 16

def add_topic(topic)
  topics << topic unless topics.include? topic
end

#remove_topic(topic) ⇒ Object



20
21
22
# File 'lib/wamp/socket.rb', line 20

def remove_topic(topic)
  topics.delete(topic)
end

#to_jsonObject



28
29
30
31
32
33
34
# File 'lib/wamp/socket.rb', line 28

def to_json
  {
    id:       id,
    topics:   topics,
    prefixes: prefixes
  }.to_json
end