Class: Wamp::Client::Manager::Establish

Inherits:
Base
  • Object
show all
Defined in:
lib/wamp/client/manager/establish.rb

Constant Summary collapse

WAMP_FEATURES =
{
    caller: {
        features: {
            caller_identification: true,
            call_timeout: true,
            call_canceling: true,
            progressive_call_results: true
        }
    },
    callee: {
        features: {
            caller_identification: true,
            ##call_trustlevels: true,
            pattern_based_registration: true,
            shared_registration: true,
            ##call_timeout: true,
            call_canceling: true,
            progressive_call_results: true,
            registration_revocation: true
        }
    },
    publisher: {
        features: {
            publisher_identification: true,
            subscriber_blackwhite_listing: true,
            publisher_exclusion: true
        }
    },
    subscriber: {
        features: {
            publisher_identification: true,
            ##publication_trustlevels: true,
            pattern_based_subscription: true,
            subscription_revocation: true
            ##event_history: true,
        }
    }
}

Instance Attribute Summary collapse

Attributes inherited from Base

#send_message_callback, #session

Instance Method Summary collapse

Constructor Details

#initialize(session, send_message) ⇒ Establish

Constructor



51
52
53
54
55
56
57
# File 'lib/wamp/client/manager/establish.rb', line 51

def initialize(session, send_message)
  super session, send_message

  self.id = nil
  self.realm = nil
  self.goodbye_sent = false
end

Instance Attribute Details

#goodbye_sentObject

Returns the value of attribute goodbye_sent.



8
9
10
# File 'lib/wamp/client/manager/establish.rb', line 8

def goodbye_sent
  @goodbye_sent
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/wamp/client/manager/establish.rb', line 8

def id
  @id
end

#realmObject

Returns the value of attribute realm.



8
9
10
# File 'lib/wamp/client/manager/establish.rb', line 8

def realm
  @realm
end

Instance Method Details

#abort(message) ⇒ Object

Handles an abort message



156
157
158
159
160
161
162
# File 'lib/wamp/client/manager/establish.rb', line 156

def abort(message)
  # Log leaving the session
  logger.info("#{self.session.class.name} left session '#{message.reason}'")

  # Trigger the leave event
  trigger :leave, message.reason, message.details
end

#challenge(message) ⇒ Object

Handles a challenge message



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/wamp/client/manager/establish.rb', line 136

def challenge(message)
  # Log challenge received
  logger.debug("#{self.session.class.name} auth challenge '#{message.authmethod}', extra: #{message.extra}")

  # Call the callback if set
  signature, extra = trigger :challenge, message.authmethod, message.extra

  # Set with initial values
  signature ||= ''
  extra ||= {}

  # Create the message
  authenticate = Message::Authenticate.new(signature, extra)

  # Send it
  send_message(authenticate)
end

#goodbye(message) ⇒ Object

Handles the goodbye message



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/wamp/client/manager/establish.rb', line 105

def goodbye(message)
  # If we didn't send the goodbye, respond
  unless self.goodbye_sent
    goodbye = Message::Goodbye.new({}, 'wamp.error.goodbye_and_out')
    send_message(goodbye)
  end

  # Close out session
  self.id = nil
  self.realm = nil
  self.goodbye_sent = false

  # Trigger leave event
  trigger :leave, message.reason, message.details
end

#is_open?Boolean

Returns true if the session is open

Returns:

  • (Boolean)


61
62
63
# File 'lib/wamp/client/manager/establish.rb', line 61

def is_open?
  self.id != nil
end

#join(realm) ⇒ Object

Will attempt to join a router



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/wamp/client/manager/establish.rb', line 67

def join(realm)

  # Set the realm
  self.realm = realm

  # Create the details
  details = {}
  details[:roles] = WAMP_FEATURES
  details[:agent] = "Ruby-Wamp::Client-#{VERSION}"
  details[:authid] = self.session.options[:authid] if self.session.options[:authid]
  details[:authmethods] = self.session.options[:authmethods] if self.session.options[:authmethods]

  # Create the message
  hello = Message::Hello.new(realm, details)

  # Send it
  send_message(hello)
end

#leave(reason, message) ⇒ Object

Leave the session



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/wamp/client/manager/establish.rb', line 87

def leave(reason, message)

  # Create the details
  details = {}
  details[:message] = message

  # Create the goobdbye message
  goodbye = Message::Goodbye.new(details, reason)

  # Send it
  send_message(goodbye)

  # Send it
  self.goodbye_sent = true
end

#welcome(message) ⇒ Object

Handles the welcome message



123
124
125
126
127
128
129
130
131
132
# File 'lib/wamp/client/manager/establish.rb', line 123

def welcome(message)
  # Get the session ID
  self.id = message.session

  # Log the message
  logger.info("#{self.session.class.name} joined session with realm '#{message.details[:realm]}'")

  # Trigger join event
  trigger :join, message.details
end