mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 09:19:40 -05:00
Changes:
- Implementation on all features in `clientSettings` - Code optimization - More detail exceptions - Downloading gifts
This commit is contained in:
@@ -4,24 +4,22 @@ import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ConfigurationExample
|
||||
{
|
||||
public class ConfigurationExample {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
||||
.configure(clientSettings ->
|
||||
{
|
||||
clientSettings.setHostName(Main.TEST_TIKTOK_USER); //tiktok user
|
||||
clientSettings.setClientLanguage("en"); //language
|
||||
clientSettings.setTimeout(Duration.ofSeconds(2)); //connection timeout
|
||||
clientSettings.setLogLevel(Level.ALL); //log level
|
||||
clientSettings.setDownloadGiftInfo(true); //TODO
|
||||
clientSettings.setCheckForUnparsedData(true); //TODO
|
||||
clientSettings.setPollingInterval(Duration.ofSeconds(1)); //TODO
|
||||
clientSettings.setPrintMessageData(true); //TODO
|
||||
clientSettings.setPrintToConsole(true); //TODO
|
||||
clientSettings.setHandleExistingMessagesOnConnect(true); //TODO
|
||||
clientSettings.setRetryOnConnectionFailure(true); //TODO
|
||||
clientSettings.setHostName(Main.TEST_TIKTOK_USER); // TikTok user name
|
||||
clientSettings.setClientLanguage("en"); // Language
|
||||
clientSettings.setTimeout(Duration.ofSeconds(2)); // Connection timeout
|
||||
clientSettings.setLogLevel(Level.ALL); // Log level
|
||||
clientSettings.setDownloadGiftInfo(true); // Downloading meta information about gifts. You can access it by client.getGiftManager().getGiftsInfo();
|
||||
clientSettings.setPrintMessageData(true); // Printing TikTok Protocol buffer messages in Base64 format
|
||||
clientSettings.setPrintToConsole(true); // Printing all logs to console even if log level is Level.OFF
|
||||
clientSettings.setHandleExistingMessagesOnConnect(true); // Invokes all TikTok events that had occurred before connection
|
||||
clientSettings.setRetryOnConnectionFailure(true); // Reconnecting if TikTok user is offline
|
||||
clientSettings.setRetryConnectionTimeout(Duration.ofSeconds(1)); // Timeout before next reconnection
|
||||
})
|
||||
.buildAndRun();
|
||||
System.in.read();
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.events.messages.*;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static String TEST_TIKTOK_USER = "mr_cios";
|
||||
public static String TEST_TIKTOK_USER = "vadimpyrography";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
var client = TikTokLive.newClient(TEST_TIKTOK_USER)
|
||||
@@ -21,59 +22,59 @@ public class Main {
|
||||
.onLike(Main::onLike)
|
||||
.onGiftMessage(Main::onGiftMessage)
|
||||
.onEmote(Main::onEmote)
|
||||
.onError(tikTokErrorEvent ->
|
||||
.onError((_client, error) ->
|
||||
{
|
||||
// tikTokErrorEvent.getException().printStackTrace();
|
||||
error.getException().printStackTrace();
|
||||
})
|
||||
.buildAndRun();
|
||||
|
||||
|
||||
var viewers = client.getRoomInfo().getViewersCount();
|
||||
System.in.read();
|
||||
}
|
||||
|
||||
private static void onConnected(TikTokConnectedEvent e) {
|
||||
private static void onConnected(LiveClient tikTokLive, TikTokConnectedEvent e) {
|
||||
print("Connected");
|
||||
}
|
||||
|
||||
private static void onDisconnected(TikTokDisconnectedEvent e) {
|
||||
private static void onDisconnected(LiveClient tikTokLive, TikTokDisconnectedEvent e) {
|
||||
print("Disconnected");
|
||||
}
|
||||
|
||||
private static void onViewerData(TikTokRoomViewerDataEvent e) {
|
||||
private static void onViewerData(LiveClient tikTokLive, TikTokRoomViewerDataEvent e) {
|
||||
print("Viewer count is:", e.getViewerCount());
|
||||
}
|
||||
|
||||
private static void onJoin(TikTokJoinEvent e) {
|
||||
private static void onJoin(LiveClient tikTokLive, TikTokJoinEvent e) {
|
||||
print(e.getUser().getUniqueId(), "joined!");
|
||||
}
|
||||
|
||||
private static void onComment(TikTokCommentEvent e) {
|
||||
private static void onComment(LiveClient tikTokLive, TikTokCommentEvent e) {
|
||||
print(e.getUser().getUniqueId(), e.getText());
|
||||
}
|
||||
|
||||
private static void onFollow(TikTokFollowEvent e) {
|
||||
private static void onFollow(LiveClient tikTokLive, TikTokFollowEvent e) {
|
||||
print(e.getNewFollower().getUniqueId(), "followed!");
|
||||
}
|
||||
|
||||
private static void onShare(TikTokShareEvent e) {
|
||||
private static void onShare(LiveClient tikTokLive, TikTokShareEvent e) {
|
||||
print(e.getUser().getUniqueId(), "shared!");
|
||||
}
|
||||
|
||||
private static void onSubscribe(TikTokSubscribeEvent e) {
|
||||
private static void onSubscribe(LiveClient tikTokLive, TikTokSubscribeEvent e) {
|
||||
print(e.getNewSubscriber().getUniqueId(), "subscribed!");
|
||||
}
|
||||
|
||||
private static void onLike(TikTokLikeEvent e) {
|
||||
private static void onLike(LiveClient tikTokLive, TikTokLikeEvent e) {
|
||||
|
||||
print(e.getSender().getUniqueId(), "liked!");
|
||||
}
|
||||
|
||||
private static void onGiftMessage(TikTokGiftMessageEvent e) {
|
||||
private static void onGiftMessage(LiveClient tikTokLive, TikTokGiftMessageEvent e)
|
||||
{
|
||||
print(e.getSender().getUniqueId(), "sent", e.getAmount(), "x", e.getGift().getName());
|
||||
}
|
||||
|
||||
private static void onEmote(TikTokEmoteEvent e) {
|
||||
private static void onEmote(LiveClient tikTokLive, TikTokEmoteEvent e) {
|
||||
print(e.getUser().getUniqueId(), "sent", e.getEmoteId());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,21 +6,24 @@ public class SimpleExample {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
||||
.onConnected(event ->
|
||||
.onConnected((client, event) ->
|
||||
{
|
||||
System.out.println("Connected");
|
||||
})
|
||||
.onJoin(event ->
|
||||
.onJoin((client, event) ->
|
||||
{
|
||||
System.out.println("User joined -> " + event.getUser().getNickName());
|
||||
})
|
||||
.onComment(event ->
|
||||
.onComment((client, event) ->
|
||||
{
|
||||
System.out.println(event.getUser().getUniqueId() + ": " + event.getText());
|
||||
})
|
||||
.onError(event ->
|
||||
.onEvent((client, event) ->
|
||||
{
|
||||
System.out.println("Viewers count: "+client.getRoomInfo().getViewersCount());
|
||||
})
|
||||
.onError((client, event) ->
|
||||
{
|
||||
System.out.println("OTO tajeminica wiary");
|
||||
event.getException().printStackTrace();
|
||||
})
|
||||
.buildAndRun();
|
||||
|
||||
Reference in New Issue
Block a user