Skip to content

Commit

Permalink
Merge pull request #17 from jwdeveloper/develop-1-0-5
Browse files Browse the repository at this point in the history
New Events
- onLiveUnpaused()
- onRoomInfo() triggered when LiveRoomInfo got updated

Removed:
- clientSettings.setHandleExistingEvents - onRoom Replaced with onRoomInfo event - onRoomUserInfo Replaced with onRoomInfo event

Gifts:
- onGift event was not triggered for the more expensive gifts
- onGiftCombo with more expensive gifts was stuck in the GiftSendType.Begin state

Fixed:
- setPrintToConsole(false) was not disabling logs
  • Loading branch information
jwdeveloper authored Nov 13, 2023
2 parents c3a48c4 + 1977cbe commit ea8c740
Show file tree
Hide file tree
Showing 32 changed files with 1,281 additions and 440 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public class ClientSettings {
*/
private Duration retryConnectionTimeout;

/**
* Whether to handle Events received from Room when Connecting
*/
private boolean handleExistingEvents;

/**
* Whether to print Logs to Console
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static ClientSettings DefaultClientSettings() {
var clientSettings = new ClientSettings();
clientSettings.setTimeout(Duration.ofSeconds(DEFAULT_TIMEOUT));
clientSettings.setClientLanguage("en-US");
clientSettings.setHandleExistingEvents(true);
clientSettings.setRetryOnConnectionFailure(false);
clientSettings.setRetryConnectionTimeout(Duration.ofSeconds(1));
clientSettings.setPrintToConsole(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.jwdeveloper.tiktok.data.events;

import io.github.jwdeveloper.tiktok.annotations.EventMeta;
import io.github.jwdeveloper.tiktok.annotations.EventType;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;


@EventMeta(eventType = EventType.Message)
public class TikTokLiveUnpausedEvent extends TikTokEvent {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.jwdeveloper.tiktok.data.events.room;

import io.github.jwdeveloper.tiktok.annotations.EventMeta;
import io.github.jwdeveloper.tiktok.annotations.EventType;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;


/*
Triggered when LiveRoomInfo got updated such as likes, viewers, ranking ....
*/
@Getter
@AllArgsConstructor
@EventMeta(eventType = EventType.Message)
public class TikTokRoomInfoEvent extends TikTokEvent
{
LiveRoomInfo roomInfo;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class User {
@Getter(AccessLevel.NONE)
private Set<UserAttribute> attributes;



public List<UserAttribute> getAttributes() {
return attributes.stream().toList();
}
Expand Down Expand Up @@ -107,6 +109,23 @@ public User(Long userId,
this.attributes = new HashSet<>();
}

public User(Long id,
String name,
String profileName,
Picture picture,
long following,
long followers,
List<Badge> badges) {
this.id = id;
this.name = name;
this.profileName = profileName;
this.picture = picture;
this.following = following;
this.followers = followers;
this.badges = badges;
this.attributes = new HashSet<>();
}

public User(Long userId,
String nickName) {
this.id = userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,31 @@
*/
package io.github.jwdeveloper.tiktok.live;

import io.github.jwdeveloper.tiktok.data.models.RankingUser;
import io.github.jwdeveloper.tiktok.data.models.users.User;
import io.github.jwdeveloper.tiktok.models.ConnectionState;

import java.util.List;

public interface LiveRoomInfo
{
/**
*
* @return get current count of viewers of live
*/
int getViewersCount();

/**
*
* @return get total current count of viewers since beginning of live
*/
int getTotalViewersCount();
int getLikesCount();
boolean isAgeRestricted();
String getRoomId();
String getHostName();
String getTitle();
User getHostUser();
List<RankingUser> getUsersRanking();
ConnectionState getConnectionState();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
*/
package io.github.jwdeveloper.tiktok.live;

import io.github.jwdeveloper.tiktok.data.models.users.User;
import lombok.Data;

@Data
public class LiveRoomMeta {

private LiveRoomStatus status;
private boolean ageRestricted;
private String titie;
private int likeCount;
private int totalViewers;
private int viewers;
private User host;

public enum LiveRoomStatus
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@

import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
import io.github.jwdeveloper.tiktok.data.events.*;
import io.github.jwdeveloper.tiktok.data.events.envelop.TikTokChestEvent;
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.room.TikTokRoomEvent;
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomUserInfoEvent;
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomInfoEvent;
import io.github.jwdeveloper.tiktok.data.events.social.TikTokFollowEvent;
import io.github.jwdeveloper.tiktok.data.events.social.TikTokJoinEvent;
import io.github.jwdeveloper.tiktok.data.events.social.TikTokLikeEvent;
Expand All @@ -40,9 +38,7 @@

public interface EventsBuilder<T> {

T onRoom(EventConsumer<TikTokRoomEvent> event);

T onRoomUserInfo(EventConsumer<TikTokRoomUserInfoEvent> event);
T onRoomInfo(EventConsumer<TikTokRoomInfoEvent> event);

T onComment(EventConsumer<TikTokCommentEvent> event);

Expand All @@ -53,8 +49,6 @@ public interface EventsBuilder<T> {
T onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> event);




T onGiftCombo(EventConsumer<TikTokGiftComboEvent> event);
T onGift(EventConsumer<TikTokGiftEvent> event);

Expand All @@ -71,12 +65,13 @@ public interface EventsBuilder<T> {
T onJoin(EventConsumer<TikTokJoinEvent> event);

T onShare(EventConsumer<TikTokShareEvent> event);
T onUnhandledSocial(EventConsumer<TikTokUnhandledSocialEvent> event);

// T onChest(EventConsumer<TikTokChestEvent> event);

T onLivePaused(EventConsumer<TikTokLivePausedEvent> event);

T onLiveUnpaused(EventConsumer<TikTokLiveUnpausedEvent> event);

T onLiveEnded(EventConsumer<TikTokLiveEndedEvent> event);

T onConnected(EventConsumer<TikTokConnectedEvent> event);
Expand Down
1 change: 1 addition & 0 deletions API/src/main/proto/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ enum MemberMessageAction {
enum ControlAction {
ControlActionUNKNOWN = 0;
STREAM_PAUSED = 1; // Stream Paused by Host
STREAM_UNPAUSED = 2;
STREAM_ENDED = 3; // Stream Ended by Host
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
import io.github.jwdeveloper.tiktok.data.events.TikTokReconnectingEvent;
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomInfoEvent;
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveOfflineHostException;
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftManager;
Expand Down Expand Up @@ -138,14 +139,24 @@ public void tryConnect() {
}


var roomData = apiService.fetchRoomInfo();
if (roomData.getStatus() != LiveRoomMeta.LiveRoomStatus.HostOnline) {
throw new TikTokLiveOfflineHostException("LiveStream for Host name could not be found. Is the Host online?");
var liveRoomMeta = apiService.fetchRoomInfo();
if (liveRoomMeta.getStatus() == LiveRoomMeta.LiveRoomStatus.HostNotFound) {
throw new TikTokLiveOfflineHostException("LiveStream for Host name could not be found.");
}
if (liveRoomMeta.getStatus() == LiveRoomMeta.LiveRoomStatus.HostOffline) {
throw new TikTokLiveOfflineHostException("LiveStream for not be found, is the Host offline?");
}

liveRoomInfo.setTitle(liveRoomMeta.getTitie());
liveRoomInfo.setViewersCount(liveRoomMeta.getViewers());
liveRoomInfo.setTotalViewersCount(liveRoomMeta.getTotalViewers());
liveRoomInfo.setAgeRestricted(liveRoomMeta.isAgeRestricted());
liveRoomInfo.setHost(liveRoomMeta.getHost());

var clientData = apiService.fetchClientData();
webSocketClient.start(clientData, this);
setState(ConnectionState.CONNECTED);
tikTokEventHandler.publish(this,new TikTokRoomInfoEvent(liveRoomInfo));
}


Expand Down
Loading

0 comments on commit ea8c740

Please sign in to comment.