mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
25 Commits
1.0.11-Rel
...
1.0.15-Rel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1308b86567 | ||
|
|
20ba88c0ac | ||
|
|
77533ea4be | ||
|
|
3231924f8f | ||
|
|
ea525470e2 | ||
|
|
b0bf4ac606 | ||
|
|
0b9f1570d0 | ||
|
|
7a4c7fecbd | ||
|
|
0ae9068858 | ||
|
|
8905958207 | ||
|
|
c12f3cc4dc | ||
|
|
7402899f52 | ||
|
|
1b8b150d61 | ||
|
|
b2305b7bed | ||
|
|
7b911838a2 | ||
|
|
e44cb71869 | ||
|
|
af8c689417 | ||
|
|
81ac92fb33 | ||
|
|
34a78b5435 | ||
|
|
534cb7906d | ||
|
|
0bb8edfe5c | ||
|
|
4979c1b27a | ||
|
|
f7c8ffdaa5 | ||
|
|
c1fda687d3 | ||
|
|
05c49c4545 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,10 +1,10 @@
|
|||||||
backend-infrastructure/.aws-sam
|
backend-infrastructure/.aws-sam
|
||||||
|
|
||||||
# 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
|
||||||
### Linux ###
|
### Linux ###
|
||||||
*~
|
*~
|
||||||
|
.db
|
||||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
.fuse_hidden*
|
.fuse_hidden*
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.0.10-Release</version>
|
<version>1.0.14-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ public class TikTokUserInfo
|
|||||||
|
|
||||||
String roomId;
|
String roomId;
|
||||||
|
|
||||||
|
long startTime;
|
||||||
|
|
||||||
public enum UserStatus
|
public enum UserStatus
|
||||||
{
|
{
|
||||||
NotFound,
|
NotFound,
|
||||||
@@ -40,4 +42,4 @@ public class TikTokUserInfo
|
|||||||
LivePaused,
|
LivePaused,
|
||||||
Live
|
Live
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,7 @@ 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.Gift;
|
||||||
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.messages.webcast.WebcastGiftMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ import lombok.Getter;
|
|||||||
* <p>Combo: 4 -> comboState = GiftSendType.Active</p>
|
* <p>Combo: 4 -> comboState = GiftSendType.Active</p>
|
||||||
* <p>Combo: 8 -> comboState = GiftSendType.Active</p>
|
* <p>Combo: 8 -> comboState = GiftSendType.Active</p>
|
||||||
* <p>Combo: 12 -> comboState = GiftSendType.Finsihed</p>
|
* <p>Combo: 12 -> comboState = GiftSendType.Finsihed</p>
|
||||||
*
|
* <p>
|
||||||
* Remember if comboState is Finsihed both TikTokGiftComboEvent and TikTokGiftEvent event gets triggered
|
* Remember if comboState is Finsihed both TikTokGiftComboEvent and TikTokGiftEvent event gets triggered
|
||||||
*/
|
*/
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
@@ -48,8 +49,8 @@ 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, WebcastGiftMessage msg, GiftSendType comboState) {
|
public TikTokGiftComboEvent(Gift gift, User host, WebcastGiftMessage msg, GiftSendType comboState) {
|
||||||
super(gift, msg);
|
super(gift, host, msg);
|
||||||
this.comboState = comboState;
|
this.comboState = comboState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,15 @@ public class TikTokGiftEvent extends TikTokHeaderEvent {
|
|||||||
private final User toUser;
|
private final User toUser;
|
||||||
private final int combo;
|
private final int combo;
|
||||||
|
|
||||||
public TikTokGiftEvent(Gift gift, WebcastGiftMessage msg) {
|
public TikTokGiftEvent(Gift 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());
|
||||||
toUser = new User(msg.getUserGiftReciever().getUserId(), "", "", new Picture(""), 0, 0, new ArrayList<>());
|
if (msg.getToUser().getNickname().isEmpty()) {
|
||||||
|
toUser = liveHost;
|
||||||
|
} else {
|
||||||
|
toUser = User.map(msg.getToUser());
|
||||||
|
}
|
||||||
combo = msg.getComboCount();
|
combo = msg.getComboCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.data.events.http;
|
package io.github.jwdeveloper.tiktok.data.events.http;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||||
|
|||||||
@@ -28,15 +28,10 @@ import lombok.Getter;
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
public class Picture {
|
public class Picture {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -49,7 +44,6 @@ public class Picture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Picture map(io.github.jwdeveloper.tiktok.messages.data.Image profilePicture) {
|
public static Picture map(io.github.jwdeveloper.tiktok.messages.data.Image profilePicture) {
|
||||||
|
|
||||||
var index = profilePicture.getUrlListCount() - 1;
|
var index = profilePicture.getUrlListCount() - 1;
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return new Picture("");
|
return new Picture("");
|
||||||
@@ -74,12 +68,11 @@ public class Picture {
|
|||||||
return CompletableFuture.supplyAsync(this::downloadImage);
|
return CompletableFuture.supplyAsync(this::downloadImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage download(String urlString)
|
private BufferedImage download(String urlString) {
|
||||||
{
|
if (urlString.isEmpty()) {
|
||||||
if(urlString.isEmpty())
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var baos = new ByteArrayOutputStream();
|
var baos = new ByteArrayOutputStream();
|
||||||
try (var is = new URL(urlString).openStream()) {
|
try (var is = new URL(urlString).openStream()) {
|
||||||
var byteChunk = new byte[4096];
|
var byteChunk = new byte[4096];
|
||||||
@@ -103,4 +96,9 @@ public class Picture {
|
|||||||
public static Picture Empty() {
|
public static Picture Empty() {
|
||||||
return new Picture("");
|
return new Picture("");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Picture{link='" + link + "', image=" + image + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,6 +37,4 @@ public class Badge {
|
|||||||
public static Badge empty() {
|
public static Badge empty() {
|
||||||
return new Badge();
|
return new Badge();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -24,19 +24,22 @@ package io.github.jwdeveloper.tiktok.data.models.badges;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class CombineBadge extends Badge {
|
public class CombineBadge extends Badge {
|
||||||
private final Picture picture;
|
private final Picture picture;
|
||||||
private final String text;
|
private final String text;
|
||||||
private final String subText;
|
private final String subText;
|
||||||
|
|
||||||
|
|
||||||
public CombineBadge(BadgeStruct.CombineBadge combineBadge) {
|
public CombineBadge(BadgeStruct.CombineBadge combineBadge) {
|
||||||
|
|
||||||
picture = Picture.map(combineBadge.getIcon());
|
picture = Picture.map(combineBadge.getIcon());
|
||||||
text = combineBadge.getText().getDefaultPattern();
|
text = combineBadge.getText().getDefaultPattern();
|
||||||
subText = combineBadge.getStr();
|
subText = combineBadge.getStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
}
|
public String toString() {
|
||||||
|
return "CombineBadge{picture=" + picture +", text='" + text + "', subText='" + subText + "'}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,12 +24,18 @@ package io.github.jwdeveloper.tiktok.data.models.badges;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class PictureBadge extends Badge {
|
public class PictureBadge extends Badge {
|
||||||
|
|
||||||
private final Picture picture;
|
private final Picture picture;
|
||||||
public PictureBadge(BadgeStruct.ImageBadge imageBadge) {
|
|
||||||
|
|
||||||
|
public PictureBadge(BadgeStruct.ImageBadge imageBadge) {
|
||||||
picture = Picture.map(imageBadge.getImage());
|
picture = Picture.map(imageBadge.getImage());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PictureBadge{picture=" + picture + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,12 +23,18 @@
|
|||||||
package io.github.jwdeveloper.tiktok.data.models.badges;
|
package io.github.jwdeveloper.tiktok.data.models.badges;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class StringBadge extends Badge {
|
public class StringBadge extends Badge {
|
||||||
|
private final String text;
|
||||||
|
|
||||||
public String text;
|
|
||||||
public StringBadge(BadgeStruct.StringBadge stringBadge) {
|
public StringBadge(BadgeStruct.StringBadge stringBadge) {
|
||||||
|
|
||||||
this.text = stringBadge.getStr();
|
this.text = stringBadge.getStr();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "StringBadge{text='" + text + "'}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,13 +23,18 @@
|
|||||||
package io.github.jwdeveloper.tiktok.data.models.badges;
|
package io.github.jwdeveloper.tiktok.data.models.badges;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public class TextBadge extends Badge
|
@Getter
|
||||||
{
|
public class TextBadge extends Badge {
|
||||||
private final String text;
|
private final String text;
|
||||||
|
|
||||||
public TextBadge(BadgeStruct.TextBadge textBadge)
|
public TextBadge(BadgeStruct.TextBadge textBadge) {
|
||||||
{
|
|
||||||
this.text = textBadge.getDefaultPattern();
|
this.text = textBadge.getDefaultPattern();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TextBadge{text='" + text + "'}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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.data.models.http;
|
package io.github.jwdeveloper.tiktok.data.models.http;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|||||||
@@ -43,13 +43,12 @@ public class User {
|
|||||||
private long followers;
|
private long followers;
|
||||||
private List<Badge> badges;
|
private List<Badge> badges;
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private Set<UserAttribute> attributes;
|
private final Set<UserAttribute> attributes = new HashSet<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<UserAttribute> getAttributes() {
|
public List<UserAttribute> getAttributes() {
|
||||||
return attributes.stream().toList();
|
return attributes.stream().toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAttribute(UserAttribute userFlag) {
|
public boolean hasAttribute(UserAttribute userFlag) {
|
||||||
return attributes.contains(userFlag);
|
return attributes.contains(userFlag);
|
||||||
}
|
}
|
||||||
@@ -106,7 +105,6 @@ public class User {
|
|||||||
this.following = following;
|
this.following = following;
|
||||||
this.followers = followers;
|
this.followers = followers;
|
||||||
this.badges = badges;
|
this.badges = badges;
|
||||||
this.attributes = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User(Long id,
|
public User(Long id,
|
||||||
@@ -123,14 +121,12 @@ public class User {
|
|||||||
this.following = following;
|
this.following = following;
|
||||||
this.followers = followers;
|
this.followers = followers;
|
||||||
this.badges = badges;
|
this.badges = badges;
|
||||||
this.attributes = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User(Long userId,
|
public User(Long userId,
|
||||||
String nickName) {
|
String nickName) {
|
||||||
this.id = userId;
|
this.id = userId;
|
||||||
this.name = nickName;
|
this.name = nickName;
|
||||||
this.attributes = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User(Long userId,
|
public User(Long userId,
|
||||||
@@ -213,4 +209,4 @@ public class User {
|
|||||||
0,
|
0,
|
||||||
List.of(Badge.empty()));
|
List.of(Badge.empty()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ public interface LiveClient {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You to manually trigger event
|
* Use to manually invoke event
|
||||||
*/
|
*/
|
||||||
void publishEvent(TikTokEvent event);
|
void publishEvent(TikTokEvent event);
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ public interface LiveRoomInfo
|
|||||||
*/
|
*/
|
||||||
int getTotalViewersCount();
|
int getTotalViewersCount();
|
||||||
int getLikesCount();
|
int getLikesCount();
|
||||||
|
long getStartTime();
|
||||||
boolean isAgeRestricted();
|
boolean isAgeRestricted();
|
||||||
String getRoomId();
|
String getRoomId();
|
||||||
String getHostName();
|
String getHostName();
|
||||||
@@ -49,4 +50,4 @@ public interface LiveRoomInfo
|
|||||||
User getHostUser();
|
User getHostUser();
|
||||||
List<RankingUser> getUsersRanking();
|
List<RankingUser> getUsersRanking();
|
||||||
ConnectionState getConnectionState();
|
ConnectionState getConnectionState();
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,9 @@ public interface TikTokMapper {
|
|||||||
|
|
||||||
TikTokMapperModel forMessage(Class<? extends GeneratedMessageV3> mapperName, Function<byte[], TikTokEvent> onMapping);
|
TikTokMapperModel forMessage(Class<? extends GeneratedMessageV3> mapperName, Function<byte[], TikTokEvent> onMapping);
|
||||||
|
|
||||||
|
TikTokMapperModel forAnyMessage();
|
||||||
|
|
||||||
|
|
||||||
boolean isRegistered(String mapperName);
|
boolean isRegistered(String mapperName);
|
||||||
|
|
||||||
<T extends GeneratedMessageV3> boolean isRegistered(Class<T> mapperName);
|
<T extends GeneratedMessageV3> boolean isRegistered(Class<T> mapperName);
|
||||||
|
|||||||
@@ -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.mappers;
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
import com.google.protobuf.GeneratedMessageV3;
|
import com.google.protobuf.GeneratedMessageV3;
|
||||||
|
|||||||
@@ -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.mappers;
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
|||||||
@@ -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.mappers.data;
|
package io.github.jwdeveloper.tiktok.mappers.data;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
|||||||
@@ -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.mappers.data;
|
package io.github.jwdeveloper.tiktok.mappers.data;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
||||||
|
|||||||
@@ -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.mappers.data;
|
package io.github.jwdeveloper.tiktok.mappers.data;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ message WebcastPushFrame {
|
|||||||
uint64 LogId = 2;
|
uint64 LogId = 2;
|
||||||
uint64 Service = 3;
|
uint64 Service = 3;
|
||||||
uint64 Method = 4;
|
uint64 Method = 4;
|
||||||
map<string,string> headers = 5;
|
map<string, string> headers = 5;
|
||||||
string PayloadEncoding = 6;
|
string PayloadEncoding = 6;
|
||||||
string PayloadType = 7;
|
string PayloadType = 7;
|
||||||
bytes Payload = 8;
|
bytes Payload = 8;
|
||||||
@@ -68,6 +68,7 @@ message WebcastGiftMessage {
|
|||||||
int32 repeatCount = 5;
|
int32 repeatCount = 5;
|
||||||
int32 comboCount = 6;
|
int32 comboCount = 6;
|
||||||
User user = 7;
|
User user = 7;
|
||||||
|
User toUser = 8;
|
||||||
int32 repeatEnd = 9;
|
int32 repeatEnd = 9;
|
||||||
int64 groupId = 11;
|
int64 groupId = 11;
|
||||||
int64 incomeTaskgifts = 12;
|
int64 incomeTaskgifts = 12;
|
||||||
@@ -84,8 +85,8 @@ message WebcastGiftMessage {
|
|||||||
|
|
||||||
message UserGiftReciever
|
message UserGiftReciever
|
||||||
{
|
{
|
||||||
int64 userId =1;
|
int64 userId = 1;
|
||||||
string deviceName = 10;
|
string deviceName = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GiftIMPriority {
|
message GiftIMPriority {
|
||||||
@@ -203,7 +204,7 @@ message WebcastChatMessage {
|
|||||||
int32 quickChatScene = 16;
|
int32 quickChatScene = 16;
|
||||||
int32 communityFlaggedStatus = 17;
|
int32 communityFlaggedStatus = 17;
|
||||||
UserIdentity UserIdentity = 18;
|
UserIdentity UserIdentity = 18;
|
||||||
map<int32,string> CommentQualityScores = 19;
|
map<int32, string> CommentQualityScores = 19;
|
||||||
|
|
||||||
// @EmoteWithIndex
|
// @EmoteWithIndex
|
||||||
// proto.webcast.im.ChatMessage
|
// proto.webcast.im.ChatMessage
|
||||||
@@ -283,14 +284,14 @@ message WebcastGoalUpdateMessage {
|
|||||||
int64 contributorId = 4;
|
int64 contributorId = 4;
|
||||||
Image contributorAvatar = 5;
|
Image contributorAvatar = 5;
|
||||||
string contributorDisplayId = 6;
|
string contributorDisplayId = 6;
|
||||||
// SubGoal contributeSubgoal = 7;
|
// SubGoal contributeSubgoal = 7;
|
||||||
int64 contributeCount = 9;
|
int64 contributeCount = 9;
|
||||||
int64 contributeScore = 10;
|
int64 contributeScore = 10;
|
||||||
int64 giftRepeatCount = 11;
|
int64 giftRepeatCount = 11;
|
||||||
string contributorIdStr = 12;
|
string contributorIdStr = 12;
|
||||||
bool pin = 13;
|
bool pin = 13;
|
||||||
bool unpin = 14;
|
bool unpin = 14;
|
||||||
// GoalPinInfo pinInfo = 15;
|
// GoalPinInfo pinInfo = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message related to Chat-moderation?
|
// Message related to Chat-moderation?
|
||||||
@@ -354,7 +355,7 @@ message WebcastSocialMessage {
|
|||||||
message WebcastSubNotifyMessage {
|
message WebcastSubNotifyMessage {
|
||||||
Common common = 1;
|
Common common = 1;
|
||||||
User user = 2;
|
User user = 2;
|
||||||
// ExhibitionType exhibitionType = 3; // Enum
|
// ExhibitionType exhibitionType = 3; // Enum
|
||||||
int64 subMonth = 4;
|
int64 subMonth = 4;
|
||||||
SubscribeType subscribeType = 5; // Enum
|
SubscribeType subscribeType = 5; // Enum
|
||||||
OldSubscribeStatus oldSubscribeStatus = 6; // Enum
|
OldSubscribeStatus oldSubscribeStatus = 6; // Enum
|
||||||
@@ -681,7 +682,7 @@ message WebcastMsgDetectMessage {
|
|||||||
bool detectP2PMsg = 3;
|
bool detectP2PMsg = 3;
|
||||||
bool detectRoomMsg = 4;
|
bool detectRoomMsg = 4;
|
||||||
bool httpOptimize = 5;
|
bool httpOptimize = 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@WebcastOecLiveShoppingMessage
|
//@WebcastOecLiveShoppingMessage
|
||||||
@@ -751,11 +752,11 @@ message WebcastLinkMessage {
|
|||||||
LinkerUpdateUserSettingContent UpdateUserSettingContent = 18;
|
LinkerUpdateUserSettingContent UpdateUserSettingContent = 18;
|
||||||
LinkerMicIdxUpdateContent MicIdxUpdateContent = 19;
|
LinkerMicIdxUpdateContent MicIdxUpdateContent = 19;
|
||||||
LinkerListChangeContent ListChangeContent = 20;
|
LinkerListChangeContent ListChangeContent = 20;
|
||||||
// CohostListChangeContent CohostListChangeContent = 21;
|
// CohostListChangeContent CohostListChangeContent = 21;
|
||||||
LinkerMediaChangeContent MediaChangeContent = 22;
|
LinkerMediaChangeContent MediaChangeContent = 22;
|
||||||
LinkerAcceptNoticeContent ReplyAcceptNoticeContent = 23;
|
LinkerAcceptNoticeContent ReplyAcceptNoticeContent = 23;
|
||||||
LinkerSysKickOutContent SysKickOutContent = 101;
|
LinkerSysKickOutContent SysKickOutContent = 101;
|
||||||
// LinkmicUserToastContent UserToastContent = 102;
|
// LinkmicUserToastContent UserToastContent = 102;
|
||||||
string Extra = 200;
|
string Extra = 200;
|
||||||
int64 ExpireTimestamp = 201;
|
int64 ExpireTimestamp = 201;
|
||||||
string TransferExtra = 202;
|
string TransferExtra = 202;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.0.10-Release</version>
|
<version>1.0.14-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.dto.TikTokUserInfo;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokReconnectingEvent;
|
import io.github.jwdeveloper.tiktok.data.events.TikTokReconnectingEvent;
|
||||||
@@ -135,13 +136,15 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
|
|
||||||
apiService.updateSessionId();
|
apiService.updateSessionId();
|
||||||
|
|
||||||
|
TikTokUserInfo info = apiService.fetchUserInfoFromTikTokApi(liveRoomInfo.getHostName());
|
||||||
|
liveRoomInfo.setStartTime(info.getStartTime());
|
||||||
if (clientSettings.getRoomId() != null) {
|
if (clientSettings.getRoomId() != null) {
|
||||||
liveRoomInfo.setRoomId(clientSettings.getRoomId());
|
liveRoomInfo.setRoomId(clientSettings.getRoomId());
|
||||||
logger.info("Using roomID from settings: " + clientSettings.getRoomId());
|
logger.info("Using roomID from settings: " + clientSettings.getRoomId());
|
||||||
} else {
|
} else {
|
||||||
var roomId = apiService.fetchRoomId(liveRoomInfo.getHostName());
|
liveRoomInfo.setRoomId(info.getRoomId());
|
||||||
liveRoomInfo.setRoomId(roomId);
|
|
||||||
}
|
}
|
||||||
|
apiService.updateRoomId(liveRoomInfo.getRoomId());
|
||||||
|
|
||||||
|
|
||||||
var liveRoomMeta = apiService.fetchRoomInfo();
|
var liveRoomMeta = apiService.fetchRoomInfo();
|
||||||
@@ -194,4 +197,4 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
{
|
{
|
||||||
tikTokEventHandler.publish(this, event);
|
tikTokEventHandler.publish(this, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,12 +113,12 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
clientSettings.setTimeout(Duration.ofSeconds(Constants.DEFAULT_TIMEOUT));
|
clientSettings.setTimeout(Duration.ofSeconds(Constants.DEFAULT_TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clientSettings.getClientLanguage() == null || clientSettings.getClientLanguage().equals("")) {
|
if (clientSettings.getClientLanguage() == null || clientSettings.getClientLanguage().isEmpty()) {
|
||||||
clientSettings.setClientLanguage(Constants.DefaultClientSettings().getClientLanguage());
|
clientSettings.setClientLanguage(Constants.DefaultClientSettings().getClientLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (clientSettings.getHostName() == null || clientSettings.getHostName().equals("")) {
|
if (clientSettings.getHostName() == null || clientSettings.getHostName().isEmpty()) {
|
||||||
throw new TikTokLiveException("HostName can not be null");
|
throw new TikTokLiveException("HostName can not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
|
|
||||||
//ConnectionEvents events
|
//ConnectionEvents events
|
||||||
var commonHandler = new TikTokCommonEventHandler();
|
var commonHandler = new TikTokCommonEventHandler();
|
||||||
var giftHandler = new TikTokGiftEventHandler(giftManager);
|
var giftHandler = new TikTokGiftEventHandler(giftManager, roomInfo);
|
||||||
var roomInfoHandler = new TikTokRoomInfoEventHandler(roomInfo);
|
var roomInfoHandler = new TikTokRoomInfoEventHandler(roomInfo);
|
||||||
var socialHandler = new TikTokSocialMediaEventHandler(roomInfo);
|
var socialHandler = new TikTokSocialMediaEventHandler(roomInfo);
|
||||||
|
|
||||||
@@ -552,11 +552,4 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
tikTokEventHandler.subscribe(TikTokReconnectingEvent.class, event);
|
tikTokEventHandler.subscribe(TikTokReconnectingEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -22,11 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.RankingUser;
|
import io.github.jwdeveloper.tiktok.data.models.RankingUser;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
|
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
|
||||||
|
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -42,6 +41,8 @@ public class TikTokRoomInfo implements LiveRoomInfo {
|
|||||||
|
|
||||||
private int totalViewersCount;
|
private int totalViewersCount;
|
||||||
|
|
||||||
|
private long startTime;
|
||||||
|
|
||||||
private boolean ageRestricted;
|
private boolean ageRestricted;
|
||||||
|
|
||||||
private User host;
|
private User host;
|
||||||
@@ -69,5 +70,4 @@ public class TikTokRoomInfo implements LiveRoomInfo {
|
|||||||
usersRanking.clear();
|
usersRanking.clear();
|
||||||
usersRanking.addAll(rankingUsers);
|
usersRanking.addAll(rankingUsers);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
@@ -22,14 +22,12 @@
|
|||||||
*/
|
*/
|
||||||
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.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
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;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -89,23 +87,17 @@ public class TikTokGiftManager implements GiftManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Gift findById(int giftId) {
|
public Gift findById(int giftId) {
|
||||||
if (!indexById.containsKey(giftId)) {
|
Gift gift = indexById.get(giftId);
|
||||||
return Gift.UNDEFINED;
|
return gift == null ? Gift.UNDEFINED : gift;
|
||||||
}
|
|
||||||
return indexById.get(giftId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gift findByName(String giftName) {
|
public Gift findByName(String giftName) {
|
||||||
if (!indexByName.containsKey(giftName)) {
|
Gift gift = indexByName.get(giftName);
|
||||||
return Gift.UNDEFINED;
|
return gift == null ? Gift.UNDEFINED : gift;
|
||||||
}
|
|
||||||
return indexByName.get(giftName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Gift> getGifts()
|
public List<Gift> getGifts() {
|
||||||
{
|
|
||||||
return indexById.values().stream().toList();
|
return indexById.values().stream().toList();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
@@ -22,58 +22,30 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http;
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class HttpUtils
|
public class HttpUtils
|
||||||
{
|
{
|
||||||
public static String parseParameters(String url, Map<String,Object> parameters)
|
public static String parseParameters(String url, Map<String,Object> parameters)
|
||||||
{
|
{
|
||||||
var parameterString = "";
|
if (parameters.isEmpty())
|
||||||
if (!parameters.isEmpty()) {
|
return url;
|
||||||
var builder = new StringBuilder();
|
|
||||||
builder.append("?");
|
|
||||||
var first = false;
|
|
||||||
for (var param : parameters.entrySet()) {
|
|
||||||
|
|
||||||
if (first) {
|
return url+ "?" + parameters.entrySet().stream().map(entry -> entry.getKey()+"="+entry.getValue()).collect(Collectors.joining("&"));
|
||||||
builder.append("&");
|
|
||||||
}
|
|
||||||
builder.append(param.getKey()).append("=").append(param.getValue());
|
|
||||||
first = true;
|
|
||||||
}
|
|
||||||
parameterString = builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return url+parameterString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
public static String parseParametersEncode(String url, Map<String,Object> parameters)
|
public static String parseParametersEncode(String url, Map<String,Object> parameters)
|
||||||
{
|
{
|
||||||
|
if (parameters.isEmpty())
|
||||||
|
return url;
|
||||||
|
|
||||||
var parameterString = "";
|
return url+ "?" + parameters.entrySet().stream().map(entry -> {
|
||||||
if (!parameters.isEmpty()) {
|
String encodedKey = URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8);
|
||||||
var builder = new StringBuilder();
|
String encodedValue = URLEncoder.encode(entry.getValue().toString(), StandardCharsets.UTF_8);
|
||||||
builder.append("?");
|
return encodedKey+"="+encodedValue;
|
||||||
var first = false;
|
}).collect(Collectors.joining("&"));
|
||||||
for (var param : parameters.entrySet()) {
|
|
||||||
|
|
||||||
if (first) {
|
|
||||||
builder.append("&");
|
|
||||||
}
|
|
||||||
|
|
||||||
final String encodedKey = URLEncoder.encode(param.getKey(), StandardCharsets.UTF_8);
|
|
||||||
final String encodedValue = URLEncoder.encode(param.getValue().toString(), StandardCharsets.UTF_8);
|
|
||||||
builder.append(encodedKey).append("=").append(encodedValue);
|
|
||||||
first = true;
|
|
||||||
}
|
|
||||||
parameterString = builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return url+parameterString;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,12 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http;
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.*;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import io.github.jwdeveloper.tiktok.ClientSettings;
|
import io.github.jwdeveloper.tiktok.ClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.data.dto.TikTokUserInfo;
|
import io.github.jwdeveloper.tiktok.data.dto.TikTokUserInfo;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveOfflineHostException;
|
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.LiveRoomMetaMapper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveRoomMetaMapper;
|
||||||
@@ -35,7 +32,6 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class TikTokApiService {
|
public class TikTokApiService {
|
||||||
private final TikTokHttpClient tiktokHttpClient;
|
private final TikTokHttpClient tiktokHttpClient;
|
||||||
@@ -48,7 +44,6 @@ public class TikTokApiService {
|
|||||||
this.clientSettings = clientSettings;
|
this.clientSettings = clientSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateSessionId() {
|
public void updateSessionId() {
|
||||||
if (clientSettings.getSessionId() == null) {
|
if (clientSettings.getSessionId() == null) {
|
||||||
return;
|
return;
|
||||||
@@ -59,43 +54,45 @@ public class TikTokApiService {
|
|||||||
tiktokHttpClient.setSessionId(clientSettings.getSessionId());
|
tiktokHttpClient.setSessionId(clientSettings.getSessionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fetchRoomId(String userName) {
|
public void updateRoomId(String roomId)
|
||||||
var userInfo = fetchUserInfoFromTikTokApi(userName);
|
{
|
||||||
clientSettings.getClientParameters().put("room_id", userInfo.getRoomId());
|
clientSettings.getClientParameters().put("room_id", roomId);
|
||||||
logger.info("RoomID -> " + userInfo.getRoomId());
|
|
||||||
return userInfo.getRoomId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokUserInfo fetchUserInfoFromTikTokApi(String userName) {
|
public TikTokUserInfo fetchUserInfoFromTikTokApi(String userName) {
|
||||||
|
|
||||||
var params = new HashMap<>(clientSettings.getClientParameters());
|
var params = new HashMap<>(clientSettings.getClientParameters());
|
||||||
params.put("uniqueId", userName);
|
params.put("uniqueId", userName);
|
||||||
params.put("sourceType", 54);
|
params.put("sourceType", 54);
|
||||||
JsonObject roomData = null;
|
JsonObject roomData;
|
||||||
try {
|
try {
|
||||||
roomData = tiktokHttpClient.getJsonFromTikTokApi("api-live/user/room/", params);
|
roomData = tiktokHttpClient.getJsonFromTikTokApi("api-live/user/room/", params);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
|
||||||
throw new TikTokLiveRequestException("Failed to fetch pre connection room information, it happens when TikTok temporary blocks you. Try to connect again in few minutes");
|
throw new TikTokLiveRequestException("Failed to fetch pre connection room information, it happens when TikTok temporary blocks you. Try to connect again in few minutes");
|
||||||
}
|
}
|
||||||
|
|
||||||
var message = roomData.get("message").getAsString();
|
var message = roomData.get("message").getAsString();
|
||||||
|
|
||||||
if (message.equals("params_error")) {
|
if (message.equals("params_error")) {
|
||||||
throw new TikTokLiveRequestException("fetchRoomIdFromTiktokApi -> Unable to fetch roomID, contact with developer");
|
throw new TikTokLiveRequestException("fetchRoomIdFromTiktokApi -> Unable to fetch roomID, contact the developer");
|
||||||
}
|
}
|
||||||
if (message.equals("user_not_found")) {
|
if (message.equals("user_not_found")) {
|
||||||
return new TikTokUserInfo(TikTokUserInfo.UserStatus.NotFound, "");
|
return new TikTokUserInfo(TikTokUserInfo.UserStatus.NotFound, "", -1);
|
||||||
}
|
}
|
||||||
//live -> status 2
|
//live -> status 2
|
||||||
//live paused -> 3
|
//live paused -> 3
|
||||||
//not live -> status 4
|
//not live -> status 4
|
||||||
var data = roomData.getAsJsonObject("data");
|
var element = roomData.get("data");
|
||||||
|
if (element.isJsonNull()) {
|
||||||
|
return new TikTokUserInfo(TikTokUserInfo.UserStatus.NotFound, "", -1);
|
||||||
|
}
|
||||||
|
var data = element.getAsJsonObject();
|
||||||
var user = data.getAsJsonObject("user");
|
var user = data.getAsJsonObject("user");
|
||||||
var roomId = user.get("roomId").getAsString();
|
var roomId = user.get("roomId").getAsString();
|
||||||
var status = user.get("status").getAsInt();
|
var status = user.get("status").getAsInt();
|
||||||
|
|
||||||
|
var liveRoom = data.getAsJsonObject("liveRoom");
|
||||||
|
long startTime = liveRoom.get("startTime").getAsLong();
|
||||||
|
|
||||||
var statusEnum = switch (status) {
|
var statusEnum = switch (status) {
|
||||||
case 2 -> TikTokUserInfo.UserStatus.Live;
|
case 2 -> TikTokUserInfo.UserStatus.Live;
|
||||||
case 3 -> TikTokUserInfo.UserStatus.LivePaused;
|
case 3 -> TikTokUserInfo.UserStatus.LivePaused;
|
||||||
@@ -103,7 +100,7 @@ public class TikTokApiService {
|
|||||||
default -> TikTokUserInfo.UserStatus.NotFound;
|
default -> TikTokUserInfo.UserStatus.NotFound;
|
||||||
};
|
};
|
||||||
|
|
||||||
return new TikTokUserInfo(statusEnum, roomId);
|
return new TikTokUserInfo(statusEnum, roomId, startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -138,4 +135,4 @@ public class TikTokApiService {
|
|||||||
throw new TikTokLiveRequestException("Failed to fetch live websocket connection data", e);
|
throw new TikTokLiveRequestException("Failed to fetch live websocket connection data", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,9 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http;
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class TikTokCookieJar {
|
public class TikTokCookieJar {
|
||||||
private final Map<String, String> cookies;
|
private final Map<String, String> cookies;
|
||||||
@@ -40,13 +39,10 @@ public class TikTokCookieJar {
|
|||||||
cookies.put(key, value);
|
cookies.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String parseCookies()
|
public String parseCookies() {
|
||||||
{
|
return cookies.entrySet()
|
||||||
var sb = new StringBuilder();
|
.stream()
|
||||||
for(var entry : cookies.entrySet())
|
.map(entry -> entry.getKey()+"="+entry.getValue()+";")
|
||||||
{
|
.collect(Collectors.joining());
|
||||||
sb.append(entry.getKey()).append("=").append(entry.getValue()).append(";");
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,8 +45,7 @@ public class TikTokHttpClient {
|
|||||||
this.tikTokCookieJar = tikTokCookieJar;
|
this.tikTokCookieJar = tikTokCookieJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSessionId(String sessionId)
|
public void setSessionId(String sessionId) {
|
||||||
{
|
|
||||||
tikTokCookieJar.set("sessionid", sessionId);
|
tikTokCookieJar.set("sessionid", sessionId);
|
||||||
tikTokCookieJar.set("sessionid_ss", sessionId);
|
tikTokCookieJar.set("sessionid_ss", sessionId);
|
||||||
tikTokCookieJar.set("sid_tt", sessionId);
|
tikTokCookieJar.set("sid_tt", sessionId);
|
||||||
@@ -54,14 +53,12 @@ public class TikTokHttpClient {
|
|||||||
|
|
||||||
|
|
||||||
public String getLivestreamPage(String userName) {
|
public String getLivestreamPage(String userName) {
|
||||||
|
|
||||||
var url = Constants.TIKTOK_URL_WEB + "@" + userName + "/live/";
|
var url = Constants.TIKTOK_URL_WEB + "@" + userName + "/live/";
|
||||||
var get = getRequest(url, null);
|
var get = getRequest(url, null);
|
||||||
return get;
|
return get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonObject getJsonFromTikTokApi(String path, Map<String,Object> params)
|
public JsonObject getJsonFromTikTokApi(String path, Map<String,Object> params) {
|
||||||
{
|
|
||||||
var get = getRequest(Constants.TIKTOK_URL_WEB + path, params);
|
var get = getRequest(Constants.TIKTOK_URL_WEB + path, params);
|
||||||
var json = JsonParser.parseString(get);
|
var json = JsonParser.parseString(get);
|
||||||
var jsonObject = json.getAsJsonObject();
|
var jsonObject = json.getAsJsonObject();
|
||||||
@@ -117,7 +114,6 @@ public class TikTokHttpClient {
|
|||||||
{
|
{
|
||||||
var split = cookie.split(";")[0].split("=");
|
var split = cookie.split(";")[0].split("=");
|
||||||
|
|
||||||
|
|
||||||
var key = split[0];
|
var key = split[0];
|
||||||
var value = split[1];
|
var value = split[1];
|
||||||
tikTokCookieJar.set(key, value);
|
tikTokCookieJar.set(key, value);
|
||||||
@@ -133,7 +129,6 @@ public class TikTokHttpClient {
|
|||||||
|
|
||||||
|
|
||||||
private String getSignedUrl(String url, Map<String, Object> parameters) {
|
private String getSignedUrl(String url, Map<String, Object> parameters) {
|
||||||
|
|
||||||
var fullUrl = HttpUtils.parseParameters(url,parameters);
|
var fullUrl = HttpUtils.parseParameters(url,parameters);
|
||||||
var signParams = new TreeMap<String,Object>();
|
var signParams = new TreeMap<String,Object>();
|
||||||
signParams.put("client", "ttlive-java");
|
signParams.put("client", "ttlive-java");
|
||||||
@@ -143,7 +138,6 @@ public class TikTokHttpClient {
|
|||||||
var request = requestFactory.setQueries(signParams);
|
var request = requestFactory.setQueries(signParams);
|
||||||
var content = request.get(Constants.TIKTOK_SIGN_API);
|
var content = request.get(Constants.TIKTOK_SIGN_API);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var json = JsonParser.parseString(content);
|
var json = JsonParser.parseString(content);
|
||||||
var jsonObject = json.getAsJsonObject();
|
var jsonObject = json.getAsJsonObject();
|
||||||
@@ -157,4 +151,4 @@ public class TikTokHttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
||||||
private final CookieManager cookieManager;
|
private final CookieManager cookieManager;
|
||||||
@@ -122,18 +123,16 @@ public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
|||||||
public TikTokHttpRequest setQueries(Map<String, Object> queries) {
|
public TikTokHttpRequest setQueries(Map<String, Object> queries) {
|
||||||
if (queries == null)
|
if (queries == null)
|
||||||
return this;
|
return this;
|
||||||
var testMap = new TreeMap<String, Object>(queries);
|
var testMap = new TreeMap<>(queries);
|
||||||
query = String.join("&", testMap.entrySet().stream().map(x ->
|
query = testMap.entrySet().stream().map(x -> {
|
||||||
{
|
|
||||||
var key = x.getKey();
|
var key = x.getKey();
|
||||||
var value = "";
|
|
||||||
try {
|
try {
|
||||||
value = URLEncoder.encode(x.getValue().toString(), StandardCharsets.UTF_8);
|
return key+"="+URLEncoder.encode(x.getValue().toString(), StandardCharsets.UTF_8);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return key + "=";
|
||||||
}
|
}
|
||||||
return key + "=" + value;
|
}).collect(Collectors.joining("&"));
|
||||||
}).toList());
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +140,7 @@ public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
|||||||
private String getContent(HttpRequest request) throws Exception {
|
private String getContent(HttpRequest request) throws Exception {
|
||||||
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
var event = new TikTokHttpResponseEvent(response.uri().toString(), HttpData.map(request), HttpData.map(response));
|
var event = new TikTokHttpResponseEvent(response.uri().toString(), HttpData.map(response), HttpData.map(request));
|
||||||
eventHandler.publish(null, event);
|
eventHandler.publish(null, event);
|
||||||
if (response.statusCode() == 404) {
|
if (response.statusCode() == 404) {
|
||||||
throw new TikTokLiveRequestException("Request responded with 404 NOT_FOUND");
|
throw new TikTokLiveRequestException("Request responded with 404 NOT_FOUND");
|
||||||
@@ -162,10 +161,7 @@ public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
|||||||
var map = new HashMap<String, List<String>>();
|
var map = new HashMap<String, List<String>>();
|
||||||
map.put(key, List.of(value));
|
map.put(key, List.of(value));
|
||||||
cookieManager.put(uri, map);
|
cookieManager.put(uri, map);
|
||||||
|
|
||||||
}
|
}
|
||||||
return response.body();
|
return response.body();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -115,8 +115,8 @@ public class TikTokListenersManager implements ListenersManager {
|
|||||||
throw new TikTokEventListenerMethodException(e);
|
throw new TikTokEventListenerMethodException(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
eventsMap.computeIfAbsent(eventClazz, (a) -> new ArrayList<EventConsumer<?>>()).add(eventMethodRef);
|
eventsMap.computeIfAbsent(eventClazz, (a) -> new ArrayList<>()).add(eventMethodRef);
|
||||||
}
|
}
|
||||||
return new ListenerBindingModel(listener, eventsMap);
|
return new ListenerBindingModel(listener, eventsMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.mappers;
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
@@ -123,4 +122,4 @@ public class LiveRoomMetaMapper {
|
|||||||
user.addAttribute(UserAttribute.LiveHost);
|
user.addAttribute(UserAttribute.LiveHost);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
package io.github.jwdeveloper.tiktok.mappers;
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
import com.google.protobuf.GeneratedMessageV3;
|
import com.google.protobuf.GeneratedMessageV3;
|
||||||
|
import io.github.jwdeveloper.tiktok.TikTokLive;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingAction;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingAction;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
||||||
@@ -36,10 +37,12 @@ public class TikTokLiveMapper implements TikTokMapper {
|
|||||||
|
|
||||||
private final Map<String, TikTokLiveMapperModel> mappers;
|
private final Map<String, TikTokLiveMapperModel> mappers;
|
||||||
private final TikTokMapperHelper mapperUtils;
|
private final TikTokMapperHelper mapperUtils;
|
||||||
|
private final TikTokLiveMapperModel globalMapperModel;
|
||||||
|
|
||||||
public TikTokLiveMapper(TikTokMapperHelper mapperUtils) {
|
public TikTokLiveMapper(TikTokMapperHelper mapperUtils) {
|
||||||
this.mappers = new HashMap<>();
|
this.mappers = new HashMap<>();
|
||||||
this.mapperUtils = mapperUtils;
|
this.mapperUtils = mapperUtils;
|
||||||
|
this.globalMapperModel = new TikTokLiveMapperModel("any message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -76,6 +79,11 @@ public class TikTokLiveMapper implements TikTokMapper {
|
|||||||
return forMessage(mapperName, (inputBytes, messageName, mapperHelper) -> MappingResult.of(inputBytes, onMapping.apply(inputBytes)));
|
return forMessage(mapperName, (inputBytes, messageName, mapperHelper) -> MappingResult.of(inputBytes, onMapping.apply(inputBytes)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TikTokMapperModel forAnyMessage() {
|
||||||
|
return globalMapperModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isRegistered(String mapperName) {
|
public boolean isRegistered(String mapperName) {
|
||||||
return mappers.containsKey(mapperName);
|
return mappers.containsKey(mapperName);
|
||||||
@@ -84,6 +92,7 @@ public class TikTokLiveMapper implements TikTokMapper {
|
|||||||
public <T extends GeneratedMessageV3> boolean isRegistered(Class<T> mapperName) {
|
public <T extends GeneratedMessageV3> boolean isRegistered(Class<T> mapperName) {
|
||||||
return mappers.containsKey(mapperName.getSimpleName());
|
return mappers.containsKey(mapperName.getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TikTokEvent> handleMapping(String messageName, byte[] bytes) {
|
public List<TikTokEvent> handleMapping(String messageName, byte[] bytes) {
|
||||||
if (!isRegistered(messageName)) {
|
if (!isRegistered(messageName)) {
|
||||||
return List.of();
|
return List.of();
|
||||||
@@ -91,10 +100,17 @@ public class TikTokLiveMapper implements TikTokMapper {
|
|||||||
var mapperModel = mappers.get(messageName);
|
var mapperModel = mappers.get(messageName);
|
||||||
|
|
||||||
var inputBytes = mapperModel.getOnBeforeMapping().onMapping(bytes, messageName, mapperUtils);
|
var inputBytes = mapperModel.getOnBeforeMapping().onMapping(bytes, messageName, mapperUtils);
|
||||||
|
var globalInputBytes = globalMapperModel.getOnBeforeMapping().onMapping(inputBytes, messageName, mapperUtils);
|
||||||
|
|
||||||
var mappingResult = mapperModel.getOnMapping().onMapping(inputBytes, messageName, mapperUtils);
|
|
||||||
|
var mappingResult = mapperModel.getOnMapping().onMapping(globalInputBytes, messageName, mapperUtils);
|
||||||
|
|
||||||
|
if (mappingResult == null) {
|
||||||
|
mappingResult = globalMapperModel.getOnMapping().onMapping(globalInputBytes, messageName, mapperUtils);
|
||||||
|
}
|
||||||
|
|
||||||
var afterMappingResult = mapperModel.getOnAfterMapping().apply(mappingResult);
|
var afterMappingResult = mapperModel.getOnAfterMapping().apply(mappingResult);
|
||||||
return afterMappingResult;
|
var globalAfterMappingResult = globalMapperModel.getOnAfterMapping().apply(MappingResult.of(mappingResult.getSource(), afterMappingResult));
|
||||||
|
return globalAfterMappingResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.mappers;
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
import com.google.protobuf.GeneratedMessageV3;
|
import com.google.protobuf.GeneratedMessageV3;
|
||||||
|
|||||||
@@ -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.mappers;
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.mappers.handlers;
|
package io.github.jwdeveloper.tiktok.mappers.handlers;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.TikTokRoomInfo;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
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;
|
||||||
@@ -43,17 +44,19 @@ import java.util.Map;
|
|||||||
public class TikTokGiftEventHandler {
|
public class TikTokGiftEventHandler {
|
||||||
private final GiftManager giftManager;
|
private final GiftManager giftManager;
|
||||||
private final Map<Long, WebcastGiftMessage> giftsMessages;
|
private final Map<Long, WebcastGiftMessage> giftsMessages;
|
||||||
|
private final TikTokRoomInfo tikTokRoomInfo;
|
||||||
|
|
||||||
public TikTokGiftEventHandler(GiftManager giftManager) {
|
public TikTokGiftEventHandler(GiftManager giftManager, TikTokRoomInfo tikTokRoomInfo) {
|
||||||
this.giftManager = giftManager;
|
this.giftManager = giftManager;
|
||||||
giftsMessages = new HashMap<>();
|
giftsMessages = new HashMap<>();
|
||||||
|
this.tikTokRoomInfo = tikTokRoomInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public MappingResult handleGifts(byte[] msg, String name, TikTokMapperHelper helper) {
|
public MappingResult handleGifts(byte[] msg, String name, TikTokMapperHelper helper) {
|
||||||
var currentMessage = WebcastGiftMessage.parseFrom(msg);
|
var currentMessage = WebcastGiftMessage.parseFrom(msg);
|
||||||
var gifts = handleGift(currentMessage);
|
var gifts = handleGift(currentMessage);
|
||||||
return MappingResult.of(currentMessage,gifts);
|
return MappingResult.of(currentMessage, gifts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TikTokEvent> handleGift(WebcastGiftMessage currentMessage) {
|
public List<TikTokEvent> handleGift(WebcastGiftMessage currentMessage) {
|
||||||
@@ -101,12 +104,12 @@ public class TikTokGiftEventHandler {
|
|||||||
|
|
||||||
private TikTokGiftEvent getGiftEvent(WebcastGiftMessage message) {
|
private TikTokGiftEvent getGiftEvent(WebcastGiftMessage message) {
|
||||||
var gift = getGiftObject(message);
|
var gift = getGiftObject(message);
|
||||||
return new TikTokGiftEvent(gift, message);
|
return new TikTokGiftEvent(gift, tikTokRoomInfo.getHost(), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TikTokGiftEvent getGiftComboEvent(WebcastGiftMessage message, GiftSendType state) {
|
private TikTokGiftEvent getGiftComboEvent(WebcastGiftMessage message, GiftSendType state) {
|
||||||
var gift = getGiftObject(message);
|
var gift = getGiftObject(message);
|
||||||
return new TikTokGiftComboEvent(gift, message, state);
|
return new TikTokGiftComboEvent(gift, tikTokRoomInfo.getHost(), message, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Gift getGiftObject(WebcastGiftMessage giftMessage) {
|
private Gift getGiftObject(WebcastGiftMessage giftMessage) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.handlers.events;
|
package io.github.jwdeveloper.tiktok.handlers.events;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.TikTokRoomInfo;
|
||||||
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;
|
||||||
@@ -49,42 +50,43 @@ class TikTokGiftEventHandlerTest {
|
|||||||
@BeforeAll
|
@BeforeAll
|
||||||
public void before() {
|
public void before() {
|
||||||
var manager = new TikTokGiftManager(Logger.getLogger("x"));
|
var manager = new TikTokGiftManager(Logger.getLogger("x"));
|
||||||
|
var info = new TikTokRoomInfo();
|
||||||
|
info.setHost(new io.github.jwdeveloper.tiktok.data.models.users.User(123L, "test", new Picture("")));
|
||||||
manager.registerGift(123, "example", 123, new Picture("image.webp"));
|
manager.registerGift(123, "example", 123, new Picture("image.webp"));
|
||||||
handler = new TikTokGiftEventHandler(manager);
|
handler = new TikTokGiftEventHandler(manager, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldHandleGifts() {
|
void shouldHandleGifts() {
|
||||||
var message = getGiftMessage("example-new-name", 123, "image-new.png", 0, 1,false);
|
var message = getGiftMessage("example-new-name", 123, "image-new.png", 0, 1, false);
|
||||||
var result = handler.handleGift(message);
|
var result = handler.handleGift(message);
|
||||||
|
|
||||||
Assertions.assertEquals(2, result.size());
|
Assertions.assertEquals(2, result.size());
|
||||||
|
|
||||||
var event = (TikTokGiftEvent) result.get(0);
|
var event = (TikTokGiftEvent) result.get(0);
|
||||||
var gift = event.getGift();
|
var gift = event.getGift();
|
||||||
Assertions.assertEquals("image-new.png",gift.getPicture().getLink());
|
Assertions.assertEquals("image-new.png", gift.getPicture().getLink());
|
||||||
Assertions.assertEquals(123,gift.getId());
|
Assertions.assertEquals(123, gift.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldHandleStrakableGift() {
|
void shouldHandleStrakableGift() {
|
||||||
var message = getGiftMessage("example-new-name", 123, "image-new.png", 0, 1,true);
|
var message = getGiftMessage("example-new-name", 123, "image-new.png", 0, 1, true);
|
||||||
var result = handler.handleGift(message);
|
var result = handler.handleGift(message);
|
||||||
|
|
||||||
Assertions.assertEquals(1, result.size());
|
Assertions.assertEquals(1, result.size());
|
||||||
|
|
||||||
var event = (TikTokGiftEvent) result.get(0);
|
var event = (TikTokGiftEvent) result.get(0);
|
||||||
var gift = event.getGift();
|
var gift = event.getGift();
|
||||||
Assertions.assertEquals("image-new.png",gift.getPicture().getLink());
|
Assertions.assertEquals("image-new.png", gift.getPicture().getLink());
|
||||||
Assertions.assertEquals(123,gift.getId());
|
Assertions.assertEquals(123, gift.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldHandleStrike()
|
void shouldHandleStrike() {
|
||||||
{
|
var message1 = getGiftMessage("example-new-name", 123, "image-new.png", 1, 1, true);
|
||||||
var message1 = getGiftMessage("example-new-name", 123, "image-new.png", 1, 1,true);
|
var message2 = getGiftMessage("example-new-name", 123, "image-new.png", 2, 1, true);
|
||||||
var message2 = getGiftMessage("example-new-name", 123, "image-new.png", 2, 1,true);
|
var message3 = getGiftMessage("example-new-name", 123, "image-new.png", 0, 1, true);
|
||||||
var message3 = getGiftMessage("example-new-name", 123, "image-new.png", 0, 1,true);
|
|
||||||
|
|
||||||
var result1 = handler.handleGift(message1);
|
var result1 = handler.handleGift(message1);
|
||||||
var result2 = handler.handleGift(message2);
|
var result2 = handler.handleGift(message2);
|
||||||
@@ -96,9 +98,9 @@ class TikTokGiftEventHandlerTest {
|
|||||||
Assertions.assertEquals(2, result3.size());
|
Assertions.assertEquals(2, result3.size());
|
||||||
var event3 = (TikTokGiftComboEvent) result3.get(0);
|
var event3 = (TikTokGiftComboEvent) result3.get(0);
|
||||||
|
|
||||||
Assertions.assertEquals(GiftSendType.Begin,event1.getComboState());
|
Assertions.assertEquals(GiftSendType.Begin, event1.getComboState());
|
||||||
Assertions.assertEquals(GiftSendType.Active,event2.getComboState());
|
Assertions.assertEquals(GiftSendType.Active, event2.getComboState());
|
||||||
Assertions.assertEquals(GiftSendType.Finished,event3.getComboState());
|
Assertions.assertEquals(GiftSendType.Finished, event3.getComboState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -116,7 +118,7 @@ class TikTokGiftEventHandlerTest {
|
|||||||
giftBuilder.setId(giftId);
|
giftBuilder.setId(giftId);
|
||||||
giftBuilder.setName(giftName);
|
giftBuilder.setName(giftName);
|
||||||
giftBuilder.setImage(Image.newBuilder().addUrlList(giftImage).build());
|
giftBuilder.setImage(Image.newBuilder().addUrlList(giftImage).build());
|
||||||
giftBuilder.setType(streakable?1:0);
|
giftBuilder.setType(streakable ? 1 : 0);
|
||||||
userBuilder.setId(userId);
|
userBuilder.setId(userId);
|
||||||
|
|
||||||
builder.setGiftId(giftId);
|
builder.setGiftId(giftId);
|
||||||
@@ -127,5 +129,4 @@ class TikTokGiftEventHandlerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class HttpUtilsTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void parseParameters_EmptyParameters_ShouldHaveNoParameters()
|
||||||
|
{
|
||||||
|
String parsed = HttpUtils.parseParameters("https://webcast.tiktok.com/webcast/im/fetch/", new HashMap<>());
|
||||||
|
|
||||||
|
Assertions.assertEquals("https://webcast.tiktok.com/webcast/im/fetch/", parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseParameters_ValidParameters_ShouldConstructValidURL()
|
||||||
|
{
|
||||||
|
LinkedHashMap<String, Object> testMap = new LinkedHashMap<>();
|
||||||
|
testMap.put("room_id", 1);
|
||||||
|
testMap.put("uniqueId", "randomName");
|
||||||
|
String parsed = HttpUtils.parseParameters("https://webcast.tiktok.com/webcast/im/fetch/", testMap);
|
||||||
|
|
||||||
|
Assertions.assertEquals("https://webcast.tiktok.com/webcast/im/fetch/?room_id=1&uniqueId=randomName", parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseParametersEncode_EmptyParameters_ShouldHaveNoParameters()
|
||||||
|
{
|
||||||
|
String parsed = HttpUtils.parseParametersEncode("https://webcast.tiktok.com/webcast/im/fetch/", new HashMap<>());
|
||||||
|
|
||||||
|
Assertions.assertEquals("https://webcast.tiktok.com/webcast/im/fetch/", parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseParametersEncode_ValidParameters_ShouldConstructValidURL()
|
||||||
|
{
|
||||||
|
LinkedHashMap<String, Object> testMap = new LinkedHashMap<>();
|
||||||
|
testMap.put("room_id", 1);
|
||||||
|
testMap.put("root_referer", "https://www.tiktok.com/");
|
||||||
|
String parsed = HttpUtils.parseParametersEncode("https://webcast.tiktok.com/webcast/im/fetch/", testMap);
|
||||||
|
|
||||||
|
Assertions.assertEquals("https://webcast.tiktok.com/webcast/im/fetch/?room_id=1&root_referer=https%3A%2F%2Fwww.tiktok.com%2F", parsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,6 @@ package io.github.jwdeveloper.tiktok.http;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.github.jwdeveloper.tiktok.ClientSettings;
|
import io.github.jwdeveloper.tiktok.ClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.LiveRoomMetaMapper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveRoomMetaMapper;
|
||||||
@@ -84,28 +83,6 @@ public class TikTokApiServiceTest
|
|||||||
verify(tiktokHttpClient, times(1)).setSessionId("validSessionId");
|
verify(tiktokHttpClient, times(1)).setSessionId("validSessionId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
void fetchRoomId_ValidResponse_ReturnsRoomId() throws Exception {
|
|
||||||
String expectedRoomId = "123456";
|
|
||||||
String htmlResponse = "room_id=" + expectedRoomId ;
|
|
||||||
when(tiktokHttpClient.getLivestreamPage(anyString())).thenReturn(htmlResponse);
|
|
||||||
|
|
||||||
String roomId = tikTokApiService.fetchRoomId("username");
|
|
||||||
|
|
||||||
assertEquals(expectedRoomId, roomId);
|
|
||||||
verify(clientSettings.getClientParameters()).put("room_id", expectedRoomId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
void fetchRoomId_ExceptionThrown_ThrowsTikTokLiveRequestException() throws Exception {
|
|
||||||
when(tiktokHttpClient.getLivestreamPage(anyString())).thenThrow(new Exception("some exception"));
|
|
||||||
|
|
||||||
assertThrows(TikTokLiveRequestException.class, () -> {
|
|
||||||
tikTokApiService.fetchRoomId("username");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
void fetchRoomInfo_ValidResponse_ReturnsLiveRoomMeta() throws Exception {
|
void fetchRoomInfo_ValidResponse_ReturnsLiveRoomMeta() throws Exception {
|
||||||
HashMap<String, Object> clientParameters = new HashMap<>();
|
HashMap<String, Object> clientParameters = new HashMap<>();
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.0.10-Release</version>
|
<version>1.0.14-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
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.Gift;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.GiftManager;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
public class CustomEventExample {
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class CheapGiftEvent extends TikTokEvent {
|
||||||
|
Gift gift;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class ExpensiveGiftEvent extends TikTokEvent {
|
||||||
|
Gift gift;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
TikTokLive.newClient(SimpleExample.TIKTOK_HOSTNAME)
|
||||||
|
.onGift((liveClient, event) ->
|
||||||
|
{
|
||||||
|
if (event.getGift().getDiamondCost() > 100)
|
||||||
|
liveClient.publishEvent(new ExpensiveGiftEvent(event.getGift()));
|
||||||
|
else
|
||||||
|
liveClient.publishEvent(new CheapGiftEvent(event.getGift()));
|
||||||
|
})
|
||||||
|
.onEvent(CheapGiftEvent.class,(liveClient, event) ->
|
||||||
|
{
|
||||||
|
System.out.println("Thanks for cheap gift");
|
||||||
|
})
|
||||||
|
.onEvent(ExpensiveGiftEvent.class,(liveClient, event) ->
|
||||||
|
{
|
||||||
|
System.out.println("Thanks for expensive gift!");
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,7 +69,7 @@ Maven
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
||||||
<artifactId>Client</artifactId>
|
<artifactId>Client</artifactId>
|
||||||
<version>1.0.10-Release</version>
|
<version>1.0.12-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -86,7 +86,7 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.0.10-Release'
|
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.0.12-Release'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.0.10-Release</version>
|
<version>1.0.14-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -55,9 +55,4 @@ public class ApiServiceMock extends TikTokApiService {
|
|||||||
return WebcastResponse.newBuilder().build();
|
return WebcastResponse.newBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String fetchRoomId(String userName) {
|
|
||||||
return "mock-room-id";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.0.10-Release</version>
|
<version>1.0.14-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>Tools-EventsWebViewer</artifactId>
|
<artifactId>Tools-EventsWebViewer</artifactId>
|
||||||
|
|||||||
@@ -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.webviewer;
|
package io.github.jwdeveloper.tiktok.webviewer;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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.webviewer.services;
|
package io.github.jwdeveloper.tiktok.webviewer.services;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.tools.TikTokLiveTools;
|
import io.github.jwdeveloper.tiktok.tools.TikTokLiveTools;
|
||||||
|
|||||||
@@ -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.webviewer.services;
|
package io.github.jwdeveloper.tiktok.webviewer.services;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ var data =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dropDown("usersDropDown", () => `${baseUrl}/tiktok/users`, async (e) => {
|
dropDown("usersDropDown", () => `${baseUrl}/tiktok/users`, async (e) => {
|
||||||
data.user = e;
|
data.user = e;
|
||||||
update();
|
update();
|
||||||
@@ -51,28 +50,15 @@ function update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateAsync() {
|
async function updateAsync() {
|
||||||
console.log(data);
|
console.log("Updating", data);
|
||||||
await updateConnectionButton()
|
await updateConnectionButton()
|
||||||
await updateDataNamesList(async (dataName) => {
|
await updateDataNamesList(async (dataName) => {
|
||||||
data.dataName = dataName;
|
data.dataName = dataName;
|
||||||
data.page = 0;
|
data.page = 0;
|
||||||
await updateContent();
|
await updateContent(`${baseUrl}/tiktok/data?name=${data.dataName}&type=${data.dataType}&page=${data.page}`);
|
||||||
await updatePagination(async (page, link) => {
|
await updatePagination(async (page, link) => {
|
||||||
data.page = page;
|
data.page = page;
|
||||||
let response = await fetch(link);
|
await updateContent(link)
|
||||||
let json = await response.text();
|
|
||||||
console.log(link)
|
|
||||||
let root = JSON.parse(json);
|
|
||||||
editor.setValue(root.content);
|
|
||||||
|
|
||||||
if(data.dataType === 'message')
|
|
||||||
{
|
|
||||||
console.log("sending proto version")
|
|
||||||
let response2 = await fetch(`${link}&asProto=true`);
|
|
||||||
let json2 = await response2.text();
|
|
||||||
let root2 = JSON.parse(json2);
|
|
||||||
editor2.setValue(root2.content);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await fetch(`${baseUrl}/tiktok/update?user=${data.user}&session=${data.sessionTag}`);
|
await fetch(`${baseUrl}/tiktok/update?user=${data.user}&session=${data.sessionTag}`);
|
||||||
@@ -100,21 +86,30 @@ async function updatePagination(onSelect) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateContent() {
|
async function updateContent(link) {
|
||||||
console.log("updating content", data)
|
console.log("updating content", data)
|
||||||
let response = await fetch(`${baseUrl}/tiktok/data?name=${data.dataName}&type=${data.dataType}&page=${data.page}`);
|
let response = await fetch(link);
|
||||||
let json = await response.text();
|
let json = await response.text();
|
||||||
|
console.log(link)
|
||||||
let root = JSON.parse(json);
|
let root = JSON.parse(json);
|
||||||
editor.setValue(root.content);
|
editor.setValue(root.content);
|
||||||
|
$("#editor2").hide()
|
||||||
|
if (data.dataType === 'message') {
|
||||||
if(data.dataType === 'message')
|
|
||||||
{
|
|
||||||
console.log("sending proto version")
|
console.log("sending proto version")
|
||||||
let response2 = await fetch(`${baseUrl}/tiktok/data?name=${data.dataName}&type=${data.dataType}&page=${data.page}&asProto=true`);
|
let response2 = await fetch(`${link}&asProto=true`);
|
||||||
let json2 = await response2.text();
|
let json2 = await response2.text();
|
||||||
let root2 = JSON.parse(json2);
|
let root2 = JSON.parse(json2);
|
||||||
editor2.setValue(root2.content);
|
editor2.setValue(root2.content);
|
||||||
|
$("#editor2").show()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.dataType === 'response' && data.dataName === 'Http') {
|
||||||
|
|
||||||
|
var content = JSON.parse(root.content);
|
||||||
|
var body = JSON.parse(content.request.body)
|
||||||
|
var asJson = JSON.stringify(body, null, 2)
|
||||||
|
editor2.setValue(asJson);
|
||||||
|
$("#editor2").show()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -194,9 +189,9 @@ async function updateConnectionButton() {
|
|||||||
|
|
||||||
async function connect() {
|
async function connect() {
|
||||||
let name = document.getElementById('name').value;
|
let name = document.getElementById('name').value;
|
||||||
let session = document.getElementById('sessionTag').value;
|
let session = document.getElementById('sessionTag').value;
|
||||||
data.collector.name = name
|
data.collector.name = name
|
||||||
data.collector.sessionTag =session
|
data.collector.sessionTag = session
|
||||||
|
|
||||||
let response = await fetch(`${baseUrl}/tiktok/connect?name=${data.collector.name}&session=${data.collector.sessionTag}`);
|
let response = await fetch(`${baseUrl}/tiktok/connect?name=${data.collector.name}&session=${data.collector.sessionTag}`);
|
||||||
let greeting = await response.text();
|
let greeting = await response.text();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.0.10-Release</version>
|
<version>1.0.14-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.0.10-Release</version>
|
<version>1.0.14-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.0.10-Release</version>
|
<version>1.0.14-Release</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>API</module>
|
<module>API</module>
|
||||||
<module>Client</module>
|
<module>Client</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user