Compare commits

..

8 Commits

Author SHA1 Message Date
kohlerpop1
7e59099793 Add session id to websocket connection to get authenticated WS as well as optional customizable type for disconnecting websocket client in various ways. 2025-05-21 18:43:14 -04:00
GitHub Action
dd2f311539 Update version in pom.xml 2025-05-19 18:47:52 +00:00
David Kohler
ba69f5f5eb Merge pull request #129 from jwdeveloper/develop-1.10.5
Add TikTok Target Identity Data Center cookie to make sessionid effective and verifiable.
2025-05-19 14:46:16 -04:00
kohlerpop1
e9a91f5741 Add TikTok Target Identity Data Center cookie to make sessionid effective and verifiable. 2025-05-19 14:40:41 -04:00
GitHub Action
053bb5e3dc Update version in pom.xml 2025-05-12 02:21:39 +00:00
David Kohler
906796dc23 Merge pull request #128 from jwdeveloper/develop-1.10.4
Fix throwing error bug when connecting using proxy!
2025-05-11 22:19:37 -04:00
kohlerpop1
162092c638 Fix throwing error bug when connecting using proxy! 2025-05-11 22:19:04 -04:00
GitHub Action
a72d134796 Update version in pom.xml 2025-05-11 02:09:04 +00:00
14 changed files with 54 additions and 25 deletions

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>TikTokLiveJava</artifactId> <artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId> <groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.10.2-Release</version> <version>1.10.5-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>API</artifactId> <artifactId>API</artifactId>

View File

@@ -90,11 +90,18 @@ public class LiveClientSettings {
private boolean throwOnAgeRestriction; private boolean throwOnAgeRestriction;
/** /**
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId * Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId.
* @see <a href="https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages">Documentation: How to obtain sessionId</a> * <p>This requires {@link #ttTargetIdc} also being set correctly for sessionid to be effective.
* @apiNote This cookie is supplied by <a href="https://www.tiktok.com">TikTok</a> and can be found in your browser cookies.
*/ */
private String sessionId; private String sessionId;
/**
* Used with {@link #sessionId} to verify it is valid and return extra chat messages and 18+ content.
* @apiNote This cookie is supplied by <a href="https://www.tiktok.com">TikTok</a> and can be found in your browser cookies.
*/
private String ttTargetIdc;
/** /**
* Optional: By default roomID is fetched before connect to live, but you can set it manually * Optional: By default roomID is fetched before connect to live, but you can set it manually
*/ */

View File

@@ -51,9 +51,17 @@ public interface LiveClient {
/** /**
* Disconnects the connection. * 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
*/ */
void disconnect(); void disconnect(int type);
default void disconnect() {
disconnect(0);
}
/** /**
* Use to manually invoke event * Use to manually invoke event

View File

@@ -27,6 +27,6 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
public interface LiveSocketClient { public interface LiveSocketClient {
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient); void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
void stop(); void stop(int type);
boolean isConnected(); boolean isConnected();
} }

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>TikTokLiveJava</artifactId> <artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId> <groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.10.2-Release</version> <version>1.10.5-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -153,9 +153,9 @@ public class TikTokLiveClient implements LiveClient
tikTokEventHandler.publish(this, new TikTokRoomInfoEvent(roomInfo)); tikTokEventHandler.publish(this, new TikTokRoomInfoEvent(roomInfo));
} }
public void disconnect() { public void disconnect(int type) {
if (webSocketClient.isConnected()) if (webSocketClient.isConnected())
webSocketClient.stop(); webSocketClient.stop(type);
if (!roomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) if (!roomInfo.hasConnectionState(ConnectionState.DISCONNECTED))
setState(ConnectionState.DISCONNECTED); setState(ConnectionState.DISCONNECTED);
} }

View File

@@ -113,6 +113,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
.withParam("uniqueId", request.getUserName()) .withParam("uniqueId", request.getUserName())
.withParam("sourceType", "54") //MAGIC NUMBER, WHAT 54 means? .withParam("sourceType", "54") //MAGIC NUMBER, WHAT 54 means?
.withCookie("sessionid", clientSettings.getSessionId()) .withCookie("sessionid", clientSettings.getSessionId())
.withCookie("tt-target-idc", clientSettings.getTtTargetIdc())
.build() .build()
.toJsonResponse(); .toJsonResponse();
@@ -141,6 +142,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
var result = httpFactory.client(url) var result = httpFactory.client(url)
.withParam("room_id", request.getRoomId()) .withParam("room_id", request.getRoomId())
.withCookie("sessionid", clientSettings.getSessionId()) .withCookie("sessionid", clientSettings.getSessionId())
.withCookie("tt-target-idc", clientSettings.getTtTargetIdc())
.build() .build()
.toJsonResponse(); .toJsonResponse();
@@ -197,6 +199,8 @@ public class TikTokLiveHttpClient implements LiveHttpClient
.withParam("client", "ttlive-java") .withParam("client", "ttlive-java")
.withParam("room_id", room_id); .withParam("room_id", room_id);
if (clientSettings.getSessionId() != null) // Allows receiving of all comments and Subscribe Events
builder.withParam("session_id", clientSettings.getSessionId());
if (clientSettings.getApiKey() != null) if (clientSettings.getApiKey() != null)
builder.withParam("apiKey", clientSettings.getApiKey()); builder.withParam("apiKey", clientSettings.getApiKey());

View File

@@ -28,6 +28,7 @@ import io.github.jwdeveloper.tiktok.data.settings.*;
import io.github.jwdeveloper.tiktok.exceptions.*; import io.github.jwdeveloper.tiktok.exceptions.*;
import io.github.jwdeveloper.tiktok.live.*; import io.github.jwdeveloper.tiktok.live.*;
import org.java_websocket.client.WebSocketClient; import org.java_websocket.client.WebSocketClient;
import org.java_websocket.framing.CloseFrame;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.net.Proxy; import java.net.Proxy;
@@ -56,7 +57,7 @@ public class TikTokWebSocketClient implements LiveSocketClient {
@Override @Override
public void start(LiveConnectionData.Response connectionData, LiveClient liveClient) { public void start(LiveConnectionData.Response connectionData, LiveClient liveClient) {
if (isConnected()) if (isConnected())
stop(); stop(0);
messageHandler.handle(liveClient, connectionData.getWebcastResponse()); messageHandler.handle(liveClient, connectionData.getWebcastResponse());
@@ -110,12 +111,11 @@ public class TikTokWebSocketClient implements LiveSocketClient {
ProxyData proxyData = proxySettings.next(); ProxyData proxyData = proxySettings.next();
if (tryProxyConnection(proxySettings, proxyData)) { if (tryProxyConnection(proxySettings, proxyData)) {
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval()); heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
break; return;
} }
if (proxySettings.isAutoDiscard()) if (proxySettings.isAutoDiscard())
proxySettings.remove(); proxySettings.remove();
} }
if (!isConnected())
throw new TikTokLiveException("Failed to connect to the websocket"); throw new TikTokLiveException("Failed to connect to the websocket");
} }
@@ -129,9 +129,19 @@ public class TikTokWebSocketClient implements LiveSocketClient {
} }
} }
public void stop() { public void stop(int type) {
if (isConnected()) { if (isConnected()) {
webSocketClient.close(); switch (type) {
case 1 -> {
try {
webSocketClient.closeBlocking();
} catch (InterruptedException e) {
throw new TikTokLiveException("Failed to stop the websocket");
}
}
case 2 -> webSocketClient.closeConnection(CloseFrame.NORMAL, "");
default -> webSocketClient.close();
}
heartbeatTask.stop(); heartbeatTask.stop();
} }
webSocketClient = null; webSocketClient = null;

View File

@@ -44,7 +44,7 @@ public class TikTokWebSocketOfflineClient implements LiveSocketClient {
} }
@Override @Override
public void stop() { public void stop(int type) {
if (liveClient != null) if (liveClient != null)
handler.publish(liveClient, new TikTokDisconnectedEvent("Stopping")); handler.publish(liveClient, new TikTokDisconnectedEvent("Stopping"));
} }

View File

@@ -41,7 +41,7 @@
<parent> <parent>
<artifactId>TikTokLiveJava</artifactId> <artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId> <groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.10.2-Release</version> <version>1.10.5-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>io.github.jwdeveloper.tiktok</groupId> <groupId>io.github.jwdeveloper.tiktok</groupId>
<artifactId>TikTokLiveJava</artifactId> <artifactId>TikTokLiveJava</artifactId>
<version>1.10.2-Release</version> <version>1.10.5-Release</version>
</parent> </parent>

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>TikTokLiveJava</artifactId> <artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId> <groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.10.2-Release</version> <version>1.10.5-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>extension-recorder</artifactId> <artifactId>extension-recorder</artifactId>

View File

@@ -7,7 +7,7 @@
<groupId>io.github.jwdeveloper.tiktok</groupId> <groupId>io.github.jwdeveloper.tiktok</groupId>
<artifactId>TikTokLiveJava</artifactId> <artifactId>TikTokLiveJava</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>1.10.2-Release</version> <version>1.10.5-Release</version>
<modules> <modules>
<module>API</module> <module>API</module>
<module>Client</module> <module>Client</module>

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>TikTokLiveJava</artifactId> <artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId> <groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.10.2-Release</version> <version>1.10.5-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>