Skip to content

Commit fc02239

Browse files
authored
Develop 1.10.8 (#140)
* Add support for TikTokLinkMicBattleItemCard for battle/match power-ups * Switch to an efficient pool of daemon threads instead of thread per websocket and sleeping! * Implement Eulerstream send chat API endpoint! * Add static to fields for single instance to manage all heartbeat threads. Far more efficient than 1 thread each sleeping! * Add global comment to known its a true global singleton!
1 parent 77eeedc commit fc02239

File tree

18 files changed

+321
-80
lines changed

18 files changed

+321
-80
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.github.jwdeveloper.tiktok.data.events;
2+
3+
import io.github.jwdeveloper.tiktok.annotations.*;
4+
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
5+
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattleItemCard;
6+
import lombok.Getter;
7+
8+
@Getter
9+
@EventMeta(eventType = EventType.Message)
10+
public class TikTokLinkMicBattleItemCard extends TikTokHeaderEvent {
11+
12+
public TikTokLinkMicBattleItemCard(WebcastLinkMicBattleItemCard msg) {
13+
super(msg.getCommon());
14+
}
15+
}

API/src/main/java/io/github/jwdeveloper/tiktok/data/models/battles/Team.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package io.github.jwdeveloper.tiktok.data.models.battles;
2424

2525
import io.github.jwdeveloper.tiktok.data.models.users.User;
26+
import io.github.jwdeveloper.tiktok.messages.data.BattleUserInfo;
2627
import io.github.jwdeveloper.tiktok.messages.enums.BattleType;
2728
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
2829
import lombok.Data;
@@ -72,12 +73,12 @@ public Team(long teamId, List<User> hosts) {
7273
this.hosts = List.copyOf(hosts);
7374
}
7475

75-
public Team(WebcastLinkMicBattle.BattleUserInfo anchorInfo) {
76+
public Team(BattleUserInfo anchorInfo) {
7677
this.hosts = List.of(new User(anchorInfo.getUser()));
7778
this.teamId = hosts.get(0).getId();
7879
}
7980

80-
public Team(WebcastLinkMicBattle.BattleUserInfo anchorInfo, WebcastLinkMicBattle.BattleComboInfo battleCombo) {
81+
public Team(BattleUserInfo anchorInfo, WebcastLinkMicBattle.BattleComboInfo battleCombo) {
8182
this(anchorInfo);
8283
this.winStreak = (int) battleCombo.getComboCount();
8384
}

API/src/main/java/io/github/jwdeveloper/tiktok/data/models/users/User.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import io.github.jwdeveloper.tiktok.data.models.Picture;
2626
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
27-
import io.github.jwdeveloper.tiktok.messages.data.BattleUserArmy;
27+
import io.github.jwdeveloper.tiktok.messages.data.*;
2828
import io.github.jwdeveloper.tiktok.messages.webcast.*;
2929
import lombok.*;
3030

@@ -140,7 +140,7 @@ public User(long id, String name, String profileId, Picture picture) {
140140
this(id, name, profileId, null, picture, 0, 0, List.of(Badge.empty()));
141141
}
142142

143-
public User(WebcastLinkMicBattle.BattleUserInfo.BattleBaseUserInfo host) {
143+
public User(BattleUserInfo.BattleBaseUserInfo host) {
144144
this(host.getUserId(), host.getDisplayId(), host.getNickName(), Picture.map(host.getAvatarThumb()));
145145
}
146146

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
2727
import io.github.jwdeveloper.tiktok.data.requests.LiveData;
2828
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
29+
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
2930

3031
public interface LiveHttpClient
3132
{
@@ -64,4 +65,6 @@ default LiveConnectionData.Response fetchLiveConnectionData(String roomId) {
6465
}
6566

6667
LiveConnectionData.Response fetchLiveConnectionData(LiveConnectionData.Request request);
68+
69+
boolean sendChat(LiveRoomInfo roomInfo, String content);
6770
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public interface LiveClient {
3636
*/
3737
void connect();
3838

39-
4039
/**
4140
* Connects in asynchronous way
4241
* When connected Consumer returns instance of LiveClient
@@ -48,7 +47,6 @@ public interface LiveClient {
4847
*/
4948
CompletableFuture<LiveClient> connectAsync();
5049

51-
5250
/**
5351
* Disconnects the connection.
5452
* @param type
@@ -68,7 +66,6 @@ default void disconnect() {
6866
*/
6967
void publishEvent(TikTokEvent event);
7068

71-
7269
/**
7370
* @param webcastMessageName name of TikTok protocol-buffer message
7471
* @param payloadBase64 protocol-buffer message bytes payload
@@ -96,4 +93,12 @@ default void disconnect() {
9693
* Logger
9794
*/
9895
Logger getLogger();
96+
97+
/**
98+
* Send a chat message to the connected room
99+
* @return true if successful, otherwise false
100+
* @apiNote This is known to return true on some sessionIds despite failing!
101+
* <p>We cannot fix this as it is a TikTok issue, not a library issue.
102+
*/
103+
boolean sendChat(String content);
99104
}

API/src/main/proto/data.proto

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,24 @@ message PublicAreaMessageCommon {
21212121
}
21222122
}
21232123

2124+
message BattleUserInfo {
2125+
BattleBaseUserInfo user = 1;
2126+
repeated BattleRivalTag tags = 2;
2127+
2128+
message BattleBaseUserInfo {
2129+
int64 user_id = 1;
2130+
string nick_name = 2;
2131+
Image avatar_thumb = 3;
2132+
string display_id = 4;
2133+
}
2134+
2135+
message BattleRivalTag {
2136+
Image bg_image = 1;
2137+
Image icon_image = 2;
2138+
string content = 3;
2139+
}
2140+
}
2141+
21242142
message GiftModeMeta {
21252143
int64 gift_id = 1;
21262144
string gift_name_key = 2;

API/src/main/proto/enums.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,4 +820,19 @@ enum BattleType {
820820
enum BattleInviteType {
821821
BATTLE_INVITE_TYPE_NORMAL = 0;
822822
BATTLE_INVITE_TYPE_AGAIN = 1;
823+
}
824+
825+
enum BattleCardMsgType {
826+
BATTLE_CARD_MSG_TYPE_UNKNOWN_CARD_ACTION = 0;
827+
BATTLE_CARD_MSG_TYPE_CARD_OBTAIN_GUIDE = 1;
828+
BATTLE_CARD_MSG_TYPE_USE_CRITICAL_STRIKE_CARD = 2;
829+
BATTLE_CARD_MSG_TYPE_USE_SMOKE_CARD = 3;
830+
BATTLE_CARD_MSG_TYPE_AWARD_CARD_NOTICE = 4;
831+
BATTLE_CARD_MSG_TYPE_USE_EXTRA_TIME_CARD = 5;
832+
BATTLE_CARD_MSG_TYPE_USE_SPECIAL_EFFECT_CARD = 6;
833+
BATTLE_CARD_MSG_TYPE_USE_POTION_CARD = 7;
834+
BATTLE_CARD_MSG_TYPE_USE_WAVE_CARD = 8;
835+
BATTLE_CARD_MSG_TYPE_SPECIAL_EFFECT_NOTICE = 9;
836+
BATTLE_CARD_MSG_TYPE_USE_TOP_2_CARD = 10;
837+
BATTLE_CARD_MSG_TYPE_USE_TOP_3_CARD = 11;
823838
}

API/src/main/proto/webcast.proto

Lines changed: 135 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,24 +1219,6 @@ message WebcastLinkMicBattle {
12191219
// BattleUserInfo user_info = 2;
12201220
// }
12211221

1222-
message BattleUserInfo {
1223-
BattleBaseUserInfo user = 1;
1224-
repeated BattleRivalTag tags = 2;
1225-
1226-
message BattleBaseUserInfo {
1227-
int64 user_id = 1;
1228-
string nick_name = 2;
1229-
Image avatar_thumb = 3;
1230-
string display_id = 4;
1231-
}
1232-
1233-
message BattleRivalTag {
1234-
Image bg_image = 1;
1235-
Image icon_image = 2;
1236-
string content = 3;
1237-
}
1238-
}
1239-
12401222
message BattleABTestSetting {
12411223
int64 uid = 1;
12421224
BattleABTestList ab_test_list = 2;
@@ -1471,4 +1453,139 @@ message RoomVerifyMessage {
14711453
string content = 3;
14721454
int64 noticeType = 4;
14731455
bool closeRoom = 5;
1456+
}
1457+
message WebcastLinkMicBattleItemCard {
1458+
CommonMessageData common = 1;
1459+
int64 battle_id = 2;
1460+
BattleCardMsgType msg_type = 3;
1461+
CardObtainGuide card_obtain_guide = 4;
1462+
UseCriticalStrikeCard use_critical_strike_card = 5;
1463+
UseSmokeCard use_smoke_card = 6;
1464+
AwardCardNotice award_card_notice = 7;
1465+
UseExtraTimeCard use_extra_time_card = 8;
1466+
UseSpecialEffectCard use_special_effect_card = 9;
1467+
UsePotionCard use_potion_card = 10;
1468+
UseWaveCard use_wave_card = 11;
1469+
SpecialEffectNotice special_effect_notice = 12;
1470+
UseTop2Card use_top2_card = 13;
1471+
UseTop3Card use_top3_card = 14;
1472+
1473+
message CardObtainGuide {
1474+
int32 not_in_use = 1;
1475+
}
1476+
1477+
message UseCriticalStrikeCard {
1478+
CriticalStrikeCardInfo card_info = 1;
1479+
int64 anchor_id = 2;
1480+
Text display_content = 3;
1481+
1482+
message CriticalStrikeCardInfo {
1483+
string card_name_key = 1;
1484+
Image card_image = 2;
1485+
int64 send_time_sec = 3;
1486+
BattleUserInfo send_user = 4;
1487+
int64 effect_last_duration = 5;
1488+
int64 critical_strike_rate_low = 6;
1489+
int64 critical_strike_rate_high = 7;
1490+
int64 multiple = 8;
1491+
string gift_name_key = 9;
1492+
string rule_url = 10;
1493+
int64 effect_time_sec = 11;
1494+
int64 to_anchor_id = 12;
1495+
string to_anchor_id_str = 13;
1496+
}
1497+
}
1498+
1499+
message UseSmokeCard {
1500+
CommonCardInfo card_info = 1;
1501+
int64 anchor_id = 2;
1502+
Text display_content = 3;
1503+
}
1504+
1505+
message AwardCardNotice {
1506+
Text display_content = 1;
1507+
repeated BattleUserInfo awarded_users = 2;
1508+
}
1509+
1510+
message UseExtraTimeCard {
1511+
ExtraTimeCardInfo card_info = 1;
1512+
int64 anchor_id = 2;
1513+
Text display_content = 3;
1514+
1515+
message ExtraTimeCardInfo {
1516+
string card_name_key = 1;
1517+
Image card_image = 2;
1518+
int64 send_time_sec = 3;
1519+
BattleUserInfo send_user = 4;
1520+
int64 effect_last_duration = 5;
1521+
string rule_url = 6;
1522+
int64 effect_time_sec = 7;
1523+
int64 to_anchor_id = 8;
1524+
int64 extra_duration_sec = 9;
1525+
string to_anchor_id_str = 10;
1526+
}
1527+
}
1528+
1529+
message UseSpecialEffectCard {
1530+
CommonCardInfo card_info = 1;
1531+
int64 anchor_id = 2;
1532+
Text display_content = 3;
1533+
repeated AnchorPair affected_anchor_pairs = 4;
1534+
}
1535+
1536+
message AnchorPair {
1537+
int64 source_anchor_id = 1;
1538+
int64 target_anchor_id = 2;
1539+
}
1540+
1541+
message UsePotionCard {
1542+
CommonCardInfo card_info = 1;
1543+
int64 anchor_id = 2;
1544+
Text display_content = 3;
1545+
}
1546+
1547+
message UseWaveCard {
1548+
CommonCardInfo card_info = 1;
1549+
int64 anchor_id = 2;
1550+
Text display_content = 3;
1551+
}
1552+
1553+
message CommonCardInfo {
1554+
string card_name_key = 1;
1555+
Image card_image = 2;
1556+
int64 send_time_sec = 3;
1557+
BattleUserInfo send_user = 4;
1558+
int64 effect_last_duration = 5;
1559+
string rule_url = 6;
1560+
int64 effect_time_sec = 7;
1561+
int64 to_anchor_id = 8;
1562+
string to_anchor_id_str = 9;
1563+
}
1564+
1565+
message SpecialEffectNotice {
1566+
int64 score = 1;
1567+
int64 from_user_id = 2;
1568+
int64 to_anchor_id = 3;
1569+
repeated AnchorPair affected_anchor_pairs = 4;
1570+
}
1571+
1572+
message UseTop2Card {
1573+
Top2CardInfo card_info = 1;
1574+
int64 anchor_id = 2;
1575+
Text display_content = 3;
1576+
1577+
message Top2CardInfo {
1578+
CommonCardInfo common = 1;
1579+
}
1580+
}
1581+
1582+
message UseTop3Card {
1583+
Top3CardInfo card_info = 1;
1584+
int64 anchor_id = 2;
1585+
Text display_content = 3;
1586+
1587+
message Top3CardInfo {
1588+
CommonCardInfo common = 1;
1589+
}
1590+
}
14741591
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ public void publishMessage(String webcastMessageName, byte[] payload) {
183183
messageHandler.handleSingleMessage(this, message);
184184
}
185185

186+
@Override
187+
public boolean sendChat(String content) {
188+
return httpClient.sendChat(roomInfo, content);
189+
}
190+
186191
public void connectAsync(Consumer<LiveClient> onConnection) {
187192
connectAsync().thenAccept(onConnection);
188193
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public LiveClient build() {
132132

133133
//networking
134134
dependance.registerSingleton(HttpClientFactory.class);
135-
dependance.registerSingleton(WebSocketHeartbeatTask.class);
135+
dependance.registerSingleton(WebSocketHeartbeatTask.class); // True global singleton - Static objects are located to serve as global
136136
if (clientSettings.isOffline()) {
137137
dependance.registerSingleton(LiveSocketClient.class, TikTokWebSocketOfflineClient.class);
138138
dependance.registerSingleton(LiveHttpClient.class, TikTokLiveHttpOfflineClient.class);

0 commit comments

Comments
 (0)