Class: Wamp::Router::Client

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

Overview

Server Session

Direct Known Subclasses

Connection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serializer = Wampproto::Serializer::JSON, authenticator = Authenticator) ⇒ Client

Returns a new instance of Client.



19
20
21
22
# File 'lib/wamp/router/client.rb', line 19

def initialize(serializer = Wampproto::Serializer::JSON, authenticator = Authenticator)
  @serializer = serializer
  @acceptor = Wampproto::Acceptor.new(serializer, authenticator)
end

Instance Attribute Details

#acceptorObject (readonly)

Returns the value of attribute acceptor.



17
18
19
# File 'lib/wamp/router/client.rb', line 17

def acceptor
  @acceptor
end

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

#routerObject

Returns the value of attribute router.



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

def router
  @router
end

#serializerObject (readonly)

Returns the value of attribute serializer.



17
18
19
# File 'lib/wamp/router/client.rb', line 17

def serializer
  @serializer
end

Instance Method Details

#on_message(data) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/wamp/router/client.rb', line 45

def on_message(data)
  unless acceptor.accepted?
    msg, is_welcome = acceptor.receive(data)
    transmit msg
    router.attach_client(self) if is_welcome
  end
  router.receive_message(self, serializer.deserialize(data))
end

#realmObject



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

def realm
  acceptor.session_details&.realm
end

#send_message(message) ⇒ Object



28
29
30
# File 'lib/wamp/router/client.rb', line 28

def send_message(message)
  transmit(message)
end

#session_idObject



32
33
34
# File 'lib/wamp/router/client.rb', line 32

def session_id
  acceptor.session_details&.session_id
end

#transmit(data) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/wamp/router/client.rb', line 36

def transmit(data)
  case data
  when Wampproto::Message::Base
    connection.on_message serializer.serialize(data)
  else
    connection.on_message data
  end
end