mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Add capability to use Eulerstream Enterprise server and websocket!
This commit is contained in:
@@ -94,6 +94,11 @@ public class LiveClientSettings {
|
|||||||
*/
|
*/
|
||||||
private boolean useEulerstreamWebsocket;
|
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.
|
* 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.
|
* <p>This requires {@link #ttTargetIdc} also being set correctly for sessionid to be effective.
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
*/
|
*/
|
||||||
private static final String TIKTOK_SIGN_API = "https://tiktok.eulerstream.com/webcast/fetch";
|
private static final String TIKTOK_SIGN_API = "https://tiktok.eulerstream.com/webcast/fetch";
|
||||||
private static final String TIKTOK_CHAT_URL = "https://tiktok.eulerstream.com/webcast/chat";
|
private static final String TIKTOK_CHAT_URL = "https://tiktok.eulerstream.com/webcast/chat";
|
||||||
|
private static final String TIKTOK_SIGN_ENTERPRISE_API = "https://tiktok.enterprise.eulerstream.com/webcast/fetch";
|
||||||
|
private static final String TIKTOK_CHAT_ENTERPRISE_URL = "https://tiktok.enterprise.eulerstream.com/webcast/chat";
|
||||||
private static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
|
private static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
|
||||||
private static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
|
private static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
|
||||||
private static final String TIKTOK_ROOM_GIFTS_URL = TIKTOK_URL_WEBCAST+"gift/list/";
|
private static final String TIKTOK_ROOM_GIFTS_URL = TIKTOK_URL_WEBCAST+"gift/list/";
|
||||||
@@ -198,7 +200,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
body.addProperty("sessionId", clientSettings.getSessionId());
|
body.addProperty("sessionId", clientSettings.getSessionId());
|
||||||
body.addProperty("ttTargetIdc", clientSettings.getTtTargetIdc());
|
body.addProperty("ttTargetIdc", clientSettings.getTtTargetIdc());
|
||||||
body.addProperty("roomId", roomInfo.getRoomId());
|
body.addProperty("roomId", roomInfo.getRoomId());
|
||||||
HttpClientBuilder builder = httpFactory.client(TIKTOK_CHAT_URL)
|
HttpClientBuilder builder = httpFactory.client(clientSettings.isUseEulerstreamEnterprise() ? TIKTOK_CHAT_ENTERPRISE_URL : TIKTOK_CHAT_URL)
|
||||||
.withHeader("Content-Type", "application/json");
|
.withHeader("Content-Type", "application/json");
|
||||||
if (clientSettings.getApiKey() != null)
|
if (clientSettings.getApiKey() != null)
|
||||||
builder.withHeader("x-api-key", clientSettings.getApiKey());
|
builder.withHeader("x-api-key", clientSettings.getApiKey());
|
||||||
@@ -219,7 +221,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
||||||
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
|
HttpClientBuilder builder = httpFactory.client(clientSettings.isUseEulerstreamEnterprise() ? TIKTOK_SIGN_ENTERPRISE_API : TIKTOK_SIGN_API)
|
||||||
.withParam("client", "ttlive-java")
|
.withParam("client", "ttlive-java")
|
||||||
.withParam("room_id", room_id);
|
.withParam("room_id", room_id);
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,11 @@ public class TikTokWebSocketEulerClient implements LiveSocketClient {
|
|||||||
if (isConnected())
|
if (isConnected())
|
||||||
stop(LiveClientStopType.NORMAL);
|
stop(LiveClientStopType.NORMAL);
|
||||||
|
|
||||||
|
String url = "wss://ws.eulerstream.com?uniqueId=%s&apiKey=%s&features.rawMessages=true".formatted(liveClient.getRoomInfo().getHostName(), clientSettings.getApiKey())
|
||||||
|
+ (clientSettings.isUseEulerstreamWebsocket() ? "&features.useEnterpriseApi=true" : "");
|
||||||
|
|
||||||
webSocketClient = new TikTokWebSocketEulerListener(
|
webSocketClient = new TikTokWebSocketEulerListener(
|
||||||
URI.create("wss://ws.eulerstream.com?uniqueId=%s&apiKey=%s&features.rawMessages=true".formatted(liveClient.getRoomInfo().getHostName(), clientSettings.getApiKey())),
|
URI.create(url),
|
||||||
new HashMap<>(clientSettings.getHttpSettings().getHeaders()),
|
new HashMap<>(clientSettings.getHttpSettings().getHeaders()),
|
||||||
clientSettings.getHttpSettings().getTimeout().toMillisPart(),
|
clientSettings.getHttpSettings().getTimeout().toMillisPart(),
|
||||||
messageHandler,
|
messageHandler,
|
||||||
|
|||||||
Reference in New Issue
Block a user