Class: Vines::Stream::Client::Session
- Inherits:
-
Object
- Object
- Vines::Stream::Client::Session
- Includes:
- Comparable
- Defined in:
- lib/vines/stream/client/session.rb
Overview
A Session tracks the state of a client stream over its lifetime from negotiation to processing stanzas to shutdown. By disconnecting the stream’s state from the stream, we can allow multiple TCP connections to access one logical session (e.g. HTTP streams).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_broadcast_presence ⇒ Object
Returns the value of attribute last_broadcast_presence.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #<=>(session) ⇒ Object
- #advance(state) ⇒ Object
-
#authenticated? ⇒ Boolean
Returns true if this client has properly authenticated with the server.
- #available! ⇒ Object
-
#available? ⇒ Boolean
An available resource has sent initial presence and can receive presence subscription requests.
-
#available_subscribed_to_resources ⇒ Object
Returns streams for available resources to which this user has successfully subscribed.
-
#available_subscribers ⇒ Object
Returns streams for available resources that are subscribed to this user’s presence updates.
-
#connected? ⇒ Boolean
A connected resource has authenticated and bound a resource identifier.
- #hash ⇒ Object
-
#initialize(stream) ⇒ Session
constructor
A new instance of Session.
-
#interested? ⇒ Boolean
An interested resource has requested its roster and can receive roster pushes.
- #ready? ⇒ Boolean
-
#remote_subscribers(to = nil) ⇒ Object
Returns contacts hosted at remote servers that are subscribed to this user’s presence updates.
- #requested_roster! ⇒ Object
- #stream_type ⇒ Object
-
#unbind!(stream) ⇒ Object
Called by the stream when its disconnected from the client.
Constructor Details
#initialize(stream) ⇒ Session
Returns a new instance of Session.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vines/stream/client/session.rb', line 16 def initialize(stream) @id = Kit.uuid @state = Client::Start.new(stream) @available = false @domain = nil @last_broadcast_presence = nil @requested_roster = false @unbound = false @user = nil end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
13 14 15 |
# File 'lib/vines/stream/client/session.rb', line 13 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/vines/stream/client/session.rb', line 14 def id @id end |
#last_broadcast_presence ⇒ Object
Returns the value of attribute last_broadcast_presence.
13 14 15 |
# File 'lib/vines/stream/client/session.rb', line 13 def last_broadcast_presence @last_broadcast_presence end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
14 15 16 |
# File 'lib/vines/stream/client/session.rb', line 14 def state @state end |
#user ⇒ Object
Returns the value of attribute user.
13 14 15 |
# File 'lib/vines/stream/client/session.rb', line 13 def user @user end |
Instance Method Details
#<=>(session) ⇒ Object
27 28 29 |
# File 'lib/vines/stream/client/session.rb', line 27 def <=>(session) session.is_a?(Session) ? self.id <=> session.id : nil end |
#advance(state) ⇒ Object
37 38 39 |
# File 'lib/vines/stream/client/session.rb', line 37 def advance(state) @state = state end |
#authenticated? ⇒ Boolean
Returns true if this client has properly authenticated with the server.
43 44 45 |
# File 'lib/vines/stream/client/session.rb', line 43 def authenticated? !@user.nil? end |
#available! ⇒ Object
47 48 49 |
# File 'lib/vines/stream/client/session.rb', line 47 def available! @available = true end |
#available? ⇒ Boolean
An available resource has sent initial presence and can receive presence subscription requests.
53 54 55 |
# File 'lib/vines/stream/client/session.rb', line 53 def available? @available && connected? end |
#available_subscribed_to_resources ⇒ Object
Returns streams for available resources to which this user has successfully subscribed.
92 93 94 95 |
# File 'lib/vines/stream/client/session.rb', line 92 def available_subscribed_to_resources subscribed = @user.subscribed_to_contacts.map {|c| c.jid } router.available_resources(subscribed) end |
#available_subscribers ⇒ Object
Returns streams for available resources that are subscribed to this user’s presence updates.
99 100 101 102 |
# File 'lib/vines/stream/client/session.rb', line 99 def available_subscribers subscribed = @user.subscribed_from_contacts.map {|c| c.jid } router.available_resources(subscribed) end |
#connected? ⇒ Boolean
A connected resource has authenticated and bound a resource identifier.
59 60 61 |
# File 'lib/vines/stream/client/session.rb', line 59 def connected? !@unbound && authenticated? && !@user.jid. end |
#hash ⇒ Object
33 34 35 |
# File 'lib/vines/stream/client/session.rb', line 33 def hash @id.hash end |
#interested? ⇒ Boolean
An interested resource has requested its roster and can receive roster pushes.
65 66 67 |
# File 'lib/vines/stream/client/session.rb', line 65 def interested? @requested_roster && connected? end |
#ready? ⇒ Boolean
69 70 71 |
# File 'lib/vines/stream/client/session.rb', line 69 def ready? @state.class == Client::Ready end |
#remote_subscribers(to = nil) ⇒ Object
Returns contacts hosted at remote servers that are subscribed to this user’s presence updates.
106 107 108 109 110 111 |
# File 'lib/vines/stream/client/session.rb', line 106 def remote_subscribers(to=nil) jid = (to.nil? || to.empty?) ? nil : JID.new(to). @user.subscribed_from_contacts.reject do |c| router.local_jid?(c.jid) || (jid && c.jid. != jid) end end |
#requested_roster! ⇒ Object
73 74 75 |
# File 'lib/vines/stream/client/session.rb', line 73 def requested_roster! @requested_roster = true end |
#stream_type ⇒ Object
77 78 79 |
# File 'lib/vines/stream/client/session.rb', line 77 def stream_type :client end |
#unbind!(stream) ⇒ Object
Called by the stream when its disconnected from the client. The stream passes itself to this method in case multiple streams are accessing this session.
84 85 86 87 88 |
# File 'lib/vines/stream/client/session.rb', line 84 def unbind!(stream) @unbound = true @available = false broadcast_unavailable end |