Add integration for Eulerstream websocket connections and other QOL changes! (#144)

* Quick string alteration for proper state!

* Remove -1 close code and convert to standard public static value with reference!

* Convert to and use LiveClientStopType enum for disconnecting websocket from magic numbers!

* Add capability to use Eulerstream Enterprise server and websocket!
This commit is contained in:
David Kohler
2025-09-16 21:46:56 -04:00
committed by GitHub
parent c8120d89b2
commit ab97affc73
20 changed files with 362 additions and 100 deletions

View File

@@ -32,7 +32,7 @@ import java.util.List;
public class GiftsDataMapper {
public GiftsData.Response map(String json) {
public static GiftsData.Response map(String json) {
var parsedJson = JsonParser.parseString(json);
var jsonObject = parsedJson.getAsJsonObject();
var gifts = jsonObject.entrySet()
@@ -43,7 +43,7 @@ public class GiftsDataMapper {
return new GiftsData.Response(json, gifts);
}
private Gift mapSingleGift(JsonElement jsonElement) {
private static Gift mapSingleGift(JsonElement jsonElement) {
var jsonObject = jsonElement.getAsJsonObject();
var id = jsonObject.get("id").getAsInt();
@@ -53,7 +53,7 @@ public class GiftsDataMapper {
return new Gift(id, name, diamondCost, new Picture(image), jsonObject);
}
public GiftsData.Response mapRoom(String json) {
public static GiftsData.Response mapRoom(String json) {
var parsedJson = JsonParser.parseString(json);
var jsonObject = parsedJson.getAsJsonObject();
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
@@ -69,7 +69,7 @@ public class GiftsDataMapper {
return new GiftsData.Response("", List.of());
}
private Gift mapSingleRoomGift(JsonElement jsonElement) {
private static Gift mapSingleRoomGift(JsonElement jsonElement) {
var jsonObject = jsonElement.getAsJsonObject();
var id = jsonObject.get("id").getAsInt();

View File

@@ -41,7 +41,7 @@ public class LiveDataMapper {
* 3 - ?
* 4 - Offline
*/
public LiveData.Response map(String json) {
public static LiveData.Response map(String json) {
var response = new LiveData.Response();
response.setJson(json);
@@ -128,7 +128,7 @@ public class LiveDataMapper {
return response;
}
public User getUser(JsonObject jsonElement) {
public static User getUser(JsonObject jsonElement) {
var id = jsonElement.get("id").getAsLong();
var name = jsonElement.get("display_id").getAsString();
var profileName = jsonElement.get("nickname").getAsString();

View File

@@ -23,6 +23,7 @@
package io.github.jwdeveloper.tiktok.http.mappers;
import com.google.gson.*;
import io.github.jwdeveloper.tiktok.*;
import io.github.jwdeveloper.tiktok.data.models.Picture;
import io.github.jwdeveloper.tiktok.data.models.users.User;
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
@@ -33,7 +34,7 @@ import java.util.logging.Logger;
public class LiveUserDataMapper
{
public LiveUserData.Response map(String json, Logger logger) {
public static LiveUserData.Response map(String json, Logger logger) {
try {
var jsonObject = JsonParser.parseString(json).getAsJsonObject();
@@ -43,14 +44,14 @@ public class LiveUserDataMapper
throw new TikTokLiveRequestException("fetchRoomIdFromTiktokApi -> Unable to fetch roomID, contact the developer");
}
if (message.equals("user_not_found")) {
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1, null);
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, null);
}
//live -> status 2
//live paused -> 3
//not live -> status 4
var element = jsonObject.get("data");
if (element.isJsonNull()) {
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1, null);
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, null);
}
var data = element.getAsJsonObject();
var user = data.getAsJsonObject("user");
@@ -58,8 +59,17 @@ public class LiveUserDataMapper
var roomId = user.get("roomId").getAsString();
var status = user.get("status").getAsInt();
TikTokRoomInfo roomInfo = new TikTokRoomInfo();
roomInfo.setRoomId(roomId);
var liveRoom = data.getAsJsonObject("liveRoom");
long startTime = liveRoom.get("startTime").getAsLong();
roomInfo.setTitle(liveRoom.get("title").getAsString());
roomInfo.setStartTime(liveRoom.get("startTime").getAsLong());
roomInfo.setTitle(liveRoom.get("title").getAsString());
roomInfo.setViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("userCount").getAsInt());
roomInfo.setTotalViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("enterCount").getAsInt());
roomInfo.setAgeRestricted(jsonObject.get("statusCode").getAsInt() == TikTokLiveHttpClient.TIKTOK_AGE_RESTRICTED_CODE);
var statusEnum = switch (status) {
case 2 -> LiveUserData.UserStatus.Live;
@@ -78,10 +88,13 @@ public class LiveUserDataMapper
stats.get("followerCount").getAsLong(),
List.of());
return new LiveUserData.Response(json, statusEnum, roomId, startTime, foundUser);
roomInfo.setHost(foundUser);
roomInfo.setHostName(foundUser.getName());
return new LiveUserData.Response(json, statusEnum, roomInfo);
} catch (JsonSyntaxException | IllegalStateException e) {
logger.warning("Malformed Json: '"+json+"' - Error Message: "+e.getMessage());
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1, null);
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, null);
}
}
}