mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 17:29:39 -05:00
Events handling
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.messages.WebcastWebsocketMessage;
|
||||
import org.junit.Test;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SerializeWebMessageTest
|
||||
{
|
||||
@Test
|
||||
public void WebcastWebsocketMessage()
|
||||
{
|
||||
try (var str = getClass().getClassLoader().getResourceAsStream("WebcastWebsocketMessage.bin"))
|
||||
{
|
||||
var bytes = str.readAllBytes();
|
||||
var person = WebcastWebsocketMessage.parseFrom(bytes);
|
||||
System.out.println("id: " + person.getId());
|
||||
System.out.println("type: " + person.getType());
|
||||
System.out.println("binary: " + person.getBinary().size());
|
||||
// System.out.println("Email: " + person.getEmail());
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
System.out.println("Error parsing the protobuf message: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error reading the file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,84 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.events.messages.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TikTokLiveTest
|
||||
{
|
||||
public static String TEST_USER_SUBJECT = "live_interactive_";
|
||||
public class TikTokLiveTest {
|
||||
public static String TEST_USER_SUBJECT = "tv_asahi_news";
|
||||
|
||||
|
||||
@Test
|
||||
public void ShouldConnect() throws IOException {
|
||||
var client = TikTokLive.newClient(TEST_USER_SUBJECT).build();
|
||||
client.run();
|
||||
|
||||
|
||||
|
||||
var client = TikTokLive.newClient(TEST_USER_SUBJECT)
|
||||
.onConnected(this::onConnected)
|
||||
.onDisconnected(this::onDisconnected)
|
||||
.onRoomViewerData(this::onViewerData)
|
||||
.onJoin(this::onJoin)
|
||||
.onComment(this::onComment)
|
||||
.onFollow(this::onFollow)
|
||||
.onShare(this::onShare)
|
||||
.onSubscribe(this::onSubscribe)
|
||||
.onLike(this::onLike)
|
||||
.onGiftMessage(this::onGiftMessage)
|
||||
.onEmote(this::onEmote)
|
||||
.buildAndRun();
|
||||
System.in.read();
|
||||
|
||||
}
|
||||
private void onConnected(TikTokConnectedEvent e) {
|
||||
print("Connected");
|
||||
}
|
||||
|
||||
private void onDisconnected(TikTokDisconnectedEvent e) {
|
||||
print("Disconnected");
|
||||
}
|
||||
|
||||
private void onViewerData(TikTokRoomViewerDataEvent e) {
|
||||
print("Viewer count is:", e.getViewerCount());
|
||||
}
|
||||
|
||||
private void onJoin(TikTokJoinEvent e) {
|
||||
print(e.getUser().getUniqueId(), "joined!");
|
||||
}
|
||||
|
||||
private void onComment(TikTokCommentEvent e) {
|
||||
print(e.getUser().getUniqueId(), e.getText());
|
||||
}
|
||||
|
||||
private void onFollow(TikTokFollowEvent e) {
|
||||
print(e.getNewFollower().getUniqueId(), "followed!");
|
||||
}
|
||||
|
||||
private void onShare(TikTokShareEvent e) {
|
||||
print(e.getUser().getUniqueId(), "shared!");
|
||||
}
|
||||
|
||||
private void onSubscribe(TikTokSubscribeEvent e) {
|
||||
print(e.getNewSubscriber().getUniqueId(), "subscribed!");
|
||||
}
|
||||
|
||||
private void onLike(TikTokLikeEvent e) {
|
||||
|
||||
print(e.getSender().getUniqueId(), "liked!");
|
||||
}
|
||||
|
||||
private void onGiftMessage(TikTokGiftMessageEvent e) {
|
||||
print(e.getSender().getUniqueId(), "sent", e.getAmount(), "x", e.getGift().getName());
|
||||
}
|
||||
|
||||
private void onEmote(TikTokEmoteEvent e) {
|
||||
print(e.getUser().getUniqueId(), "sent", e.getEmoteId());
|
||||
}
|
||||
|
||||
private static void print(Object... messages) {
|
||||
var sb = new StringBuilder();
|
||||
for (var message : messages) {
|
||||
sb.append(message).append(" ");
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
|
||||
}
|
||||
32
Client/src/test/resources/WebcastWebsocketMessage.bin
Normal file
32
Client/src/test/resources/WebcastWebsocketMessage.bin
Normal file
@@ -0,0 +1,32 @@
|
||||
ŔĆł»›„ÖF¸E *
|
||||
|
||||
compress_typenone2pb:msgBš
|
||||
Ű
|
||||
WebcastLikeMessageş
|
||||
|
||||
WebcastLikeMessageˇ–¤ŚöÍííd –żÚřęëíd0BŔ
|
||||
pm_mt_msg_viewer{0:user} liked the LIVE
|
||||
#ffffffff "‚
|
||||
Ş}
|
||||
{ ”‚•ÉÔëdhulajnoga czek˛hulajnoga.czek5ňLMS4wLjABAAAAx4-lIrRjH0pMT0D3laROVsnU-4u6P1tN4td82AQTCHjKZ-CHaF_DluNSFQQp1s4DHP°¸Ŕ ĆЂҟ1†q*Ü ”‚•ÉÔëdhulajnoga czek˛ş ˛hulajnoga.czek5J˙
|
||||
Čhttps://p16-sign-useast2a.tiktokcdn.com/tos-useast2a-avt-0068-euttp/26aa68e29831ff0c9d4fb37875efffdd~tplv-tiktok-shrink:72:72.webp?x-expires=1692291600&x-signature=Z2ZM2T%2FckIxKSj%2BJY%2BONoypyMwo%3D
|
||||
´https://p16-sign-useast2a.tiktokcdn.com/tos-useast2a-avt-0068-euttp/26aa68e29831ff0c9d4fb37875efffdd~c5_100x100.webp?x-expires=1692291600&x-signature=gJgrVHIZWnVCif4Z6gXuhnl1pn8%3D
|
||||
´https://p16-sign-useast2a.tiktokcdn.com/tos-useast2a-avt-0068-euttp/26aa68e29831ff0c9d4fb37875efffdd~c5_100x100.jpeg?x-expires=1692291600&x-signature=ITqTLj6v7UVl12HeeGa6a6FYNpc%3DD100x100/tos-useast2a-avt-0068-euttp/26aa68e29831ff0c9d4fb37875efffddŞ0‚ ňLMS4wLjABAAAAx4-lIrRjH0pMT0D3laROVsnU-4u6P1tN4td82AQTCHjKZ-CHaF_DluNSFQQp1s4D‚îR„sslocal://webcast_webview_popup?gravity=bottom&show_mask=1&url=https%3A%2F%2Flf16-web.tiktokcdn.com%2Fobj%2Fies-hotsoon-draft-sg%2Ftiktok-live-faq%2Ftiktok_live_revenue_new_gifter_details.html&web_bg_color=FFFFFF&height=60%25&mask_bg_color=000000b3&use_spark=1b:"10000037267585271263611681*0
|
||||
271541203697319145231Ş pm_mt_live_ng_im
|
||||
New gifter( ‚Ü Résslocal://webcast_lynxview_popup?use_spark=1&url=https%3A%2F%2Flf16-gecko-source.tiktokcdn.com%2Fobj%2Fbyte-gurd-source-sg%2Ftiktok%2Ffe%2Flive%2Ftiktok_live_revenue_user_level_main%2Fsrc%2Fpages%2Fprivilege%2Fpanel%2Ftemplate.js&hide_status_bar=0&hide_nav_bar=1&container_bg_color=00000000&height=90%25&bdhm_bid=tiktok_live_revenue_user_level_main&use_forest=1XbN
|
||||
271383811767874578280".mock_fix_width_transparent_7138381176787457828*2ş’Ő+webcast-va/grade_badge_icon_lite_lv1_v1.png:ésslocal://webcast_lynxview_popup?use_spark=1&url=https%3A%2F%2Flf16-gecko-source.tiktokcdn.com%2Fobj%2Fbyte-gurd-source-sg%2Ftiktok%2Ffe%2Flive%2Ftiktok_live_revenue_user_level_main%2Fsrc%2Fpages%2Fprivilege%2Fpanel%2Ftemplate.js&hide_status_bar=0&hide_nav_bar=1&container_bg_color=00000000&height=90%25&bdhm_bid=tiktok_live_revenue_user_level_main&use_forest=1
|
||||
\https://p16-webcast.tiktokcdn.com/webcast-va/grade_badge_icon_lite_lv1_v1.png~tplv-obj.image
|
||||
\https://p19-webcast.tiktokcdn.com/webcast-va/grade_badge_icon_lite_lv1_v1.png~tplv-obj.image"2* b
|
||||
#99789EE7x2 : " Z
|
||||
#99789EE7€‚÷( R„sslocal://webcast_webview_popup?gravity=bottom&show_mask=1&url=https%3A%2F%2Flf16-web.tiktokcdn.com%2Fobj%2Fies-hotsoon-draft-sg%2Ftiktok-live-faq%2Ftiktok_live_revenue_new_gifter_details.html&web_bg_color=FFFFFF&height=60%25&mask_bg_color=000000b3&use_spark=1Xb:
|
||||
271541203697319145231"10000037267585271263611681*0ş¦x€Ű 0:„sslocal://webcast_webview_popup?gravity=bottom&show_mask=1&url=https%3A%2F%2Flf16-web.tiktokcdn.com%2Fobj%2Fies-hotsoon-draft-sg%2Ftiktok-live-faq%2Ftiktok_live_revenue_new_gifter_details.html&web_bg_color=FFFFFF&height=60%25&mask_bg_color=000000b3&use_spark=1
|
||||
Shttps://p16-webcast.tiktokcdn.com/webcast-va/new_gifter_badge_v3.png~tplv-obj.image
|
||||
Shttps://p19-webcast.tiktokcdn.com/webcast-va/new_gifter_badge_v3.png~tplv-obj.image"webcast-va/new_gifter_badge_v3.png
|
||||
pm_mt_live_ng_im
|
||||
New gifterZ
|
||||
#803F3F3Fb
|
||||
#803F3F3FBÍ†Ë”Ź¨Á‚cŔ
|
||||
pm_mt_msg_viewer{0:user} liked the LIVE
|
||||
#ffffffff "‚
|
||||
Ş}
|
||||
{˛hulajnoga.czek5ňLMS4wLjABAAAAx4-lIrRjH0pMT0D3laROVsnU-4u6P1tN4td82AQTCHjKZ-CHaF_DluNSFQQp1s4D ”‚•ÉÔëdhulajnoga czekHˇ–¤ŚöÍííd)1692120689751_7267603020139989890_1_1_0_0č ×؂ҟ1*-@H
|
||||
Reference in New Issue
Block a user