Skip to content

Commit cfdced9

Browse files
committed
Add direct method to provide sessionId and ttTargetIdc for sending chats from 1 client.
1 parent 7589a2a commit cfdced9

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

API/src/main/java/io/github/jwdeveloper/tiktok/http/LiveHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ default LiveConnectionData.Response fetchLiveConnectionData(String roomId) {
6666

6767
LiveConnectionData.Response fetchLiveConnectionData(LiveConnectionData.Request request);
6868

69-
boolean sendChat(LiveRoomInfo roomInfo, String content);
69+
boolean sendChat(LiveRoomInfo roomInfo, String content, String sessionId, String ttTargetIdc);
7070
}

API/src/main/java/io/github/jwdeveloper/tiktok/live/LiveClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,12 @@ default void disconnect() {
102102
* <p>We cannot fix this as it is a TikTok issue, not a library issue.
103103
*/
104104
boolean sendChat(String content);
105+
106+
/**
107+
* Send a chat message to the connected room
108+
* @return true if successful, otherwise false
109+
* @apiNote This is known to return true on some sessionIds despite failing!
110+
* <p>We cannot fix this as it is a TikTok issue, not a library issue.
111+
*/
112+
boolean sendChat(String content, String sessionId, String ttTargetIdc);
105113
}

Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,12 @@ public void publishMessage(String webcastMessageName, byte[] payload) {
199199

200200
@Override
201201
public boolean sendChat(String content) {
202-
return httpClient.sendChat(roomInfo, content);
202+
return sendChat(content, clientSettings.getSessionId(), clientSettings.getTtTargetIdc());
203+
}
204+
205+
@Override
206+
public boolean sendChat(String content, String sessionId, String ttTargetIdc) {
207+
return httpClient.sendChat(roomInfo, content, sessionId, ttTargetIdc);
203208
}
204209

205210
public void connectAsync(Consumer<LiveClient> onConnection) {

Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveHttpClient.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,23 @@ public LiveConnectionData.Response fetchLiveConnectionData(LiveConnectionData.Re
182182
}
183183

184184
@Override
185-
public boolean sendChat(LiveRoomInfo roomInfo, String content) {
185+
public boolean sendChat(LiveRoomInfo roomInfo, String content, String sessionId, String ttTargetIdc) {
186186
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
187187
if (proxyClientSettings.isEnabled()) {
188188
while (proxyClientSettings.hasNext()) {
189189
try {
190-
return requestSendChat(roomInfo, content);
190+
return requestSendChat(roomInfo, content, sessionId, ttTargetIdc);
191191
} catch (TikTokProxyRequestException ignored) {}
192192
}
193193
}
194-
return requestSendChat(roomInfo, content);
194+
return requestSendChat(roomInfo, content, sessionId, ttTargetIdc);
195195
}
196196

197-
public boolean requestSendChat(LiveRoomInfo roomInfo, String content) {
197+
public boolean requestSendChat(LiveRoomInfo roomInfo, String content, String sessionId, String ttTargetIdc) {
198198
JsonObject body = new JsonObject();
199199
body.addProperty("content", content);
200-
body.addProperty("sessionId", clientSettings.getSessionId());
201-
body.addProperty("ttTargetIdc", clientSettings.getTtTargetIdc());
200+
body.addProperty("sessionId", sessionId);
201+
body.addProperty("ttTargetIdc", ttTargetIdc);
202202
body.addProperty("roomId", roomInfo.getRoomId());
203203
HttpClientBuilder builder = httpFactory.client(clientSettings.isUseEulerstreamEnterprise() ? TIKTOK_CHAT_ENTERPRISE_URL : TIKTOK_CHAT_URL)
204204
.withHeader("Content-Type", "application/json");

Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveHttpOfflineClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public LiveConnectionData.Response fetchLiveConnectionData(LiveConnectionData.Re
6464
}
6565

6666
@Override
67-
public boolean sendChat(LiveRoomInfo roomInfo, String content) {
67+
public boolean sendChat(LiveRoomInfo roomInfo, String content, String sessionId, String ttTargetIdc) {
6868
// DO NOTHING
6969
return false;
7070
}

0 commit comments

Comments
 (0)