Class: Discordrb::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/gateway.rb

Overview

This class stores the data of an active gateway session. Note that this is different from a websocket connection - there may be multiple sessions per connection or one session may persist over multiple connections.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_id) ⇒ Session

Returns a new instance of Session.


98
99
100
101
102
103
# File 'lib/discordrb/gateway.rb', line 98

def initialize(session_id)
  @session_id = session_id
  @sequence = 0
  @suspended = false
  @invalid = false
end

Instance Attribute Details

#sequenceObject

Returns the value of attribute sequence


96
97
98
# File 'lib/discordrb/gateway.rb', line 96

def sequence
  @sequence
end

#session_idObject (readonly)

Returns the value of attribute session_id


95
96
97
# File 'lib/discordrb/gateway.rb', line 95

def session_id
  @session_id
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)

124
125
126
# File 'lib/discordrb/gateway.rb', line 124

def invalid?
  @invalid
end

#invalidateObject

Flags this session as being invalid


120
121
122
# File 'lib/discordrb/gateway.rb', line 120

def invalidate
  @invalid = true
end

#resumeObject

Flags this session as no longer being suspended, so we can resume


115
116
117
# File 'lib/discordrb/gateway.rb', line 115

def resume
  @suspended = false
end

#should_resume?Boolean

Returns:

  • (Boolean)

128
129
130
# File 'lib/discordrb/gateway.rb', line 128

def should_resume?
  suspended? && !invalid?
end

#suspendObject

Flags this session as suspended, so we know not to try and send heartbeats, etc. to the gateway until we've reconnected


106
107
108
# File 'lib/discordrb/gateway.rb', line 106

def suspend
  @suspended = true
end

#suspended?Boolean

Returns:

  • (Boolean)

110
111
112
# File 'lib/discordrb/gateway.rb', line 110

def suspended?
  @suspended
end