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

Instance Attribute Details

#resume_gateway_urlString (readonly)

Returns Gateway URL used to reconnect to the gateway node that Discord wants this session to use.

Returns:

  • (String)

    Gateway URL used to reconnect to the gateway node that Discord wants this session to use.



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

def resume_gateway_url
  @resume_gateway_url
end

#sequenceInteger

Returns Incrementing integer used to determine the most recent event reccived from Discord.

Returns:

  • (Integer)

    Incrementing integer used to determine the most recent event reccived from Discord.



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

def sequence
  @sequence
end

#session_idString (readonly)

Returns Used to uniquely identify this session. Mostly used when resuming connections.

Returns:

  • (String)

    Used to uniquely identify this session. Mostly used when resuming connections.



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

def session_id
  @session_id
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/discordrb/gateway.rb', line 131

def invalid?
  @invalid
end

#invalidateObject

Flags this session as being invalid



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

def invalidate
  @invalid = true
  @resume_gateway_url = nil
end

#resumeObject

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



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

def resume
  @suspended = false
end

#should_resume?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/discordrb/gateway.rb', line 135

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



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

def suspend
  @suspended = true
end

#suspended?Boolean

Returns:

  • (Boolean)


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

def suspended?
  @suspended
end