- add comments next to magic numbers

This commit is contained in:
jacek.wolniewicz
2024-07-04 11:51:45 +02:00
parent 36475c2cf6
commit 3e555a502a
8 changed files with 118 additions and 13 deletions

View File

@@ -99,7 +99,7 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
//TODO 250 Magic number
if (clientSettings.getPingInterval() < 250)
throw new TikTokLiveException("Minimum allowed ping interval is 250 millseconds");
throw new TikTokLiveException("Minimum allowed ping interval is 250 milliseconds");
var httpSettings = clientSettings.getHttpSettings();
httpSettings.getParams().put("app_language", clientSettings.getClientLanguage());
@@ -176,12 +176,10 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
dependance.registerSingleton(LiveClient.class, TikTokLiveClient.class);
onCustomDependencies.forEach(action -> action.accept(dependance));
var container = dependance.build();
var listenerManager = container.find(ListenersManager.class);
listeners.forEach(listenerManager::addListener);
return container.find(LiveClient.class);
}

View File

@@ -136,7 +136,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
var url = TIKTOK_URL_WEB + "api-live/user/room";
var result = httpFactory.client(url)
.withParam("uniqueId", request.getUserName())
.withParam("sourceType", "54")
.withParam("sourceType", "54") //MAGIC NUMBER, WHAT 54 means?
.build()
.toJsonResponse();
@@ -218,7 +218,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
private ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
.withParam("client", "ttlive-java")
.withParam("uuc", "1")
.withParam("uuc", "1") //MAGIC NUMBER!
.withParam("room_id", room_id);
if (clientSettings.getApiKey() != null)

View File

@@ -129,7 +129,7 @@ public class TikTokListenersManager implements ListenersManager {
var methodContainer = dependanceContainer.createChildContainer()
.configure(configuration ->
{
//Modfying container, so it returns TikTokEvent object instance,
//Modifying container, so it returns TikTokEvent object instance,
//when TikTokEvent type is encountered in the methods parameters
configuration.onInjection(injectionEvent ->
{

View File

@@ -53,7 +53,7 @@ public class TikTokGenericEventMapper {
private final Map<Class<?>, Method> methodCache;
private final Map<TypePair, Constructor<?>> constructorCache;
private static final String PARSE_FIELD = "parseFrom";
public TikTokGenericEventMapper() {
this.methodCache = new HashMap<>();
this.constructorCache = new HashMap<>();
@@ -75,7 +75,7 @@ public class TikTokGenericEventMapper {
public Method getParsingMethod(Class<?> input) throws RuntimeException {
return methodCache.computeIfAbsent(input, aClass -> {
try {
return aClass.getDeclaredMethod("parseFrom", byte[].class);
return aClass.getDeclaredMethod(PARSE_FIELD, byte[].class);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}

View File

@@ -34,11 +34,12 @@ public class TikTokLiveMapper implements LiveMapper {
private final Map<String, TikTokLiveMapperModel> mappers;
private final LiveMapperHelper mapperUtils;
private final TikTokLiveMapperModel globalMapperModel;
private static final String GLOBAL_MESSAGE = "GLOBAL MESSAGE";
public TikTokLiveMapper(LiveMapperHelper mapperUtils) {
this.mappers = new HashMap<>();
this.mapperUtils = mapperUtils;
this.globalMapperModel = new TikTokLiveMapperModel("any message");
this.globalMapperModel = new TikTokLiveMapperModel(GLOBAL_MESSAGE);
}
@Override

View File

@@ -38,7 +38,6 @@ import java.util.*;
public class TikTokGiftEventHandler {
private final Map<Long, WebcastGiftMessage> giftsMessages;
private final TikTokRoomInfo tikTokRoomInfo;
private final GiftsManager giftsManager;
public TikTokGiftEventHandler(GiftsManager giftsManager, TikTokRoomInfo tikTokRoomInfo) {