mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 09:19:40 -05:00
Compare commits
16 Commits
1.5.0-Rele
...
1.6.0-Rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d467d79c3 | ||
|
|
33c98508c0 | ||
|
|
67948b14cc | ||
|
|
22e11a7822 | ||
|
|
4545503441 | ||
|
|
498d34a90b | ||
|
|
103ed7e3ed | ||
|
|
67e70c34bc | ||
|
|
786c24d267 | ||
|
|
966d2f65d8 | ||
|
|
7ba7143f5a | ||
|
|
92fde03f2b | ||
|
|
e058290118 | ||
|
|
d25741b229 | ||
|
|
560a8d7c3b | ||
|
|
6178bc25cf |
@@ -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.4.0-Release</version>
|
<version>1.5.4-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.LinkMicArmy;
|
import io.github.jwdeveloper.tiktok.data.models.LinkMicArmy;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicArmies;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicArmies;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggered every time a battle participant receives points. Contains the current status of the battle and the army that suported the group.
|
* Triggered every time a battle participant receives points. Contains the current status of the battle and the army that suported the group.
|
||||||
*/
|
*/
|
||||||
@@ -40,8 +40,10 @@ import java.util.List;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
||||||
private final Long battleId;
|
private final Long battleId;
|
||||||
|
/**
|
||||||
private final Integer battleStatus;
|
true if battle is finished otherwise false
|
||||||
|
*/
|
||||||
|
private final boolean finished;
|
||||||
|
|
||||||
private final Picture picture;
|
private final Picture picture;
|
||||||
|
|
||||||
@@ -52,6 +54,6 @@ public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
|||||||
battleId = msg.getId();
|
battleId = msg.getId();
|
||||||
armies = msg.getBattleItemsList().stream().map(LinkMicArmy::new).toList();
|
armies = msg.getBattleItemsList().stream().map(LinkMicArmy::new).toList();
|
||||||
picture = Picture.map(msg.getImage());
|
picture = Picture.map(msg.getImage());
|
||||||
battleStatus = msg.getBattleStatus();
|
finished = msg.getBattleStatus() == LinkMicBattleStatus.ARMY_FINISHED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,29 +22,50 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.events;
|
package io.github.jwdeveloper.tiktok.data.events;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.LinkMicBattleTeam;
|
import io.github.jwdeveloper.tiktok.data.models.battles.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggered every time a battle starts.
|
* Triggered every time a battle starts & ends
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent {
|
public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
||||||
|
{
|
||||||
private final Long battleId;
|
private final Long battleId;
|
||||||
private final List<LinkMicBattleTeam> team1;
|
/**
|
||||||
private final List<LinkMicBattleTeam> team2;
|
true if battle is finished otherwise false
|
||||||
|
*/
|
||||||
|
private final boolean finished;
|
||||||
|
private final List<Team> teams;
|
||||||
|
|
||||||
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
battleId = msg.getId();
|
battleId = msg.getId();
|
||||||
team1 = msg.getTeams1List().stream().map(LinkMicBattleTeam::new).toList();
|
finished = msg.getBattleStatus() == LinkMicBattleStatus.BATTLE_FINISHED;
|
||||||
team2 = msg.getTeams2List().stream().map(LinkMicBattleTeam::new).toList();
|
teams = new ArrayList<>();
|
||||||
|
if (msg.getHostTeamCount() == 2) { // 1v1 battle
|
||||||
|
teams.add(new Team1v1(msg.getHostTeam(0), msg));
|
||||||
|
teams.add(new Team1v1(msg.getHostTeam(1), msg));
|
||||||
|
} else { // 2v2 battle
|
||||||
|
if (isFinished()) {
|
||||||
|
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg));
|
||||||
|
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 2).findFirst().orElse(null), msg));
|
||||||
|
} else {
|
||||||
|
teams.add(new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg));
|
||||||
|
teams.add(new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info:
|
||||||
|
// - msg.getDetailsList() & msg.getViewerTeamList() both only have content when battle is finished
|
||||||
|
// - msg.getDetailsCount() & msg.getViewerTeamCount() always is 2 only when battle is finished
|
||||||
|
// - msg.getHostTeamCount() always is 2 for 1v1 or 4 for 2v2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
|
||||||
import lombok.Value;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Value
|
|
||||||
public class LinkMicBattleTeam {
|
|
||||||
Long teamId;
|
|
||||||
List<User> users;
|
|
||||||
|
|
||||||
public LinkMicBattleTeam(WebcastLinkMicBattle.LinkMicBattleTeam team) {
|
|
||||||
this.teamId = team.getId();
|
|
||||||
this.users = team.getUsersList().stream().map(User::new).toList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -44,11 +44,11 @@ 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.getUrlCount() - 1;
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return new Picture("");
|
return new Picture("");
|
||||||
}
|
}
|
||||||
var url = profilePicture.getUrlList(index);
|
var url = profilePicture.getUrl(index);
|
||||||
return new Picture(url);
|
return new Picture(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
public abstract class Team {
|
||||||
|
/**
|
||||||
|
* Provides a check for verifying if this team represents a 1v1 Team.
|
||||||
|
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean is1v1Team() {
|
||||||
|
return this instanceof Team1v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a check for verifying if this team represents a 1v1 Team.
|
||||||
|
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean is2v2Team() {
|
||||||
|
return this instanceof Team2v2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to get this team as a {@link Team1v1}. If this team is of some
|
||||||
|
* other type, an {@link IllegalStateException} will result. Hence it is best to use this method
|
||||||
|
* after ensuring that this element is of the desired type by calling {@link #is1v1Team()} first.
|
||||||
|
*
|
||||||
|
* @return this team as a {@link Team1v1}.
|
||||||
|
* @throws IllegalStateException if this team is of another type.
|
||||||
|
*/
|
||||||
|
public Team1v1 getAs1v1Team() {
|
||||||
|
if (is1v1Team())
|
||||||
|
return (Team1v1) this;
|
||||||
|
throw new IllegalStateException("Not a 1v1Team: " + this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to get this team as a {@link Team2v2}. If this team is of some
|
||||||
|
* other type, an {@link IllegalStateException} will result. Hence it is best to use this method
|
||||||
|
* after ensuring that this element is of the desired type by calling {@link #is2v2Team()} first.
|
||||||
|
*
|
||||||
|
* @return this team as a {@link Team2v2}.
|
||||||
|
* @throws IllegalStateException if this team is of another type.
|
||||||
|
*/
|
||||||
|
public Team2v2 getAs2v2Team() {
|
||||||
|
if (is2v2Team())
|
||||||
|
return (Team2v2) this;
|
||||||
|
throw new IllegalStateException("Not a 2v2Team: " + this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Team1v1 extends Team
|
||||||
|
{
|
||||||
|
/** Value >= 0 when finished otherwise -1 */
|
||||||
|
private final int totalPoints;
|
||||||
|
private final int winStreak;
|
||||||
|
private final User host;
|
||||||
|
private final List<Viewer> viewers;
|
||||||
|
|
||||||
|
public Team1v1(WebcastLinkMicBattle.LinkMicBattleHost hostTeam, WebcastLinkMicBattle msg) {
|
||||||
|
long hostId = hostTeam.getId();
|
||||||
|
this.winStreak = msg.getTeamDataList().stream().filter(data -> data.getTeamId() == hostId).map(data -> data.getData().getWinStreak()).findFirst().orElse(-1);
|
||||||
|
this.totalPoints = msg.getDetailsList().stream().filter(dets -> dets.getId() == hostId).map(dets -> dets.getSummary().getPoints()).findFirst().orElse(-1);
|
||||||
|
this.host = new User(hostTeam.getHostGroup(0).getHost(0));
|
||||||
|
this.viewers = msg.getViewerTeamList().stream().filter(team -> team.getId() == hostId).findFirst().map(topViewers ->
|
||||||
|
topViewers.getViewerGroup(0).getViewerList().stream().map(Viewer::new).toList()).orElseGet(ArrayList::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Team2v2 extends Team {
|
||||||
|
/** Value >= 0 when finished otherwise -1 */
|
||||||
|
private final int totalPoints;
|
||||||
|
|
||||||
|
private final List<User> hosts;
|
||||||
|
private final List<Viewer> viewers;
|
||||||
|
|
||||||
|
public Team2v2(WebcastLinkMicBattle.LinkMicBattleHost hostTeam1, WebcastLinkMicBattle.LinkMicBattleHost hostTeam2, WebcastLinkMicBattle msg) {
|
||||||
|
this.totalPoints = -1;
|
||||||
|
this.hosts = List.of(new User(hostTeam1.getHostGroup(0).getHost(0)), new User(hostTeam2.getHostGroup(0).getHost(0)));
|
||||||
|
this.viewers = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team2v2(WebcastLinkMicBattle.Host2v2Data hd, WebcastLinkMicBattle msg) {
|
||||||
|
this.totalPoints = hd.getTotalPoints();
|
||||||
|
var host = new User(msg.getHostTeamList().stream().filter(data -> data.getId() == hd.getHostdata(0).getHostId()).findFirst().orElseThrow().getHostGroup(0).getHost(0));
|
||||||
|
var cohost = new User(msg.getHostTeamList().stream().filter(data -> data.getId() == hd.getHostdata(1).getHostId()).findFirst().orElseThrow().getHostGroup(0).getHost(0));
|
||||||
|
this.hosts = List.of(host, cohost);
|
||||||
|
this.viewers = msg.getViewerTeamList().stream().filter(team -> team.getId() == host.getId() || team.getId() == cohost.getId()).findFirst().map(topViewers ->
|
||||||
|
topViewers.getViewerGroup(0).getViewerList().stream().map(Viewer::new).toList()).orElseGet(ArrayList::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Viewer {
|
||||||
|
private final User user;
|
||||||
|
private final int points;
|
||||||
|
|
||||||
|
public Viewer(WebcastLinkMicBattle.LinkMicBattleTopViewers.TopViewerGroup.TopViewer topViewer) {
|
||||||
|
this.user = new User(topViewer.getId(), null, topViewer.getProfileId(), Picture.map(topViewer.getImages(0)));
|
||||||
|
this.points = topViewer.getPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ package io.github.jwdeveloper.tiktok.data.models.users;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastEnvelopeMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@@ -136,6 +136,14 @@ public class User {
|
|||||||
this.picture = picture;
|
this.picture = picture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User(long id, String name, String profileId, Picture picture) {
|
||||||
|
this(id, name, profileId, picture, 0, 0, List.of(Badge.empty()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(WebcastLinkMicBattle.LinkMicBattleHost.HostGroup.Host host) {
|
||||||
|
this(host.getId(), host.getName(), host.getProfileId(), Picture.map(host.getImages(0)));
|
||||||
|
}
|
||||||
|
|
||||||
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
||||||
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
||||||
profileName = user.getNickname();
|
profileName = user.getNickname();
|
||||||
@@ -159,7 +167,6 @@ public class User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static User EMPTY = new User(0L,
|
public static User EMPTY = new User(0L,
|
||||||
"",
|
"",
|
||||||
Picture.Empty(),
|
Picture.Empty(),
|
||||||
@@ -209,4 +216,18 @@ public class User {
|
|||||||
0,
|
0,
|
||||||
List.of(Badge.empty()));
|
List.of(Badge.empty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + "'" +
|
||||||
|
", profileName='" + profileName + "'" +
|
||||||
|
", picture=" + picture +
|
||||||
|
", following=" + following +
|
||||||
|
", followers=" + followers +
|
||||||
|
", badges=" + badges +
|
||||||
|
", attributes=" + attributes +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ public interface LiveRoomInfo
|
|||||||
String getRoomId();
|
String getRoomId();
|
||||||
String getHostName();
|
String getHostName();
|
||||||
String getTitle();
|
String getTitle();
|
||||||
User getHostUser();
|
User getHost();
|
||||||
List<RankingUser> getUsersRanking();
|
List<RankingUser> getUsersRanking();
|
||||||
ConnectionState getConnectionState();
|
ConnectionState getConnectionState();
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,8 @@ message Text {
|
|||||||
|
|
||||||
// @Image
|
// @Image
|
||||||
message Image {
|
message Image {
|
||||||
repeated string urlList = 1;
|
repeated string url = 1;
|
||||||
|
string extras = 2;
|
||||||
bool isAnimated = 9;
|
bool isAnimated = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,14 @@ enum LinkmicApplierSortSetting {
|
|||||||
LINKMIC_APPLIER_SORT_SETTING_BY_GIFT_SCORE = 1;
|
LINKMIC_APPLIER_SORT_SETTING_BY_GIFT_SCORE = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum LinkMicBattleStatus {
|
||||||
|
BATTLE_ARMY_UNKNOWN = 0;
|
||||||
|
ARMY_ONGOING = 1;
|
||||||
|
ARMY_FINISHED = 2;
|
||||||
|
BATTLE_ONGOING = 4;
|
||||||
|
BATTLE_FINISHED = 5;
|
||||||
|
}
|
||||||
|
|
||||||
enum HashtagNamespace {
|
enum HashtagNamespace {
|
||||||
GLOBAL = 0;
|
GLOBAL = 0;
|
||||||
GAMING = 1;
|
GAMING = 1;
|
||||||
|
|||||||
@@ -521,7 +521,7 @@ message WebcastLinkMicArmies {
|
|||||||
uint64 id2 = 4;
|
uint64 id2 = 4;
|
||||||
uint64 timeStamp1 = 5;
|
uint64 timeStamp1 = 5;
|
||||||
uint64 timeStamp2 = 6;
|
uint64 timeStamp2 = 6;
|
||||||
int32 battleStatus = 7; // SHOULD BE AN ENUM
|
LinkMicBattleStatus battleStatus = 7;
|
||||||
uint64 data1 = 8;
|
uint64 data1 = 8;
|
||||||
uint64 data2 = 9;
|
uint64 data2 = 9;
|
||||||
uint32 data3 = 10;
|
uint32 data3 = 10;
|
||||||
@@ -574,11 +574,26 @@ message WebcastLinkMicBattle {
|
|||||||
Common common = 1;
|
Common common = 1;
|
||||||
uint64 id = 2;
|
uint64 id = 2;
|
||||||
LinkMicBattleConfig battleConfig = 3;
|
LinkMicBattleConfig battleConfig = 3;
|
||||||
uint32 data2 = 4;
|
LinkMicBattleStatus battleStatus = 4;
|
||||||
repeated LinkMicBattleDetails details = 5;
|
repeated LinkMicBattleDetails details = 5;
|
||||||
repeated LinkMicBattleTeam teams1 = 9;
|
repeated LinkMicBattleTopViewers viewerTeam = 9;
|
||||||
repeated LinkMicBattleTeam teams2 = 10;
|
repeated LinkMicBattleHost hostTeam = 10;
|
||||||
repeated LinkMicBattleTeamData teamData = 13;
|
repeated LinkMicBattleTeamData teamData = 13;
|
||||||
|
uint64 unknownData16 = 16;
|
||||||
|
repeated Host2v2Data hostData2v2 = 17;
|
||||||
|
|
||||||
|
message Host2v2Data {
|
||||||
|
uint32 teamNumber = 1;
|
||||||
|
repeated HostData hostdata = 2;
|
||||||
|
uint32 unknownData3 = 3;
|
||||||
|
uint32 totalPoints = 4;
|
||||||
|
|
||||||
|
message HostData {
|
||||||
|
uint64 hostId = 1;
|
||||||
|
uint32 points = 2;
|
||||||
|
string hostIdStr = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message LinkMicBattleConfig {
|
message LinkMicBattleConfig {
|
||||||
uint64 id1 = 1;
|
uint64 id1 = 1;
|
||||||
@@ -586,29 +601,69 @@ message WebcastLinkMicBattle {
|
|||||||
uint32 data1 = 3;
|
uint32 data1 = 3;
|
||||||
uint64 id2 = 4;
|
uint64 id2 = 4;
|
||||||
uint32 data2 = 5;
|
uint32 data2 = 5;
|
||||||
|
uint32 data3 = 6;
|
||||||
|
uint32 data4 = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
message LinkMicBattleTeamData {
|
||||||
|
uint64 teamId = 1;
|
||||||
|
LinkMicBattleData data = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkMicBattleData {
|
message LinkMicBattleData {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
uint32 data1 = 2;
|
uint32 data1 = 2;
|
||||||
uint32 data2 = 3;
|
uint32 winStreak = 3;
|
||||||
uint32 data3 = 5;
|
uint32 data3 = 5;
|
||||||
string url = 6;
|
string url = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkMicBattleDetails {
|
message LinkMicBattleDetails {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
LinkMicBattleData details = 2;
|
LinkMicBattleDetailsSummary summary = 2;
|
||||||
}
|
|
||||||
|
|
||||||
message LinkMicBattleTeam {
|
message LinkMicBattleDetailsSummary {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
repeated User users = 2;
|
uint32 unknownData2 = 2;
|
||||||
|
uint32 points = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkMicBattleTeamData {
|
message LinkMicBattleTopViewers {
|
||||||
uint64 teamId = 1;
|
uint64 id = 1;
|
||||||
LinkMicBattleData data = 2;
|
repeated TopViewerGroup viewerGroup = 2;
|
||||||
|
|
||||||
|
message TopViewerGroup {
|
||||||
|
repeated TopViewer viewer = 1;
|
||||||
|
uint32 points = 2;
|
||||||
|
string hostIdOrTeamNum = 3; // 1v1 Battle = HostId | 2v2 Battle = Team # - 1 & 2
|
||||||
|
|
||||||
|
message TopViewer {
|
||||||
|
uint64 id = 1;
|
||||||
|
uint32 points = 2;
|
||||||
|
string profileId = 3;
|
||||||
|
repeated Image images = 4;
|
||||||
|
string stringId = 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message LinkMicBattleHost {
|
||||||
|
uint64 id = 1;
|
||||||
|
repeated HostGroup hostGroup = 2;
|
||||||
|
|
||||||
|
message HostGroup {
|
||||||
|
repeated Host host = 1;
|
||||||
|
uint32 points = 2;
|
||||||
|
string hostId = 3;
|
||||||
|
|
||||||
|
message Host {
|
||||||
|
uint64 id = 1;
|
||||||
|
string profileId = 2;
|
||||||
|
repeated Image images = 3;
|
||||||
|
string name = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,5 +848,3 @@ message RoomVerifyMessage {
|
|||||||
int64 noticeType = 4;
|
int64 noticeType = 4;
|
||||||
bool closeRoom = 5;
|
bool closeRoom = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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.4.0-Release</version>
|
<version>1.5.4-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -61,11 +61,6 @@ public class TikTokRoomInfo implements LiveRoomInfo {
|
|||||||
return connectionState == state;
|
return connectionState == state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public User getHostUser() {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateRanking(List<RankingUser> rankingUsers) {
|
public void updateRanking(List<RankingUser> rankingUsers) {
|
||||||
usersRanking.clear();
|
usersRanking.clear();
|
||||||
usersRanking.addAll(rankingUsers);
|
usersRanking.addAll(rankingUsers);
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.http.mappers.*;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.net.http.*;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ActionResult<T> {
|
public class ActionResult<T> {
|
||||||
|
|
||||||
|
private static final Gson gson = new Gson().newBuilder().disableHtmlEscaping()
|
||||||
|
.registerTypeHierarchyAdapter(HttpResponse.class, new HttpResponseJsonMapper())
|
||||||
|
.registerTypeHierarchyAdapter(HttpRequest.class, new HttpRequestJsonMapper())
|
||||||
|
.setPrettyPrinting().create();
|
||||||
|
|
||||||
private boolean success = true;
|
private boolean success = true;
|
||||||
private T content;
|
private T content;
|
||||||
private String message;
|
private String message;
|
||||||
@@ -93,7 +100,7 @@ public class ActionResult<T> {
|
|||||||
public JsonObject toJson() {
|
public JsonObject toJson() {
|
||||||
JsonObject map = new JsonObject();
|
JsonObject map = new JsonObject();
|
||||||
map.addProperty("success", success);
|
map.addProperty("success", success);
|
||||||
map.add("content", new Gson().toJsonTree(content));
|
map.add("content", gson.toJsonTree(content));
|
||||||
map.addProperty("message", message);
|
map.addProperty("message", message);
|
||||||
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
||||||
return map;
|
return map;
|
||||||
@@ -101,6 +108,6 @@ public class ActionResult<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ActionResult: "+new Gson().newBuilder().setPrettyPrinting().create().toJson(toJson());
|
return "ActionResult: "+gson.toJson(toJson());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
|
||||||
|
public class HttpRequestJsonMapper implements JsonSerializer<HttpRequest>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(HttpRequest src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("method", src.method());
|
||||||
|
object.add("timeout", context.serialize(src.timeout().toString()));
|
||||||
|
object.addProperty("expectContinue", src.expectContinue());
|
||||||
|
object.add("uri", context.serialize(src.uri()));
|
||||||
|
object.add("version", context.serialize(src.version().toString()));
|
||||||
|
object.add("headers", context.serialize(src.headers().map()));
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
|
||||||
|
public class HttpResponseJsonMapper implements JsonSerializer<HttpResponse>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(HttpResponse src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("statusCode", src.statusCode());
|
||||||
|
object.add("request", context.serialize(src.request()));
|
||||||
|
object.add("headers", context.serialize(src.headers().map()));
|
||||||
|
object.add("body", context.serialize(src.body()));
|
||||||
|
object.add("uri", context.serialize(src.uri().toString()));
|
||||||
|
object.add("version", context.serialize(src.version().toString()));
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,7 +65,7 @@ public class LiveUserDataMapper
|
|||||||
};
|
};
|
||||||
|
|
||||||
return new LiveUserData.Response(json, statusEnum, roomId, startTime);
|
return new LiveUserData.Response(json, statusEnum, roomId, startTime);
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException | IllegalStateException e) {
|
||||||
logger.warning("Malformed Json: '"+json+"' - Error Message: "+e.getMessage());
|
logger.warning("Malformed Json: '"+json+"' - Error Message: "+e.getMessage());
|
||||||
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(e));
|
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(e));
|
||||||
}
|
}
|
||||||
if (isNotClosing()) {
|
if (isOpen()) {
|
||||||
sendPing();
|
sendPing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,8 +79,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
pushFrameBuilder.setPayloadType("ack");
|
pushFrameBuilder.setPayloadType("ack");
|
||||||
pushFrameBuilder.setLogId(websocketPushFrame.getLogId());
|
pushFrameBuilder.setLogId(websocketPushFrame.getLogId());
|
||||||
pushFrameBuilder.setPayload(webcastResponse.getInternalExtBytes());
|
pushFrameBuilder.setPayload(webcastResponse.getInternalExtBytes());
|
||||||
if (isNotClosing())
|
if (isOpen()) {
|
||||||
{
|
|
||||||
this.send(pushFrameBuilder.build().toByteArray());
|
this.send(pushFrameBuilder.build().toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,7 +89,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
@Override
|
@Override
|
||||||
public void onOpen(ServerHandshake serverHandshake) {
|
public void onOpen(ServerHandshake serverHandshake) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokConnectedEvent());
|
tikTokEventHandler.publish(tikTokLiveClient, new TikTokConnectedEvent());
|
||||||
if (isNotClosing()) {
|
if (isOpen()) {
|
||||||
sendPing();
|
sendPing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +103,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Exception error) {
|
public void onError(Exception error) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(error));
|
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(error));
|
||||||
if (isNotClosing()) {
|
if (isOpen()) {
|
||||||
sendPing();
|
sendPing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,10 +128,6 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNotClosing() {
|
|
||||||
return !isClosed() && !isClosing();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(String s) {
|
public void onMessage(String s) {
|
||||||
// System.err.println(s);
|
// System.err.println(s);
|
||||||
|
|||||||
@@ -117,7 +117,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().addUrl(giftImage).build());
|
||||||
giftBuilder.setType(streakable ? 1 : 0);
|
giftBuilder.setType(streakable ? 1 : 0);
|
||||||
userBuilder.setId(userId);
|
userBuilder.setId(userId);
|
||||||
|
|
||||||
|
|||||||
@@ -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.4.0-Release</version>
|
<version>1.5.4-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>extension-collector</artifactId>
|
<artifactId>extension-collector</artifactId>
|
||||||
<version>1.4.0-Release</version>
|
<version>1.5.4-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -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.4.0-Release</version>
|
<version>1.5.4-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<version>1.4.0-Release</version>
|
<version>1.5.4-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
<version>1.4.0-Release</version>
|
<version>1.5.4-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.extension.collector.api;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
|
public interface CollectorEvent {
|
||||||
|
boolean execute(LiveClient client, Document document);
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.github.jwdeveloper.tiktok.extension.collector.api.settings;
|
package io.github.jwdeveloper.tiktok.extension.collector.api.settings;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.extension.collector.api.CollectorEvent;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
|
||||||
@@ -9,5 +10,5 @@ import java.util.function.Function;
|
|||||||
@Data
|
@Data
|
||||||
public class CollectorListenerSettings {
|
public class CollectorListenerSettings {
|
||||||
private Map<String, Object> extraFields;
|
private Map<String, Object> extraFields;
|
||||||
private Function<Document, Boolean> filter;
|
private CollectorEvent filter;
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.extension.collector.impl;
|
package io.github.jwdeveloper.tiktok.extension.collector.impl;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.extension.collector.api.CollectorEvent;
|
||||||
import io.github.jwdeveloper.tiktok.extension.collector.api.Storage;
|
import io.github.jwdeveloper.tiktok.extension.collector.api.Storage;
|
||||||
import io.github.jwdeveloper.tiktok.extension.collector.api.settings.CollectorListenerSettings;
|
import io.github.jwdeveloper.tiktok.extension.collector.api.settings.CollectorListenerSettings;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
@@ -40,6 +41,7 @@ public class DataCollector {
|
|||||||
public void connect() {
|
public void connect() {
|
||||||
storage.connect();
|
storage.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
storage.disconnect();
|
storage.disconnect();
|
||||||
}
|
}
|
||||||
@@ -49,11 +51,11 @@ public class DataCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DataCollectorListener newListener(Map<String, Object> additionalFields) {
|
public DataCollectorListener newListener(Map<String, Object> additionalFields) {
|
||||||
return newListener(additionalFields, (e) -> true);
|
return newListener(additionalFields, (live, document) -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataCollectorListener newListener(Map<String, Object> additionalFields,
|
public DataCollectorListener newListener(Map<String, Object> additionalFields,
|
||||||
Function<Document, Boolean> filter) {
|
CollectorEvent filter) {
|
||||||
var settings = new CollectorListenerSettings();
|
var settings = new CollectorListenerSettings();
|
||||||
settings.setExtraFields(additionalFields);
|
settings.setExtraFields(additionalFields);
|
||||||
settings.setFilter(filter);
|
settings.setFilter(filter);
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ import org.bson.Document;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.UUID;
|
import java.util.Date;
|
||||||
|
|
||||||
public class DataCollectorListener implements LiveDataCollector {
|
public class DataCollectorListener implements LiveDataCollector {
|
||||||
|
|
||||||
private final Storage storage;
|
private final Storage storage;
|
||||||
private final CollectorListenerSettings settings;
|
private final CollectorListenerSettings settings;
|
||||||
private String sessionId;
|
private String roomId;
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
public DataCollectorListener(Storage collection, CollectorListenerSettings settings) {
|
public DataCollectorListener(Storage collection, CollectorListenerSettings settings) {
|
||||||
@@ -41,44 +41,42 @@ public class DataCollectorListener implements LiveDataCollector {
|
|||||||
@TikTokEventObserver
|
@TikTokEventObserver
|
||||||
private void onEvent(LiveClient liveClient, TikTokEvent event) {
|
private void onEvent(LiveClient liveClient, TikTokEvent event) {
|
||||||
if (event instanceof TikTokConnectingEvent) {
|
if (event instanceof TikTokConnectingEvent) {
|
||||||
sessionId = UUID.randomUUID().toString();
|
|
||||||
userName = liveClient.getRoomInfo().getHostName();
|
userName = liveClient.getRoomInfo().getHostName();
|
||||||
|
roomId = liveClient.getRoomInfo().getRoomId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event instanceof TikTokErrorEvent) {
|
if (event instanceof TikTokErrorEvent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
includeEvent(event);
|
includeEvent(liveClient, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TikTokEventObserver
|
@TikTokEventObserver
|
||||||
private void onError(LiveClient liveClient, TikTokErrorEvent event) {
|
private void onError(LiveClient liveClient, TikTokErrorEvent event) {
|
||||||
event.getException().printStackTrace();
|
event.getException().printStackTrace();
|
||||||
includeError(event);
|
includeError(liveClient, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void includeResponse(LiveClient liveClient, WebcastResponse message) {
|
private void includeResponse(LiveClient liveClient, WebcastResponse message) {
|
||||||
var messageContent = Base64.getEncoder().encodeToString(message.toByteArray());
|
var messageContent = Base64.getEncoder().encodeToString(message.toByteArray());
|
||||||
insertDocument(createDocument("response", "webcast", messageContent));
|
insertDocument(liveClient, createDocument("response", "webcast", messageContent));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void includeMessage(LiveClient liveClient, WebcastResponse.Message message) {
|
private void includeMessage(LiveClient liveClient, WebcastResponse.Message message) {
|
||||||
var method = message.getMethod();
|
var method = message.getMethod();
|
||||||
var messageContent = Base64.getEncoder().encodeToString(message.getPayload().toByteArray());
|
var messageContent = Base64.getEncoder().encodeToString(message.getPayload().toByteArray());
|
||||||
|
insertDocument(liveClient, createDocument("message", method, messageContent));
|
||||||
insertDocument(createDocument("message", method, messageContent));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void includeEvent(TikTokEvent event) {
|
private void includeEvent(LiveClient client, TikTokEvent event) {
|
||||||
var json = JsonUtil.toJson(event);
|
var json = JsonUtil.toJson(event);
|
||||||
var content = Base64.getEncoder().encodeToString(json.getBytes());
|
var content = Base64.getEncoder().encodeToString(json.getBytes());
|
||||||
var name = event.getClass().getSimpleName();
|
var name = event.getClass().getSimpleName();
|
||||||
insertDocument(createDocument("event", name, content));
|
insertDocument(client, createDocument("event", name, content));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void includeError(TikTokErrorEvent event) {
|
private void includeError(LiveClient client, TikTokErrorEvent event) {
|
||||||
var exception = event.getException();
|
var exception = event.getException();
|
||||||
var exceptionName = event.getException().getClass().getSimpleName();
|
var exceptionName = event.getException().getClass().getSimpleName();
|
||||||
|
|
||||||
@@ -86,18 +84,18 @@ public class DataCollectorListener implements LiveDataCollector {
|
|||||||
var pw = new PrintWriter(sw);
|
var pw = new PrintWriter(sw);
|
||||||
event.getException().printStackTrace(pw);
|
event.getException().printStackTrace(pw);
|
||||||
var content = sw.toString();
|
var content = sw.toString();
|
||||||
|
var contentBase64 = Base64.getEncoder().encodeToString(content.getBytes());
|
||||||
var doc = createDocument("error", exceptionName, content);
|
var doc = createDocument("error", exceptionName, contentBase64);
|
||||||
if (exception instanceof TikTokLiveMessageException ex) {
|
if (exception instanceof TikTokLiveMessageException ex) {
|
||||||
doc.append("message", ex.messageToBase64())
|
doc.append("message", ex.messageToBase64())
|
||||||
.append("response", ex.webcastResponseToBase64());
|
.append("response", ex.webcastResponseToBase64());
|
||||||
}
|
}
|
||||||
insertDocument(doc);
|
insertDocument(client, doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void insertDocument(Document document) {
|
private void insertDocument(LiveClient client, Document document) {
|
||||||
if (!settings.getFilter().apply(document)) {
|
if (!settings.getFilter().execute(client, document)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
storage.insert(document);
|
storage.insert(document);
|
||||||
@@ -106,7 +104,7 @@ public class DataCollectorListener implements LiveDataCollector {
|
|||||||
|
|
||||||
private Document createDocument(String dataType, String dataTypeName, String content) {
|
private Document createDocument(String dataType, String dataTypeName, String content) {
|
||||||
var doc = new Document();
|
var doc = new Document();
|
||||||
doc.append("session", sessionId);
|
doc.append("roomId", roomId);
|
||||||
for (var entry : settings.getExtraFields().entrySet()) {
|
for (var entry : settings.getExtraFields().entrySet()) {
|
||||||
doc.append(entry.getKey(), entry.getValue());
|
doc.append(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
@@ -114,6 +112,7 @@ public class DataCollectorListener implements LiveDataCollector {
|
|||||||
doc.append("dataType", dataType);
|
doc.append("dataType", dataType);
|
||||||
doc.append("dataTypeName", dataTypeName);
|
doc.append("dataTypeName", dataTypeName);
|
||||||
doc.append("content", content);
|
doc.append("content", content);
|
||||||
|
doc.append("createdAt", new Date());
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.4.0-Release</version>
|
<version>1.5.4-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>extension-recorder</artifactId>
|
<artifactId>extension-recorder</artifactId>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
|||||||
import io.github.jwdeveloper.tiktok.extension.recorder.api.LiveRecorder;
|
import io.github.jwdeveloper.tiktok.extension.recorder.api.LiveRecorder;
|
||||||
import io.github.jwdeveloper.tiktok.extension.recorder.impl.data.*;
|
import io.github.jwdeveloper.tiktok.extension.recorder.impl.data.*;
|
||||||
import io.github.jwdeveloper.tiktok.extension.recorder.impl.enums.LiveQuality;
|
import io.github.jwdeveloper.tiktok.extension.recorder.impl.enums.LiveQuality;
|
||||||
|
import io.github.jwdeveloper.tiktok.extension.recorder.impl.event.TikTokLiveRecorderStartedEvent;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||||
|
|
||||||
@@ -60,7 +61,9 @@ public class RecorderListener implements LiveRecorder {
|
|||||||
var json = event.getLiveData().getJson();
|
var json = event.getLiveData().getJson();
|
||||||
|
|
||||||
liveClient.getLogger().info("Searching for live download url");
|
liveClient.getLogger().info("Searching for live download url");
|
||||||
downloadData = settings.getPrepareDownloadData() != null ? settings.getPrepareDownloadData().apply(json) : mapToDownloadData(json);
|
downloadData = settings.getPrepareDownloadData() != null ?
|
||||||
|
settings.getPrepareDownloadData().apply(json) :
|
||||||
|
mapToDownloadData(json);
|
||||||
|
|
||||||
if (downloadData.getDownloadLiveUrl().isEmpty())
|
if (downloadData.getDownloadLiveUrl().isEmpty())
|
||||||
liveClient.getLogger().warning("Unable to find download live url!");
|
liveClient.getLogger().warning("Unable to find download live url!");
|
||||||
@@ -72,8 +75,11 @@ public class RecorderListener implements LiveRecorder {
|
|||||||
private void onConnected(LiveClient liveClient, TikTokConnectedEvent event) {
|
private void onConnected(LiveClient liveClient, TikTokConnectedEvent event) {
|
||||||
if (isConnected())
|
if (isConnected())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
liveDownloadThread = new Thread(() -> {
|
liveDownloadThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
|
liveClient.getLogger().info("Recording started");
|
||||||
var url = new URL(downloadData.getFullUrl());
|
var url = new URL(downloadData.getFullUrl());
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||||
var headers = LiveClientSettings.DefaultRequestHeaders();
|
var headers = LiveClientSettings.DefaultRequestHeaders();
|
||||||
@@ -98,13 +104,19 @@ public class RecorderListener implements LiveRecorder {
|
|||||||
}
|
}
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
} finally {
|
} finally {
|
||||||
liveClient.getLogger().severe("Stopped recording "+liveClient.getRoomInfo().getHostName());
|
liveClient.getLogger().severe("Stopped recording " + liveClient.getRoomInfo().getHostName());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var recordingStartedEvent = new TikTokLiveRecorderStartedEvent(downloadData);
|
||||||
|
liveClient.publishEvent(recordingStartedEvent);
|
||||||
|
if (recordingStartedEvent.isCanceled()) {
|
||||||
|
liveClient.getLogger().info("Recording cancelled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
liveDownloadThread.start();
|
liveDownloadThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,32 +132,6 @@ public class RecorderListener implements LiveRecorder {
|
|||||||
liveDownloadThread.interrupt();
|
liveDownloadThread.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int terminateFfmpeg(final Process process) {
|
|
||||||
if (!process.isAlive()) {
|
|
||||||
// ffmpeg -version, do nothing
|
|
||||||
return process.exitValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ffmpeg -f x11grab
|
|
||||||
System.out.println("About to destroy the child process...");
|
|
||||||
try (final OutputStreamWriter out = new OutputStreamWriter(process.getOutputStream(), UTF_8)) {
|
|
||||||
out.write('q');
|
|
||||||
} catch (final IOException ioe) {
|
|
||||||
ioe.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (!process.waitFor(5L, TimeUnit.SECONDS)) {
|
|
||||||
process.destroy();
|
|
||||||
process.waitFor();
|
|
||||||
}
|
|
||||||
return process.exitValue();
|
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
System.out.println("Interrupted");
|
|
||||||
ie.printStackTrace();
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private DownloadData mapToDownloadData(String json) {
|
private DownloadData mapToDownloadData(String json) {
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,18 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.extension.recorder.impl.data.DownloadData;
|
import io.github.jwdeveloper.tiktok.extension.recorder.impl.data.DownloadData;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Data
|
@Getter
|
||||||
public class TikTokLiveRecorderStartedEvent extends TikTokEvent
|
public class TikTokLiveRecorderStartedEvent extends TikTokEvent {
|
||||||
{
|
|
||||||
DownloadData downloadData;
|
DownloadData downloadData;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
boolean canceled;
|
||||||
|
|
||||||
|
public TikTokLiveRecorderStartedEvent(DownloadData downloadData) {
|
||||||
|
this.downloadData = downloadData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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.4.0-Release</version>
|
<version>1.5.4-Release</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>API</module>
|
<module>API</module>
|
||||||
<module>Client</module>
|
<module>Client</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user