mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Changes:
`TikTokEventListener` new method of listening events see it at TestApplication/ListenerExample.java Bugs: - Fixed bug: Websocket was sending ping after it was closed
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.annotations.TikTokEventHandler;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokCommentEvent;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokErrorEvent;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokGiftMessageEvent;
|
||||
import io.github.jwdeveloper.tiktok.listener.TikTokEventListener;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ListenerExample
|
||||
{
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
CustomListener customListener = new CustomListener();
|
||||
|
||||
// set tiktok username
|
||||
TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
||||
.addListener(customListener)
|
||||
.buildAndRun();
|
||||
|
||||
System.in.read();
|
||||
}
|
||||
|
||||
public static class CustomListener implements TikTokEventListener
|
||||
{
|
||||
|
||||
@TikTokEventHandler
|
||||
public void onError(LiveClient liveClient, TikTokErrorEvent event)
|
||||
{
|
||||
System.out.println(event.getException().getMessage());
|
||||
}
|
||||
|
||||
@TikTokEventHandler
|
||||
public void onCommentMessage(LiveClient liveClient, TikTokCommentEvent event)
|
||||
{
|
||||
System.out.println(event.getText());
|
||||
}
|
||||
|
||||
@TikTokEventHandler
|
||||
public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event)
|
||||
{
|
||||
System.out.println(event.getGift().getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,11 @@ import java.time.Duration;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static String TEST_TIKTOK_USER = "olchik.m1";
|
||||
public static String TEST_TIKTOK_USER = "bangbetmenygy";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
var client = TikTokLive.newClient(TEST_TIKTOK_USER)
|
||||
public static void main(String[] args) throws IOException, InterruptedException
|
||||
{
|
||||
LiveClient client = TikTokLive.newClient(TEST_TIKTOK_USER)
|
||||
.configure(clientSettings ->
|
||||
{
|
||||
clientSettings.setRetryConnectionTimeout(Duration.ofSeconds(5));
|
||||
@@ -28,17 +29,15 @@ public class Main {
|
||||
.onLike(Main::onLike)
|
||||
.onGiftMessage(Main::onGiftMessage)
|
||||
.onEmote(Main::onEmote)
|
||||
.onEvent((liveClient, event) ->
|
||||
{
|
||||
|
||||
})
|
||||
.onError((_client, error) ->
|
||||
{
|
||||
error.getException().printStackTrace();
|
||||
})
|
||||
.onEvent((liveClient, event) ->
|
||||
{
|
||||
var viewers = liveClient.getRoomInfo().getViewersCount();
|
||||
})
|
||||
.buildAndRun();
|
||||
|
||||
|
||||
System.in.read();
|
||||
}
|
||||
|
||||
@@ -81,7 +80,7 @@ public class Main {
|
||||
|
||||
private static void onGiftMessage(LiveClient tikTokLive, TikTokGiftMessageEvent e)
|
||||
{
|
||||
print(e.getSender().getUniqueId(), "sent", e.getAmount(), "x", e.getGift().getName());
|
||||
print(e.getSender().getUniqueId(), "sent", e.getComboCount(), "x", e.getGift().getName());
|
||||
}
|
||||
|
||||
private static void onEmote(LiveClient tikTokLive, TikTokEmoteEvent e) {
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SimpleExample {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
// set tiktok username
|
||||
TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
||||
.configure(clientSettings ->
|
||||
{
|
||||
|
||||
})
|
||||
.onFollow((liveClient, event) ->
|
||||
{
|
||||
System.out.println("Follow joined -> " + event.getNewFollower().getNickName());
|
||||
@@ -14,7 +18,6 @@ public class SimpleExample {
|
||||
{
|
||||
System.out.println("Connected");
|
||||
})
|
||||
|
||||
.onJoin((client, event) ->
|
||||
{
|
||||
System.out.println("User joined -> " + event.getUser().getNickName());
|
||||
|
||||
Reference in New Issue
Block a user