Skip to content

Commit

Permalink
Added new fields for User like FollowInfo (#58)
Browse files Browse the repository at this point in the history
* Added `timestamp` to `WebcastMessageEvent`, `WebcastChatMessageDetails`

* Generic protos at bottom

* `uint32` => `uint64` for field 2 in `WebcastMessageEvent`

* merge `WebcastChatMessageDetails` with `WebcastMessageEvent`

* Rename fields according to TikTok JS definitions

* Remove `method` field from `WebcastMessageEvent`

* Remove `roomId` from `WebcastMessageEvent`

* Add converter function for `WebcastMessageEvent`

* Add `secUid` to user attributes

* Added new fields for `User` like `FollowInfo`

* [+] topViewers

* `WebcastRoomUserSeqMessage`.`Users` => `TopUser`

* map top viewers

* `int64` => `int32` for follow counts

* map `followInfo` attributes

* rename `createTime` => `groupId`, `jsonAnchor` => `monitorExtra`

* parse `monitorExtra` json

Co-authored-by: zerodytrash <59258980+zerodytrash@users.noreply.github.com>
  • Loading branch information
carcabot and zerodytrash committed Aug 20, 2022
1 parent b37827b commit feb498b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
38 changes: 37 additions & 1 deletion src/lib/webcastDataConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function simplifyObject(webcastObject) {
delete webcastObject.eventDetails;
}

if (webcastObject.topViewers) {
webcastObject.topViewers = getTopViewerAttributes(webcastObject.topViewers);
}

if (webcastObject.battleUsers) {
let battleUsers = [];
webcastObject.battleUsers.forEach((user) => {
Expand Down Expand Up @@ -91,6 +95,16 @@ function simplifyObject(webcastObject) {
webcastObject.timestamp = parseInt(webcastObject.timestamp);
}
}

if (webcastObject.groupId) {
webcastObject.groupId = webcastObject.groupId.toString();
}

if (typeof webcastObject.monitorExtra === 'string' && webcastObject.monitorExtra.indexOf('{') === 0) {
try {
webcastObject.monitorExtra = JSON.parse(webcastObject.monitorExtra);
} catch (err) {}
}
}

if (webcastObject.emote) {
Expand Down Expand Up @@ -121,10 +135,23 @@ function getUserAttributes(webcastUser) {
uniqueId: webcastUser.uniqueId !== '' ? webcastUser.uniqueId : undefined,
nickname: webcastUser.nickname !== '' ? webcastUser.nickname : undefined,
profilePictureUrl: webcastUser.profilePicture?.urls[2],
followRole: webcastUser.extraAttributes?.followRole,
followRole: webcastUser.followInfo?.followStatus,
userBadges: mapBadges(webcastUser.badges),
userDetails: {
createTime: webcastUser.createTime?.toString(),
bioDescription: webcastUser.bioDescription,
},
};

if (webcastUser.followInfo) {
userAttributes.followInfo = {
followingCount: webcastUser.followInfo.followingCount,
followerCount: webcastUser.followInfo.followerCount,
followStatus: webcastUser.followInfo.followStatus,
pushStatus: webcastUser.followInfo.pushStatus,
};
}

userAttributes.isModerator = userAttributes.userBadges.some((x) => x.type && x.type.toLowerCase().includes('moderator'));
userAttributes.isNewGifter = userAttributes.userBadges.some((x) => x.type && x.type.toLowerCase().includes('live_ng_'));
userAttributes.isSubscriber = userAttributes.userBadges.some((x) => x.url && x.url.toLowerCase().includes('/sub_'));
Expand All @@ -143,6 +170,15 @@ function getEventAttributes(event) {
return event;
}

function getTopViewerAttributes(topViewers) {
return topViewers.map((viewer) => {
return {
user: viewer.user ? getUserAttributes(viewer.user) : null,
coinCount: viewer.coinCount ? parseInt(viewer.coinCount) : 0,
};
});
}

function mapBadges(badges) {
let simplifiedBadges = [];

Expand Down
27 changes: 19 additions & 8 deletions src/proto/tiktokSchema.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ message WebcastControlMessage {

// Statistics like viewer count
message WebcastRoomUserSeqMessage {
repeated TopUser topViewers = 2;
int32 viewerCount = 3;
}

message TopUser {
uint64 coinCount = 1;
User user = 2;
}
message WebcastChatMessage {
WebcastMessageEvent event = 1;
User user = 2;
Expand All @@ -48,14 +53,14 @@ message WebcastMemberMessage {
}

message WebcastGiftMessage {
User user = 7;

// New Data Structure since 04/2022
WebcastMessageEvent event = 1;
int32 giftId = 2;
int32 repeatCount = 5;
User user = 7;
int32 repeatEnd = 9;

uint64 groupId = 11;
WebcastGiftMessageGiftDetails giftDetails = 15;
string monitorExtra = 22;
WebcastGiftMessageGiftExtra giftExtra = 23;
}

Expand Down Expand Up @@ -230,10 +235,19 @@ message User {
uint64 userId = 1;
string nickname = 3;
ProfilePicture profilePicture = 9;
UserExtraAttributes extraAttributes = 22;
string uniqueId = 38;
string secUid = 46;
repeated UserBadgesAttributes badges = 64;
uint64 createTime = 16;
string bioDescription = 5;
FollowInfo followInfo = 22;
}

message FollowInfo {
int32 followingCount = 1;
int32 followerCount = 2;
int32 followStatus = 3;
int32 pushStatus = 4;
}

message LinkUser {
Expand All @@ -247,9 +261,6 @@ message ProfilePicture {
repeated string urls = 1;
}

message UserExtraAttributes {
int32 followRole = 3;
}

message UserBadgesAttributes {
repeated UserBadge badges = 21;
Expand Down

0 comments on commit feb498b

Please sign in to comment.