This commit is contained in:
JW
2024-02-21 22:47:29 +01:00
parent 1b2a8bad93
commit 0252b9a42f
15 changed files with 1473 additions and 1464 deletions

2
.gitignore vendored
View File

@@ -1,5 +1,7 @@
backend-infrastructure/.aws-sam backend-infrastructure/.aws-sam
.db
# Created by https://www.gitignore.io/api/osx,linux,python,windows,pycharm,visualstudiocode # Created by https://www.gitignore.io/api/osx,linux,python,windows,pycharm,visualstudiocode
*.db *.db
### Linux ### ### Linux ###

View File

@@ -24,7 +24,7 @@ package io.github.jwdeveloper.tiktok.data.events.gift;
import io.github.jwdeveloper.tiktok.annotations.EventMeta; import io.github.jwdeveloper.tiktok.annotations.EventMeta;
import io.github.jwdeveloper.tiktok.annotations.EventType; import io.github.jwdeveloper.tiktok.annotations.EventType;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift; import io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld;
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftSendType; import io.github.jwdeveloper.tiktok.data.models.gifts.GiftSendType;
import io.github.jwdeveloper.tiktok.data.models.users.User; import io.github.jwdeveloper.tiktok.data.models.users.User;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage; import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
@@ -49,7 +49,7 @@ import lombok.Getter;
public class TikTokGiftComboEvent extends TikTokGiftEvent { public class TikTokGiftComboEvent extends TikTokGiftEvent {
private final GiftSendType comboState; private final GiftSendType comboState;
public TikTokGiftComboEvent(Gift gift, User host, WebcastGiftMessage msg, GiftSendType comboState) { public TikTokGiftComboEvent(GiftOld gift, User host, WebcastGiftMessage msg, GiftSendType comboState) {
super(gift, host, msg); super(gift, host, msg);
this.comboState = comboState; this.comboState = comboState;
} }

View File

@@ -26,15 +26,11 @@ package io.github.jwdeveloper.tiktok.data.events.gift;
import io.github.jwdeveloper.tiktok.annotations.EventMeta; import io.github.jwdeveloper.tiktok.annotations.EventMeta;
import io.github.jwdeveloper.tiktok.annotations.EventType; import io.github.jwdeveloper.tiktok.annotations.EventType;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent; import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
import io.github.jwdeveloper.tiktok.data.models.Picture; import io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftSendType;
import io.github.jwdeveloper.tiktok.data.models.users.User; import io.github.jwdeveloper.tiktok.data.models.users.User;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage; import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
/** /**
* Triggered when user sends gifts that has * Triggered when user sends gifts that has
@@ -44,12 +40,12 @@ import java.util.ArrayList;
@EventMeta(eventType = EventType.Message) @EventMeta(eventType = EventType.Message)
@Getter @Getter
public class TikTokGiftEvent extends TikTokHeaderEvent { public class TikTokGiftEvent extends TikTokHeaderEvent {
private final Gift gift; private final GiftOld gift;
private final User user; private final User user;
private final User toUser; private final User toUser;
private final int combo; private final int combo;
public TikTokGiftEvent(Gift gift, User liveHost, WebcastGiftMessage msg) { public TikTokGiftEvent(GiftOld gift, User liveHost, WebcastGiftMessage msg) {
super(msg.getCommon()); super(msg.getCommon());
this.gift = gift; this.gift = gift;
user = User.map(msg.getUser(), msg.getUserIdentity()); user = User.map(msg.getUser(), msg.getUserIdentity());

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,6 @@
*/ */
package io.github.jwdeveloper.tiktok.data.requests; package io.github.jwdeveloper.tiktok.data.requests;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.Getter; import lombok.Getter;

View File

@@ -22,7 +22,7 @@
*/ */
package io.github.jwdeveloper.tiktok.live; package io.github.jwdeveloper.tiktok.live;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift; import io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld;
import io.github.jwdeveloper.tiktok.data.models.Picture; import io.github.jwdeveloper.tiktok.data.models.Picture;
import java.util.List; import java.util.List;
@@ -38,7 +38,7 @@ public interface GiftManager {
* @param diamondCost diamond cost * @param diamondCost diamond cost
* @return * @return
*/ */
Gift registerGift(int id, String name, int diamondCost, Picture picture); GiftOld registerGift(int id, String name, int diamondCost, Picture picture);
/** /**
@@ -46,18 +46,18 @@ public interface GiftManager {
* @param giftId * @param giftId
* @return * @return
*/ */
Gift findById(int giftId); GiftOld findById(int giftId);
/** /**
* *
* @param giftName * @param giftName
* @return * @return
*/ */
Gift findByName(String giftName); GiftOld findByName(String giftName);
/** /**
* *
* @return all gifts * @return all gifts
*/ */
List<Gift> getGifts(); List<GiftOld> getGifts();
} }

View File

@@ -23,7 +23,7 @@
package io.github.jwdeveloper.tiktok.gifts; package io.github.jwdeveloper.tiktok.gifts;
import io.github.jwdeveloper.tiktok.data.models.Picture; import io.github.jwdeveloper.tiktok.data.models.Picture;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift; import io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld;
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException; import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
import io.github.jwdeveloper.tiktok.live.GiftManager; import io.github.jwdeveloper.tiktok.live.GiftManager;
import sun.misc.Unsafe; import sun.misc.Unsafe;
@@ -33,8 +33,8 @@ import java.util.logging.Logger;
public class TikTokGiftManager implements GiftManager { public class TikTokGiftManager implements GiftManager {
private final Map<Integer, Gift> indexById; private final Map<Integer, GiftOld> indexById;
private final Map<String, Gift> indexByName; private final Map<String, GiftOld> indexByName;
private final Logger logger; private final Logger logger;
public TikTokGiftManager(Logger logger) public TikTokGiftManager(Logger logger)
@@ -46,34 +46,34 @@ public class TikTokGiftManager implements GiftManager {
} }
protected void init() { protected void init() {
for (var gift : Gift.values()) { for (var gift : GiftOld.values()) {
indexById.put(gift.getId(), gift); indexById.put(gift.getId(), gift);
indexByName.put(gift.getName(), gift); indexByName.put(gift.getName(), gift);
} }
} }
public Gift registerGift(int id, String name, int diamondCost, Picture picture) { public GiftOld registerGift(int id, String name, int diamondCost, Picture picture) {
try { try {
var constructor = Unsafe.class.getDeclaredConstructors()[0]; var constructor = Unsafe.class.getDeclaredConstructors()[0];
constructor.setAccessible(true); constructor.setAccessible(true);
var unsafe = (Unsafe) constructor.newInstance(); var unsafe = (Unsafe) constructor.newInstance();
Gift enumInstance = (Gift) unsafe.allocateInstance(Gift.class); GiftOld enumInstance = (GiftOld) unsafe.allocateInstance(GiftOld.class);
var field = Gift.class.getDeclaredField("id"); var field = GiftOld.class.getDeclaredField("id");
field.setAccessible(true); field.setAccessible(true);
field.set(enumInstance, id); field.set(enumInstance, id);
field = Gift.class.getDeclaredField("name"); field = GiftOld.class.getDeclaredField("name");
field.setAccessible(true); field.setAccessible(true);
field.set(enumInstance, name); field.set(enumInstance, name);
// EnumSet // EnumSet
field = Gift.class.getDeclaredField("diamondCost"); field = GiftOld.class.getDeclaredField("diamondCost");
field.setAccessible(true); field.setAccessible(true);
field.set(enumInstance, diamondCost); field.set(enumInstance, diamondCost);
field = Gift.class.getDeclaredField("picture"); field = GiftOld.class.getDeclaredField("picture");
field.setAccessible(true); field.setAccessible(true);
field.set(enumInstance, picture); field.set(enumInstance, picture);
@@ -86,18 +86,18 @@ public class TikTokGiftManager implements GiftManager {
} }
} }
public Gift findById(int giftId) { public GiftOld findById(int giftId) {
Gift gift = indexById.get(giftId); GiftOld gift = indexById.get(giftId);
return gift == null ? Gift.UNDEFINED : gift; return gift == null ? GiftOld.UNDEFINED : gift;
} }
public Gift findByName(String giftName) { public GiftOld findByName(String giftName) {
Gift gift = indexByName.get(giftName); GiftOld gift = indexByName.get(giftName);
return gift == null ? Gift.UNDEFINED : gift; return gift == null ? GiftOld.UNDEFINED : gift;
} }
@Override @Override
public List<Gift> getGifts() { public List<GiftOld> getGifts() {
return indexById.values().stream().toList(); return indexById.values().stream().toList();
} }
} }

View File

@@ -27,7 +27,7 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftComboEvent; 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.gift.TikTokGiftEvent;
import io.github.jwdeveloper.tiktok.data.models.Picture; import io.github.jwdeveloper.tiktok.data.models.Picture;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift; import io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld;
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftSendType; import io.github.jwdeveloper.tiktok.data.models.gifts.GiftSendType;
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException; import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
import io.github.jwdeveloper.tiktok.live.GiftManager; import io.github.jwdeveloper.tiktok.live.GiftManager;
@@ -112,13 +112,13 @@ public class TikTokGiftEventHandler {
return new TikTokGiftComboEvent(gift, tikTokRoomInfo.getHost(), message, state); return new TikTokGiftComboEvent(gift, tikTokRoomInfo.getHost(), message, state);
} }
private Gift getGiftObject(WebcastGiftMessage giftMessage) { private GiftOld getGiftObject(WebcastGiftMessage giftMessage) {
var giftId = (int) giftMessage.getGiftId(); var giftId = (int) giftMessage.getGiftId();
var gift = giftManager.findById(giftId); var gift = giftManager.findById(giftId);
if (gift == Gift.UNDEFINED) { if (gift == GiftOld.UNDEFINED) {
gift = giftManager.findByName(giftMessage.getGift().getName()); gift = giftManager.findByName(giftMessage.getGift().getName());
} }
if (gift == Gift.UNDEFINED) { if (gift == GiftOld.UNDEFINED) {
gift = giftManager.registerGift( gift = giftManager.registerGift(
giftId, giftId,
giftMessage.getGift().getName(), giftMessage.getGift().getName(),
@@ -133,12 +133,12 @@ public class TikTokGiftEventHandler {
} }
private void updatePicture(Gift gift, WebcastGiftMessage webcastGiftMessage) { private void updatePicture(GiftOld gift, WebcastGiftMessage webcastGiftMessage) {
try { try {
var picture = Picture.map(webcastGiftMessage.getGift().getImage()); var picture = Picture.map(webcastGiftMessage.getGift().getImage());
var constructor = Unsafe.class.getDeclaredConstructors()[0]; var constructor = Unsafe.class.getDeclaredConstructors()[0];
constructor.setAccessible(true); constructor.setAccessible(true);
var field = Gift.class.getDeclaredField("picture"); var field = GiftOld.class.getDeclaredField("picture");
field.setAccessible(true); field.setAccessible(true);
field.set(gift, picture); field.set(gift, picture);
} catch (Exception e) { } catch (Exception e) {

View File

@@ -22,7 +22,7 @@
*/ */
package io.github.jwdeveloper.tiktok.gifts; package io.github.jwdeveloper.tiktok.gifts;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift; import io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld;
import io.github.jwdeveloper.tiktok.data.models.Picture; import io.github.jwdeveloper.tiktok.data.models.Picture;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -65,7 +65,7 @@ public class TikTokGiftManagerTest {
@Test @Test
void getGifts() { void getGifts() {
Assertions.assertEquals(Gift.values().length, giftManager.getGifts().size()); Assertions.assertEquals(GiftOld.values().length, giftManager.getGifts().size());
} }

View File

@@ -23,24 +23,22 @@
package io.github.jwdeveloper.tiktok; package io.github.jwdeveloper.tiktok;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent; import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
import io.github.jwdeveloper.tiktok.data.models.Picture; import io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
import io.github.jwdeveloper.tiktok.live.GiftManager;
import io.github.jwdeveloper.tiktok.live.LiveClient;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
public class CustomEventExample { public class CustomEventExample {
@AllArgsConstructor @AllArgsConstructor
public static class CheapGiftEvent extends TikTokEvent { public static class CheapGiftEvent extends TikTokEvent {
Gift gift; GiftOld gift;
} }
@AllArgsConstructor @AllArgsConstructor
public static class ExpensiveGiftEvent extends TikTokEvent { public static class ExpensiveGiftEvent extends TikTokEvent {
Gift gift; GiftOld gift;
} }
public static void main(String[] args) { public static void main(String[] args)
{
TikTokLive.newClient(SimpleExample.TIKTOK_HOSTNAME) TikTokLive.newClient(SimpleExample.TIKTOK_HOSTNAME)
.configure(clientSettings -> .configure(clientSettings ->
{ {

View File

@@ -22,11 +22,6 @@
*/ */
package io.github.jwdeveloper.tiktok.webviewer; package io.github.jwdeveloper.tiktok.webviewer;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkLayerMessage;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
import io.github.jwdeveloper.tiktok.tools.TikTokLiveTools; import io.github.jwdeveloper.tiktok.tools.TikTokLiveTools;
import java.io.IOException; import java.io.IOException;

View File

@@ -83,7 +83,7 @@ Are you willing to help or improve TikTokLiveJava?
#### Tools #### Tools
Project that contains code generators. Project that contains code generators.
The most useful one is class `GenerateGiftsEnum` that download gifts json from TikTok The most useful one is class `GenerateGiftsEnum` that download gifts json from TikTok
and generates code for `Gift` enum that is later added to `API` module at path `io.github.jwdeveloper.tiktok.data.models.gifts.Gift` and generates code for `Gift` enum that is later added to `API` module at path `io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld`
#### Tools-EventsCollector #### Tools-EventsCollector
Tool that can be used to store all `protocol-buffer` and `events` from live to `sqlLite` database or `Json` file Tool that can be used to store all `protocol-buffer` and `events` from live to `sqlLite` database or `Json` file

Binary file not shown.

View File

@@ -26,6 +26,5 @@ import io.github.jwdeveloper.tiktok.listener.TikTokEventListener;
public interface LiveRecorder extends TikTokEventListener { public interface LiveRecorder extends TikTokEventListener {
void pause();
void unpause();
} }