mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Changes:
LiveRoomInfo
+ new method getConnectionState() getting current state of connection
+ ListenersManager
getBindingModels() renamed to getListeners()
+ Introducing documentation, each public interface got small documentation
+ New property in config .setSessionId()
+ New event: onReconnecting()
Bugs:
CommentEvent was throwing mapping exception
This commit is contained in:
@@ -2,6 +2,7 @@ package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokDisconnectedEvent;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokErrorEvent;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokReconnectingEvent;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveOfflineHostException;
|
||||
import io.github.jwdeveloper.tiktok.handlers.TikTokEventObserver;
|
||||
@@ -62,6 +63,7 @@ public class TikTokLiveClient implements LiveClient {
|
||||
}
|
||||
catch (Exception ignored){}
|
||||
logger.info("Reconnecting");
|
||||
tikTokEventHandler.publish(this, new TikTokReconnectingEvent());
|
||||
this.connect();
|
||||
}
|
||||
throw e;
|
||||
@@ -85,6 +87,8 @@ public class TikTokLiveClient implements LiveClient {
|
||||
logger.info("Connecting");
|
||||
setState(ConnectionState.CONNECTING);
|
||||
|
||||
|
||||
apiService.updateSessionId();
|
||||
var roomId = apiService.fetchRoomId(liveRoomInfo.getUserName());
|
||||
liveRoomInfo.setRoomId(roomId);
|
||||
var roomData = apiService.fetchRoomInfo();
|
||||
|
||||
@@ -344,6 +344,13 @@ public class TikTokLiveClientBuilder implements TikTokEventBuilder<TikTokLiveCli
|
||||
tikTokEventHandler.subscribe(TikTokWebsocketMessageEvent.class, event);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TikTokLiveClientBuilder onReconnecting(TikTokEventConsumer<TikTokReconnectingEvent> event)
|
||||
{
|
||||
tikTokEventHandler.subscribe(TikTokReconnectingEvent.class, event);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,45 +26,19 @@ public class TikTokApiService {
|
||||
this.clientSettings = clientSettings;
|
||||
}
|
||||
|
||||
/*
|
||||
if (sessionId) {
|
||||
// Update sessionId
|
||||
this.#options.sessionId = sessionId;
|
||||
|
||||
public void updateSessionId()
|
||||
{
|
||||
if(clientSettings.getSessionId() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.#options.sessionId) {
|
||||
throw new Error('Missing SessionId. Please provide your current SessionId to use this feature.');
|
||||
if(clientSettings.getSessionId().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Retrieve current room_id if not connected
|
||||
if (!this.#isConnected) {
|
||||
await this.#retrieveRoomId();
|
||||
}
|
||||
|
||||
// Add the session cookie to the CookieJar
|
||||
this.#httpClient.setSessionId(this.#options.sessionId);
|
||||
|
||||
// Submit the chat request
|
||||
let requestParams = { ...this.#clientParams, content: text };
|
||||
let response = await this.#httpClient.postFormDataToWebcastApi('room/chat/', requestParams, null);
|
||||
|
||||
// Success?
|
||||
if (response?.status_code === 0) {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// Handle errors
|
||||
switch (response?.status_code) {
|
||||
case 20003:
|
||||
throw new Error('Your SessionId has expired. Please provide a new one.');
|
||||
default:
|
||||
throw new Error(`TikTok responded with status code ${response?.status_code}: ${response?.data?.message}`);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to send chat message. ${err.message}`);
|
||||
}
|
||||
*/
|
||||
tiktokHttpClient.setSessionId(clientSettings.getSessionId());
|
||||
}
|
||||
|
||||
public boolean sendMessage(String message, String sessionId) {
|
||||
if (sessionId.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user