mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Fix Eulerstream websocket roomInfo incorrectly being mapped!
This commit is contained in:
@@ -66,7 +66,6 @@ public class LiveUserDataMapper
|
|||||||
|
|
||||||
roomInfo.setTitle(liveRoom.get("title").getAsString());
|
roomInfo.setTitle(liveRoom.get("title").getAsString());
|
||||||
roomInfo.setStartTime(liveRoom.get("startTime").getAsLong());
|
roomInfo.setStartTime(liveRoom.get("startTime").getAsLong());
|
||||||
roomInfo.setTitle(liveRoom.get("title").getAsString());
|
|
||||||
roomInfo.setViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("userCount").getAsInt());
|
roomInfo.setViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("userCount").getAsInt());
|
||||||
roomInfo.setTotalViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("enterCount").getAsInt());
|
roomInfo.setTotalViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("enterCount").getAsInt());
|
||||||
roomInfo.setAgeRestricted(jsonObject.get("statusCode").getAsInt() == TikTokLiveHttpClient.TIKTOK_AGE_RESTRICTED_CODE);
|
roomInfo.setAgeRestricted(jsonObject.get("statusCode").getAsInt() == TikTokLiveHttpClient.TIKTOK_AGE_RESTRICTED_CODE);
|
||||||
@@ -92,9 +91,51 @@ public class LiveUserDataMapper
|
|||||||
roomInfo.setHostName(foundUser.getName());
|
roomInfo.setHostName(foundUser.getName());
|
||||||
|
|
||||||
return new LiveUserData.Response(json, statusEnum, roomInfo);
|
return new LiveUserData.Response(json, statusEnum, roomInfo);
|
||||||
} catch (JsonSyntaxException | IllegalStateException e) {
|
} catch (JsonSyntaxException | IllegalStateException | NullPointerException 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, null);
|
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LiveUserData.Response mapEulerstream(JsonObject jsonObject, Logger logger) {
|
||||||
|
try {
|
||||||
|
JsonObject roomInfoJson = jsonObject.getAsJsonObject("roomInfo");
|
||||||
|
JsonObject userJson = jsonObject.getAsJsonObject("user");
|
||||||
|
|
||||||
|
var roomId = roomInfoJson.get("id").getAsString();
|
||||||
|
var status = roomInfoJson.get("status").getAsInt();
|
||||||
|
|
||||||
|
TikTokRoomInfo roomInfo = new TikTokRoomInfo();
|
||||||
|
roomInfo.setRoomId(roomId);
|
||||||
|
roomInfo.setTitle(roomInfoJson.get("title").getAsString());
|
||||||
|
roomInfo.setStartTime(roomInfoJson.get("startTime").getAsLong());
|
||||||
|
roomInfo.setViewersCount(roomInfoJson.get("currentViewers").getAsInt());
|
||||||
|
roomInfo.setTotalViewersCount(roomInfoJson.get("totalViewers").getAsInt());
|
||||||
|
|
||||||
|
var statusEnum = switch (status) {
|
||||||
|
case 2 -> LiveUserData.UserStatus.Live;
|
||||||
|
case 3 -> LiveUserData.UserStatus.LivePaused;
|
||||||
|
case 4 -> LiveUserData.UserStatus.Offline;
|
||||||
|
default -> LiveUserData.UserStatus.NotFound;
|
||||||
|
};
|
||||||
|
|
||||||
|
User foundUser = new User(
|
||||||
|
Long.parseLong(userJson.get("numericUid").getAsString()),
|
||||||
|
userJson.get("uniqueId").getAsString(),
|
||||||
|
userJson.get("nickname").getAsString(),
|
||||||
|
userJson.get("signature").getAsString(),
|
||||||
|
new Picture(userJson.get("avatarUrl").getAsString()),
|
||||||
|
userJson.get("following").getAsLong(),
|
||||||
|
userJson.get("followers").getAsLong(),
|
||||||
|
List.of());
|
||||||
|
|
||||||
|
roomInfo.setHost(foundUser);
|
||||||
|
roomInfo.setHostName(foundUser.getName());
|
||||||
|
|
||||||
|
return new LiveUserData.Response(jsonObject.toString(), statusEnum, roomInfo);
|
||||||
|
} catch (JsonSyntaxException | IllegalStateException | NullPointerException e) {
|
||||||
|
logger.warning("Malformed Json: '"+jsonObject.toString()+"' - Error Message: "+e.getMessage());
|
||||||
|
return new LiveUserData.Response(jsonObject.toString(), LiveUserData.UserStatus.NotFound, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class TikTokWebSocketEulerListener extends TikTokWebSocketListener
|
|||||||
switch (oMsg.get("type").getAsString()) { // Should only receive these 2 types ever
|
switch (oMsg.get("type").getAsString()) { // Should only receive these 2 types ever
|
||||||
case "workerInfo" -> liveClient.getLogger().info(oMsg.toString()); // Always 1st message
|
case "workerInfo" -> liveClient.getLogger().info(oMsg.toString()); // Always 1st message
|
||||||
case "roomInfo" -> { // Always 2nd message
|
case "roomInfo" -> { // Always 2nd message
|
||||||
LiveUserData.Response data = LiveUserDataMapper.map(oMsg.getAsJsonObject("data").getAsJsonObject("raw").toString(), liveClient.getLogger());
|
LiveUserData.Response data = LiveUserDataMapper.mapEulerstream(oMsg.getAsJsonObject("data"), liveClient.getLogger());
|
||||||
liveClient.getRoomInfo().copy(data.getRoomInfo());
|
liveClient.getRoomInfo().copy(data.getRoomInfo());
|
||||||
eventHandler.publish(liveClient, new TikTokRoomInfoEvent(liveClient.getRoomInfo()));
|
eventHandler.publish(liveClient, new TikTokRoomInfoEvent(liveClient.getRoomInfo()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user