Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add websocket connection state events / new connection lost sta…
…te (#597) * feat: emit websocket events * feat: include old value in onStateChanged * feat: split event into chat and pubsub events * feat: include old state in fired event * refactor: use equality operator on enums * fix: allow early manual connect after connection lost * refactor: rename chat var in connection event * fix: avoid leak from early connect after lost * refactor: rename connection events * docs: add javadocs for WebsocketConnectionState Co-authored-by: Sidd <iProdigy@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
175 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
chat/src/main/java/com/github/twitch4j/chat/events/ChatConnectionStateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.twitch4j.chat.events; | ||
|
||
import com.github.philippheuer.events4j.core.domain.Event; | ||
import com.github.twitch4j.chat.TwitchChat; | ||
import com.github.twitch4j.client.websocket.domain.WebsocketConnectionState; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
/** | ||
* Chat Connection Event | ||
* <p> | ||
* Called when a chat socket's connection status changes. | ||
*/ | ||
@Data | ||
@EqualsAndHashCode(callSuper = false) | ||
public class ChatConnectionStateEvent extends Event { | ||
|
||
/** | ||
* The previous state of the websocket. | ||
*/ | ||
private final WebsocketConnectionState previousState; | ||
|
||
/** | ||
* The updated state of the websocket. | ||
*/ | ||
private final WebsocketConnectionState state; | ||
|
||
/** | ||
* The chat instance whose connection status changed. | ||
*/ | ||
private final TwitchChat connection; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 37 additions & 1 deletion
38
...t/src/main/java/com/github/twitch4j/client/websocket/domain/WebsocketConnectionState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
package com.github.twitch4j.client.websocket.domain; | ||
|
||
import com.github.twitch4j.client.websocket.WebsocketConnection; | ||
|
||
/** | ||
* The state of a {@link WebsocketConnection}. | ||
*/ | ||
public enum WebsocketConnectionState { | ||
|
||
/** | ||
* The websocket is in the process of disconnecting after a call to {@link WebsocketConnection#disconnect()}. | ||
*/ | ||
DISCONNECTING, | ||
|
||
/** | ||
* The websocket has started its reconnection procedure after a call to {@link WebsocketConnection#reconnect()}. | ||
*/ | ||
RECONNECTING, | ||
|
||
/** | ||
* The websocket is (deliberately) fully disconnected. | ||
* <p> | ||
* This state will eventually be set after a call to {@link WebsocketConnection#disconnect()}. | ||
* This is also the initial state upon creation of {@link WebsocketConnection}. | ||
*/ | ||
DISCONNECTED, | ||
|
||
/** | ||
* The websocket has started its connection procedure after a call to {@link WebsocketConnection#connect()}. | ||
*/ | ||
CONNECTING, | ||
CONNECTED | ||
|
||
/** | ||
* The websocket has established a connection after completing the connection handshake procedure. | ||
*/ | ||
CONNECTED, | ||
|
||
/** | ||
* The websocket inadvertently lost connection. | ||
* <p> | ||
* This could occur for a variety of reasons including: network issues, firewall changes, or even a server-side crash. | ||
*/ | ||
LOST | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
pubsub/src/main/java/com/github/twitch4j/pubsub/events/PubSubConnectionStateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.twitch4j.pubsub.events; | ||
|
||
import com.github.philippheuer.events4j.core.domain.Event; | ||
import com.github.twitch4j.client.websocket.domain.WebsocketConnectionState; | ||
import com.github.twitch4j.pubsub.TwitchPubSub; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
/** | ||
* PubSub Connection Event | ||
* <p> | ||
* Called when a PubSub socket's connection status changes. | ||
*/ | ||
@Data | ||
@EqualsAndHashCode(callSuper = false) | ||
public class PubSubConnectionStateEvent extends Event { | ||
|
||
/** | ||
* The previous state of the websocket. | ||
*/ | ||
private final WebsocketConnectionState previousState; | ||
|
||
/** | ||
* The updated state of the websocket. | ||
*/ | ||
private final WebsocketConnectionState state; | ||
|
||
/** | ||
* The PubSub instance whose connection status changed. | ||
*/ | ||
private final TwitchPubSub connection; | ||
|
||
} |