mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Breaking changes:
'Gift': changed from class to enum, so now you can handle
incoming gifts in switch
`Events`
- new:
onGiftComboFinished
- Removed:
onGiftBrodcast
- Rename:
onGiftMessage -> onGift
onRoomPinMessage -> onRoomPin
onRoomMessage -> onRoom
onLinkMessage -> onLink
onBarrageMessage -> onBarrage
onPollMessage -> onPoll
onShopMessage -> onShop
onDetectMessage -> onDetect
`GiftManager`
added:
registerGift
findById
findByName
getGifts
removed:
getActiveGifts
This commit is contained in:
@@ -25,5 +25,5 @@ package io.github.jwdeveloper.tiktok.annotations;
|
||||
|
||||
public enum EventType
|
||||
{
|
||||
Control, Message, Custom, Debug
|
||||
Control, Message, Debug
|
||||
}
|
||||
|
||||
@@ -29,6 +29,6 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
/**
|
||||
* Triggered when the live stream gets terminated by the host. Will also trigger the TikTokDisconnectedEvent event.
|
||||
*/
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLiveEndedEvent extends TikTokEvent {
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLivePausedEvent extends TikTokEvent {
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import lombok.Getter;
|
||||
* Triggers when a user creates a subscription.
|
||||
*/
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokSubscribeEvent extends TikTokHeaderEvent {
|
||||
private User user;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastControlMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokUnhandledControlEvent extends TikTokUnhandledEvent<WebcastControlMessage> {
|
||||
|
||||
public TikTokUnhandledControlEvent(WebcastControlMessage data) {
|
||||
|
||||
@@ -29,7 +29,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokUnhandledSocialEvent extends TikTokUnhandledEvent<WebcastSocialMessage>
|
||||
{
|
||||
public TikTokUnhandledSocialEvent(WebcastSocialMessage data) {
|
||||
|
||||
@@ -29,12 +29,11 @@ import io.github.jwdeveloper.tiktok.data.models.Gift;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
@Getter
|
||||
public class TikTokGiftComboFinishedEvent extends TikTokGiftEvent
|
||||
public class TikTokGiftComboEvent extends TikTokGiftEvent
|
||||
{
|
||||
|
||||
public TikTokGiftComboFinishedEvent(Gift gift, WebcastGiftMessage msg) {
|
||||
public TikTokGiftComboEvent(Gift gift, WebcastGiftMessage msg) {
|
||||
super(gift, msg);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
|
||||
/**
|
||||
/*
|
||||
* Triggered every time a gift arrives.
|
||||
*/
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
|
||||
@@ -31,7 +31,7 @@ import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
@Getter
|
||||
public class TikTokPollEndEvent extends TikTokPollEvent
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ import lombok.Getter;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokPollStartEvent extends TikTokPollEvent {
|
||||
|
||||
private final List<PollOption> options;
|
||||
|
||||
@@ -31,7 +31,7 @@ import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
@Getter
|
||||
public class TikTokPollUpdateEvent extends TikTokPollEvent {
|
||||
private final List<PollOption> options;
|
||||
|
||||
@@ -33,7 +33,7 @@ import lombok.Value;
|
||||
* Triggers when a user follows the streamer. Based on social event.
|
||||
*/
|
||||
@Value
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokFollowEvent extends TikTokHeaderEvent
|
||||
{
|
||||
User user;
|
||||
|
||||
@@ -31,7 +31,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokJoinEvent extends TikTokHeaderEvent {
|
||||
private final User user;
|
||||
private final int totalUsers;
|
||||
|
||||
@@ -35,7 +35,7 @@ import lombok.Getter;
|
||||
* Triggered when a viewer sends likes to the streamer. For streams with many viewers, this event is not always triggered by TikTok.
|
||||
*/
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLikeEvent extends TikTokHeaderEvent
|
||||
{
|
||||
private final User user;
|
||||
|
||||
@@ -33,7 +33,7 @@ import lombok.Getter;
|
||||
* Triggers when a user shares the stream. Based on social event.
|
||||
*/
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokShareEvent extends TikTokHeaderEvent {
|
||||
private final User user;
|
||||
private final int totalShares;
|
||||
|
||||
@@ -34,8 +34,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
public class Picture {
|
||||
@@ -67,21 +66,20 @@ public class Picture {
|
||||
if (isDownloaded()) {
|
||||
return image;
|
||||
}
|
||||
if (link.equalsIgnoreCase("")) {
|
||||
return null;
|
||||
}
|
||||
image = download(link);
|
||||
return image;
|
||||
}
|
||||
|
||||
public Future<Image> downloadImageAsync() {
|
||||
var executor = Executors.newSingleThreadExecutor();
|
||||
var future = executor.submit(this::downloadImage);
|
||||
executor.shutdown();
|
||||
return future;
|
||||
public CompletableFuture<Image> downloadImageAsync() {
|
||||
return CompletableFuture.supplyAsync(this::downloadImage);
|
||||
}
|
||||
|
||||
private BufferedImage download(String urlString) {
|
||||
private BufferedImage download(String urlString)
|
||||
{
|
||||
if(urlString.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var baos = new ByteArrayOutputStream();
|
||||
try (var is = new URL(urlString).openStream()) {
|
||||
var byteChunk = new byte[4096];
|
||||
@@ -105,8 +103,4 @@ public class Picture {
|
||||
public static Picture Empty() {
|
||||
return new Picture("");
|
||||
}
|
||||
|
||||
public static List<Picture> EmptyList() {
|
||||
return new ArrayList<Picture>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,18 +27,22 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Getter
|
||||
public class Text {
|
||||
String key;
|
||||
String pattern;
|
||||
List<TextPiece> textPieces;
|
||||
String value;
|
||||
|
||||
public Text(String key, String pattern, List<TextPiece> textPieces) {
|
||||
this.key = key;
|
||||
this.pattern = pattern;
|
||||
this.textPieces = textPieces;
|
||||
this.value = computeValue();
|
||||
}
|
||||
|
||||
public static Text map(io.github.jwdeveloper.tiktok.messages.data.Text input) {
|
||||
@@ -53,15 +57,31 @@ public class Text {
|
||||
var user = User.map(input.getUserValue().getUser());
|
||||
yield new UserTextPiece(user);
|
||||
}
|
||||
//case 12 -> new GiftTextPiece(input.getStringValue());
|
||||
case 12 -> new GiftTextPiece(input.getGiftValue().getGiftId());
|
||||
default -> new StringTextPiece(input.getStringValue());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private String computeValue() {
|
||||
var regexPattern = Pattern.compile("\\{.*?\\}");
|
||||
var matcher = regexPattern.matcher(pattern);
|
||||
var format = matcher.replaceAll("%s");
|
||||
|
||||
var output = new ArrayList<String>();
|
||||
for (var piece : textPieces) {
|
||||
output.add(piece.getText());
|
||||
}
|
||||
return String.format(format, output.toArray());
|
||||
}
|
||||
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class TextPiece {
|
||||
|
||||
public String getText() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Value
|
||||
@@ -79,13 +99,25 @@ public class Text {
|
||||
public UserTextPiece(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return user.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
public static class GiftTextPiece extends TextPiece {
|
||||
Gift gift;
|
||||
|
||||
public GiftTextPiece(String value) {
|
||||
int giftId;
|
||||
|
||||
public GiftTextPiece(int giftId) {
|
||||
this.giftId = giftId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return giftId + "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ package io.github.jwdeveloper.tiktok.live;
|
||||
import io.github.jwdeveloper.tiktok.listener.ListenersManager;
|
||||
import io.github.jwdeveloper.tiktok.listener.TikTokEventListener;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface LiveClient {
|
||||
@@ -34,6 +36,19 @@ public interface LiveClient {
|
||||
*/
|
||||
void connect();
|
||||
|
||||
|
||||
/**
|
||||
* Connects in asynchronous way
|
||||
* When connected Consumer returns instance of LiveClient
|
||||
*/
|
||||
void connectAsync(Consumer<LiveClient> onConnection);
|
||||
|
||||
/**
|
||||
* Connects in asynchronous way
|
||||
*/
|
||||
CompletableFuture<LiveClient> connectAsync();
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects the connection.
|
||||
*/
|
||||
@@ -45,12 +60,6 @@ public interface LiveClient {
|
||||
*/
|
||||
GiftManager getGiftManager();
|
||||
|
||||
/**
|
||||
* Get user manager
|
||||
* @return
|
||||
*/
|
||||
UserManager getUserManager();
|
||||
|
||||
/**
|
||||
* Gets the current room info from TikTok API including streamer info, room status and statistics.
|
||||
*/
|
||||
@@ -58,13 +67,13 @@ public interface LiveClient {
|
||||
|
||||
/**
|
||||
* Manage TikTokEventListener
|
||||
*
|
||||
* @see TikTokEventListener
|
||||
*/
|
||||
ListenersManager getListenersManager();
|
||||
|
||||
/**
|
||||
* Logger
|
||||
* @return
|
||||
* Logger
|
||||
*/
|
||||
Logger getLogger();
|
||||
}
|
||||
|
||||
@@ -26,15 +26,17 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LiveRoomMeta {
|
||||
/**
|
||||
* 0 - Unknown
|
||||
* 1 - ?
|
||||
* 2 - Online
|
||||
* 3 - ?
|
||||
* 4 - Offline
|
||||
*/
|
||||
|
||||
private int status;
|
||||
private LiveRoomStatus status;
|
||||
|
||||
private boolean ageRestricted;
|
||||
|
||||
|
||||
|
||||
public enum LiveRoomStatus
|
||||
{
|
||||
HostNotFound,
|
||||
HostOnline,
|
||||
HostOffline
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ package io.github.jwdeveloper.tiktok.live.builder;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftComboFinishedEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftComboEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomUserInfoEvent;
|
||||
@@ -37,7 +37,7 @@ import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketRespons
|
||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
||||
|
||||
|
||||
public interface EventBuilder<T> {
|
||||
public interface EventsBuilder<T> {
|
||||
|
||||
T onRoom(EventConsumer<TikTokRoomEvent> event);
|
||||
|
||||
@@ -45,15 +45,13 @@ public interface EventBuilder<T> {
|
||||
|
||||
T onComment(EventConsumer<TikTokCommentEvent> event);
|
||||
|
||||
|
||||
T onWebsocketMessage(EventConsumer<TikTokWebsocketMessageEvent> event);
|
||||
|
||||
T onWebsocketResponse(EventConsumer<TikTokWebsocketResponseEvent> event);
|
||||
|
||||
T onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> event);
|
||||
|
||||
|
||||
T onGiftCombo(EventConsumer<TikTokGiftComboFinishedEvent> event);
|
||||
T onGiftCombo(EventConsumer<TikTokGiftComboEvent> event);
|
||||
|
||||
T onGift(EventConsumer<TikTokGiftEvent> event);
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.live.builder;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.ClientSettings;
|
||||
@@ -7,7 +29,7 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface LiveClientBuilder extends EventBuilder<LiveClientBuilder> {
|
||||
public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
||||
LiveClientBuilder configure(Consumer<ClientSettings> consumer);
|
||||
|
||||
LiveClientBuilder addListener(TikTokEventListener listener);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class JsonUtil {
|
||||
}
|
||||
|
||||
if (fieldAttributes.getName().equals("common_")) {
|
||||
return true;
|
||||
// return true;
|
||||
}
|
||||
if (fieldAttributes.getName().equals("bytes")) {
|
||||
return true;
|
||||
|
||||
@@ -82,7 +82,7 @@ message Text {
|
||||
}
|
||||
|
||||
message TextPieceGift {
|
||||
int64 giftId = 1;
|
||||
int32 giftId = 1;
|
||||
// PatternRef nameRef = 2;
|
||||
// ShowType showType = 3; // Enum
|
||||
int64 colorId = 4;
|
||||
|
||||
Reference in New Issue
Block a user