Skip to content

Commit 59c4761

Browse files
Add WebSocketPreConnectGatewayEvent
1 parent 31afd77 commit 59c4761

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.dv8tion.jda.api.events;
18+
19+
import net.dv8tion.jda.api.JDA;
20+
import net.dv8tion.jda.internal.requests.WebSocketClient;
21+
22+
import javax.annotation.Nonnull;
23+
24+
/**
25+
* Called before a WebSocket connects to the gateway
26+
*/
27+
public class WebSocketPreConnectGatewayEvent extends Event
28+
{
29+
private final WebSocketClient client;
30+
31+
public WebSocketPreConnectGatewayEvent(@Nonnull JDA api, @Nonnull WebSocketClient client)
32+
{
33+
super(api);
34+
this.client = client;
35+
}
36+
37+
@Nonnull
38+
public WebSocketClient getClient()
39+
{
40+
return client;
41+
}
42+
}

src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public void onGenericEvent(@Nonnull GenericEvent event) {}
132132
public void onGenericUpdate(@Nonnull UpdateEvent<?, ?> event) {}
133133
public void onRawGateway(@Nonnull RawGatewayEvent event) {}
134134
public void onPreProcessedRawGateway(@Nonnull PreProcessedRawGatewayEvent event) {}
135+
public void onWebSocketPreConnectGateway(@Nonnull WebSocketPreConnectGatewayEvent event) {}
135136
public void onGatewayPing(@Nonnull GatewayPingEvent event) {}
136137

137138
//Session Events

src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import net.dv8tion.jda.api.events.ExceptionEvent;
3131
import net.dv8tion.jda.api.events.PreProcessedRawGatewayEvent;
3232
import net.dv8tion.jda.api.events.RawGatewayEvent;
33+
import net.dv8tion.jda.api.events.WebSocketPreConnectGatewayEvent;
3334
import net.dv8tion.jda.api.events.session.*;
3435
import net.dv8tion.jda.api.exceptions.ParsingException;
3536
import net.dv8tion.jda.api.managers.AudioManager;
@@ -396,6 +397,9 @@ protected synchronized void connect()
396397
throw new RejectedExecutionException("JDA is shutdown!");
397398
initiating = true;
398399

400+
WebSocketPreConnectGatewayEvent event = new WebSocketPreConnectGatewayEvent(api, this);
401+
api.handleEvent(event);
402+
399403
try
400404
{
401405
String gatewayUrl = resumeUrl != null ? resumeUrl : api.getGatewayUrl();

0 commit comments

Comments
 (0)