Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/protoeditor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
{
EventType eventType();
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.data.events.envelop;

import io.github.jwdeveloper.tiktok.annotations.EventMeta;
import io.github.jwdeveloper.tiktok.annotations.EventType;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
import io.github.jwdeveloper.tiktok.data.models.Text;

import io.github.jwdeveloper.tiktok.data.models.chest.Chest;
import io.github.jwdeveloper.tiktok.data.models.users.User;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastEnvelopeMessage;
import lombok.Value;

import java.util.Date;


@EventMeta(eventType = EventType.Message)
@Value
public class TikTokChestEvent extends TikTokHeaderEvent {

/**
* Chest target
*/
Chest chest;

/**
* User that send a chest
*/
User user;

/**
* Time when chest has been open
*/
Date openedAt;

public TikTokChestEvent(Chest chest, WebcastEnvelopeMessage msg) {
super(msg.getCommon());
this.chest = chest;

var text = Text.map(msg.getCommon().getDisplayText());
var userPiece = (Text.UserTextPiece) text.getTextPieces().get(0);
user = userPiece.getUser();


var envelopInfo = msg.getEnvelopeInfo();

openedAt = new Date(envelopInfo.getUnpackAt());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

@Getter
Expand All @@ -45,6 +46,12 @@ public Text(String key, String pattern, List<TextPiece> textPieces) {
this.value = computeValue();
}


public <T extends TextPiece> Optional<TextPiece> getTextPiece(Class<T> type)
{
return textPieces.stream().filter(e -> e.getClass().equals(type)).findFirst();
}

public static Text map(io.github.jwdeveloper.tiktok.messages.data.Text input) {
var pieces = input.getPiecesListList().stream().map(Text::mapTextPiece).toList();
return new Text(input.getKey(), input.getDefaultPattern(), pieces);
Expand Down Expand Up @@ -98,6 +105,7 @@ public StringTextPiece(String text) {
}
}

@Value
public static class UserTextPiece extends TextPiece {
User user;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.jwdeveloper.tiktok.data.models.chest;


import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Chest {

/**
* Total diamonds inside the chest
*/
int totalDiamonds;

/**
* Total users participated in chest
*/
int totalUsers;



}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ public interface TikTokHttpRequest {
String get(String url);

String post(String url);

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
public class LiveRoomMeta {

private LiveRoomStatus status;

private boolean ageRestricted;



public enum LiveRoomStatus
{
HostNotFound,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
import io.github.jwdeveloper.tiktok.data.events.*;
import io.github.jwdeveloper.tiktok.data.events.envelop.TikTokChestEvent;
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;
Expand Down Expand Up @@ -51,6 +52,9 @@ public interface EventsBuilder<T> {

T onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> event);




T onGiftCombo(EventConsumer<TikTokGiftComboEvent> event);
T onGift(EventConsumer<TikTokGiftEvent> event);

Expand All @@ -69,6 +73,8 @@ public interface EventsBuilder<T> {
T onShare(EventConsumer<TikTokShareEvent> event);
T onUnhandledSocial(EventConsumer<TikTokUnhandledSocialEvent> event);

T onChestOpen(EventConsumer<TikTokChestEvent> event);

T onLivePaused(EventConsumer<TikTokLivePausedEvent> event);

T onLiveEnded(EventConsumer<TikTokLiveEndedEvent> event);
Expand All @@ -80,10 +86,11 @@ public interface EventsBuilder<T> {
T onDisconnected(EventConsumer<TikTokDisconnectedEvent> event);

T onError(EventConsumer<TikTokErrorEvent> event);

T onEvent(EventConsumer<TikTokEvent> event);




// TODO Figure out how those events works
//T onLinkMicFanTicket(TikTokEventConsumer<TikTokLinkMicFanTicketEvent> event);

Expand Down
25 changes: 25 additions & 0 deletions API/src/main/proto/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,29 @@ enum BarrageType
FansLevelUpgrade = 10;
FansLevelEntrance = 11;
GamePartnership = 12;
}

enum EnvelopeBusinessType
{
BusinessTypeUnknown = 0;
BusinessTypeUserDiamond = 1;
BusinessTypePlatformDiamond = 2;
BusinessTypePlatformShell = 3;
BusinessTypePortal = 4;
BusinessTypePlatformMerch = 5;
BusinessTypeEoYDiamond = 6;
BusinessTypeFanClubGtM = 7;
}
enum EnvelopeFollowShowStatus
{
EnvelopeFollowShowUnknown = 0;
EnvelopeFollowShow = 1;
EnvelopeFollowNotShow = 2;
}

enum EnvelopeDisplay
{
EnvelopeDisplayUnknown = 0;
EnvelopeDisplayNew = 1;
EnvelopeDisplayHide = 2;
}
6 changes: 3 additions & 3 deletions API/src/main/proto/webcast.proto
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ message WebcastEmoteChatMessage {
message WebcastEnvelopeMessage {
Common common = 1;
EnvelopeInfo envelopeInfo = 2;
int64 display = 3; // @warning Enum not found, should be Display
EnvelopeDisplay display = 3; // @warning Enum not found, should be Display

// @EnvelopeInfo
// proto.webcast.im.EnvelopeMessage
message EnvelopeInfo {
string envelopeId = 1;
int64 businessType = 2; // @warning Enum not found, should be BusinessType
EnvelopeBusinessType businessType = 2;
string envelopeIdc = 3;
string sendUserName = 4;
int32 diamondCount = 5;
Expand All @@ -262,7 +262,7 @@ message WebcastEnvelopeMessage {
Image sendUserAvatar = 9;
string createAt = 10;
string roomId = 11;
int64 followShowStatus = 12; // @warning Enum not found, should be FollowShowStatus
EnvelopeFollowShowStatus followShowStatus = 12; // @warning Enum not found, should be FollowShowStatus
int32 skinId = 13;
}
}
Expand Down
13 changes: 13 additions & 0 deletions Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLive.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@
package io.github.jwdeveloper.tiktok;


import io.github.jwdeveloper.tiktok.http.TikTokLiveOnlineChecker;
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;

import java.util.concurrent.CompletableFuture;

public class TikTokLive
{
public static LiveClientBuilder newClient(String hostName)
{
return new TikTokLiveClientBuilder(hostName);
}

public static boolean isLiveOnline(String hostName)
{
return new TikTokLiveOnlineChecker().isOnline(hostName);
}

public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName)
{
return new TikTokLiveOnlineChecker().isOnlineAsync(hostName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import io.github.jwdeveloper.tiktok.data.events.*;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
import io.github.jwdeveloper.tiktok.data.events.envelop.TikTokChestEvent;
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.poll.TikTokPollEvent;
Expand Down Expand Up @@ -135,6 +136,7 @@ public String format(LogRecord record) {
}



}

public LiveClient build() {
Expand All @@ -148,7 +150,7 @@ public LiveClient build() {
var requestFactory = new TikTokHttpRequestFactory(cookieJar);
var apiClient = new TikTokHttpClient(cookieJar, requestFactory);
var apiService = new TikTokApiService(apiClient, logger, clientSettings);
var giftManager = new TikTokGiftManager();
var giftManager = new TikTokGiftManager(logger);
var eventMapper = new TikTokGenericEventMapper();
var giftHandler = new TikTokGiftEventHandler(giftManager);

Expand Down Expand Up @@ -190,6 +192,12 @@ public TikTokLiveClientBuilder onUnhandledSocial(
return this;
}

@Override
public LiveClientBuilder onChestOpen(EventConsumer<TikTokChestEvent> event) {
tikTokEventHandler.subscribe(TikTokChestEvent.class, event);
return this;
}

public TikTokLiveClientBuilder onLinkMicFanTicket(
EventConsumer<TikTokLinkMicFanTicketEvent> event) {
tikTokEventHandler.subscribe(TikTokLinkMicFanTicketEvent.class, event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,29 @@
*/
package io.github.jwdeveloper.tiktok;

import io.github.jwdeveloper.tiktok.data.models.Picture;
import io.github.jwdeveloper.tiktok.messages.data.User;
import io.github.jwdeveloper.tiktok.models.ConnectionState;
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
import lombok.Data;

@Data
public class TikTokRoomInfo implements LiveRoomInfo
{
private String roomId;

private int likesCount;

private int viewersCount;

private String roomId;

private boolean ageRestricted;

private User host;

private Picture picture;

private String description;

private String hostName;

private ConnectionState connectionState = ConnectionState.DISCONNECTED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@
import io.github.jwdeveloper.tiktok.live.GiftManager;
import sun.misc.Unsafe;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.logging.Logger;

public class TikTokGiftManager implements GiftManager {

private final Map<Integer, Gift> indexById;
private final Map<String, Gift> indexByName;
private final Logger logger;

public TikTokGiftManager() {
public TikTokGiftManager(Logger logger)
{
indexById = new HashMap<>();
indexByName = new HashMap<>();
this.logger = logger;
init();
}

Expand All @@ -66,6 +70,17 @@ public Gift registerGift(int id, String name, int diamondCost, Picture picture)
field.set(enumInstance, name);


Arrays.stream(Gift.class.getSuperclass().getDeclaredFields()).toList().forEach(field1 ->
{
System.out.println(field1.getName()+" ");
});


field = Gift.class.getSuperclass().getDeclaredField("name");
field.setAccessible(true);
field.set(enumInstance,"dupa");

// EnumSet
field = Gift.class.getDeclaredField("diamondCost");
field.setAccessible(true);
field.set(enumInstance, diamondCost);
Expand Down
Loading