Improvement of Listener

This commit is contained in:
jacek.wolniewicz
2024-07-03 22:27:15 +02:00
parent 7005f58edd
commit 660cb287e9
16 changed files with 121 additions and 83 deletions

View File

@@ -0,0 +1,18 @@
package io.github.jwdeveloper.tiktok.annotations;
/**
* HIGHEST 1
* HIGH 2
* NORMAL 3
* LOW 4
* LOWEST 5
*/
public enum Priority {
LOWEST(2), LOW(1), NORMAL(0), HIGH(-1), HIGHEST(-2);
public int priorityValue;
Priority(int value) {
this.priorityValue = value;
}
}

View File

@@ -26,7 +26,13 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface TikTokEventObserver
{
public @interface TikTokEventObserver {
Priority priority() default Priority.NORMAL;
/**
* when true, action is invoked on the another thread
* @return
*/
boolean async();
}

View File

@@ -27,14 +27,13 @@ import java.util.List;
/**
* You can dynamically add or removing TikTokEventListener
*
* @see TikTokEventListener
*
*/
public interface ListenersManager
{
List<TikTokEventListener> getListeners();
List<Object> getListeners();
void addListener(TikTokEventListener listener);
void addListener(Object listener);
void removeListener(TikTokEventListener listener);
void removeListener(Object listener);
}

View File

@@ -40,7 +40,7 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
* {@code
* public static class CustomListener implements TikTokEventListener
* {
* @TikTokEventObserver
* @TikTokEventObserver
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
* {
* System.out.println(event.getException().getMessage());
@@ -67,7 +67,9 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
* }
* </pre>
*/
public interface TikTokEventListener
{
//TODO I think this interface can be removed, since we are using,
//annotation @TikTokEventHandler to check methods that are events
@Deprecated(forRemoval = true, since = "This interface is not longer needed, please remove it from your class")
public interface TikTokEventListener {
}

View File

@@ -54,12 +54,11 @@ public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
LiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure);
/**
* @see TikTokEventListener
* Adding events listener class, its fancy way to register events without using lamda method
* but actual method in class that implements TikTokEventListener
* @return
*/
LiveClientBuilder addListener(TikTokEventListener listener);
LiveClientBuilder addListener(Object listener);
/**

View File

@@ -24,9 +24,8 @@ package io.github.jwdeveloper.tiktok.websocket;
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
import io.github.jwdeveloper.tiktok.live.LiveClient;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
public interface SocketClient {
public interface LiveSocketClient {
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
void stop();
}