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.


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

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


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

def sequence
  @sequence
end

#session_idObject (readonly)

Returns the value of attribute session_id


93
94
95
# File 'lib/discordrb/gateway.rb', line 93

def session_id
  @session_id
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)

122
123
124
# File 'lib/discordrb/gateway.rb', line 122

def invalid?
  @invalid
end

#invalidateObject

Flags this session as being invalid


118
119
120
# File 'lib/discordrb/gateway.rb', line 118

def invalidate
  @invalid = true
end

#resumeObject

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


113
114
115
# File 'lib/discordrb/gateway.rb', line 113

def resume
  @suspended = false
end

#should_resume?Boolean

Returns:

  • (Boolean)

126
127
128
# File 'lib/discordrb/gateway.rb', line 126

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


104
105
106
# File 'lib/discordrb/gateway.rb', line 104

def suspend
  @suspended = true
end

#suspended?Boolean

Returns:

  • (Boolean)

108
109
110
# File 'lib/discordrb/gateway.rb', line 108

def suspended?
  @suspended
end