mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Add integration for Eulerstream websocket connections and other QOL changes! (#144)
* Quick string alteration for proper state! * Remove -1 close code and convert to standard public static value with reference! * Convert to and use LiveClientStopType enum for disconnecting websocket from magic numbers! * Add capability to use Eulerstream Enterprise server and websocket!
This commit is contained in:
@@ -30,14 +30,22 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Control)
|
||||
public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
||||
public static int UNKNOWN_CLOSE_CODE = -1;
|
||||
|
||||
/** Valid CloseFrame code or -1 for unknown */
|
||||
private final int code;
|
||||
private final String reason;
|
||||
|
||||
public TikTokDisconnectedEvent(String reason) {
|
||||
public TikTokDisconnectedEvent(int code, String reason) {
|
||||
this.code = code;
|
||||
this.reason = reason.isBlank() ? "None" : reason;
|
||||
}
|
||||
|
||||
public static TikTokDisconnectedEvent of(String reason)
|
||||
{
|
||||
return new TikTokDisconnectedEvent(reason);
|
||||
public TikTokDisconnectedEvent(String reason) {
|
||||
this(UNKNOWN_CLOSE_CODE, reason);
|
||||
}
|
||||
|
||||
public boolean isUnknownCloseCode() {
|
||||
return this.code == UNKNOWN_CLOSE_CODE;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.data.requests;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
|
||||
import lombok.*;
|
||||
|
||||
public class LiveUserData {
|
||||
@@ -43,9 +43,7 @@ public class LiveUserData {
|
||||
public static class Response {
|
||||
private final String json;
|
||||
private final UserStatus userStatus;
|
||||
private final String roomId;
|
||||
private final long startTime;
|
||||
private final User user;
|
||||
private final LiveRoomInfo roomInfo;
|
||||
|
||||
public boolean isLiveOnline() {
|
||||
return userStatus == LiveUserData.UserStatus.Live || userStatus == LiveUserData.UserStatus.LivePaused;
|
||||
|
||||
@@ -89,6 +89,16 @@ public class LiveClientSettings {
|
||||
/** Throw an exception on 18+ Age Restriction */
|
||||
private boolean throwOnAgeRestriction;
|
||||
|
||||
/** Use Eulerstream.com websocket for events
|
||||
* @apiNote Requires API Key
|
||||
*/
|
||||
private boolean useEulerstreamWebsocket;
|
||||
|
||||
/** Use Eulerstream.com enterprise endpoints
|
||||
* @apiNote Requires API Key with
|
||||
*/
|
||||
private boolean useEulerstreamEnterprise;
|
||||
|
||||
/**
|
||||
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId.
|
||||
* <p>This requires {@link #ttTargetIdc} also being set correctly for sessionid to be effective.
|
||||
|
||||
@@ -24,6 +24,7 @@ package io.github.jwdeveloper.tiktok.live;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.listener.ListenersManager;
|
||||
import io.github.jwdeveloper.tiktok.websocket.LiveClientStopType;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
@@ -49,16 +50,16 @@ public interface LiveClient {
|
||||
|
||||
/**
|
||||
* Disconnects the connection.
|
||||
* @param type
|
||||
* <p>0 - Normal - Initiates disconnection and returns
|
||||
* <p>1 - Disconnects blocking and returns after closure
|
||||
* <p>2 - Disconnects and kills connection to websocket
|
||||
* <p>Default {@link #disconnect()} is 0
|
||||
* @param type {@code LiveClientStopType}
|
||||
* @see LiveClientStopType
|
||||
*/
|
||||
void disconnect(int type);
|
||||
void disconnect(LiveClientStopType type);
|
||||
|
||||
/**
|
||||
* Disconnects with {@link LiveClientStopType#NORMAL}
|
||||
*/
|
||||
default void disconnect() {
|
||||
disconnect(0);
|
||||
disconnect(LiveClientStopType.NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,5 +49,7 @@ public interface LiveRoomInfo
|
||||
String getTitle();
|
||||
User getHost();
|
||||
List<RankingUser> getUsersRanking();
|
||||
String getLanguage();
|
||||
ConnectionState getConnectionState();
|
||||
void copy(LiveRoomInfo roomInfo);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2024 jwdeveloper jacekwoln@gmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.websocket;
|
||||
|
||||
public enum LiveClientStopType
|
||||
{
|
||||
/**
|
||||
* Initiates the websocket close handshake. This method does not block<br> In oder to make sure
|
||||
* the connection is closed use {@link LiveClientStopType#CLOSE_BLOCKING}
|
||||
*/
|
||||
NORMAL,
|
||||
/**
|
||||
* Same as {@link LiveClientStopType#NORMAL} but blocks until the websocket closed or failed to do so.<br>
|
||||
*
|
||||
* @apiNote Can throw {@link InterruptedException} when/if the threads get interrupted
|
||||
*/
|
||||
CLOSE_BLOCKING,
|
||||
/**
|
||||
* This will close the connection immediately without a proper close handshake.
|
||||
* The code and the message therefore won't be transferred over the wire also they will be forwarded to onClose/onWebsocketClose. */
|
||||
DISCONNECT
|
||||
}
|
||||
@@ -27,6 +27,6 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
|
||||
public interface LiveSocketClient {
|
||||
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
|
||||
void stop(int type);
|
||||
void stop(LiveClientStopType type);
|
||||
boolean isConnected();
|
||||
}
|
||||
Reference in New Issue
Block a user