Skip to content

Commit

Permalink
Close with 4000 on op 7
Browse files Browse the repository at this point in the history
  • Loading branch information
swarley committed Jun 29, 2020
1 parent a0499da commit 018e401
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/discordrb/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def reconnect(attempt_resume = true)
@instant_reconnect = true
@should_reconnect = true

close
close(4000)
end

# Sends a resume packet (op 6). This replays all events from a previous point specified by its packet sequence. This
Expand Down Expand Up @@ -808,7 +808,7 @@ def handle_close(e)
end
end

def send(data, type = :text)
def send(data, type = :text, code = nil)
LOGGER.out(data)

unless @handshaked && !@closed
Expand All @@ -817,7 +817,7 @@ def send(data, type = :text)
end

# Create the frame we're going to send
frame = ::WebSocket::Frame::Outgoing::Client.new(data: data, type: type, version: @handshake.version)
frame = ::WebSocket::Frame::Outgoing::Client.new(data: data, type: type, version: @handshake.version, code: code)

# Try to send it
begin
Expand All @@ -829,15 +829,15 @@ def send(data, type = :text)
end
end

def close
def close(code = 1000)
# If we're already closed, there's no need to do anything - return
return if @closed

# Suspend the session so we don't send heartbeats
@session&.suspend

# Send a close frame (if we can)
send nil, :close unless @pipe_broken
send nil, :close, code unless @pipe_broken

# We're officially closed, notify the main loop.
@closed = true
Expand Down

0 comments on commit 018e401

Please sign in to comment.