moons-ta-client 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  export declare const masterAddress = "server.tournamentassistant.net";
2
2
  export declare const masterPort = "8676";
3
3
  export declare const masterApiPort = "8678";
4
- export declare const version = "1.2.2";
5
- export declare const versionCode = 1220;
4
+ export declare const version = "1.2.4";
5
+ export declare const versionCode = 1240;
package/dist/constants.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export const masterAddress = "server.tournamentassistant.net";
2
2
  export const masterPort = "8676";
3
3
  export const masterApiPort = "8678";
4
- export const version = "1.2.2";
5
- export const versionCode = 1220;
4
+ export const version = "1.2.4";
5
+ export const versionCode = 1240;
package/dist/index.d.ts CHANGED
@@ -5021,6 +5021,11 @@ type ResponseFromUser = {
5021
5021
  userId: string;
5022
5022
  response: Response;
5023
5023
  };
5024
+ declare enum LogLevel {
5025
+ Quiet = 0,
5026
+ Debug = 1,
5027
+ Info = 2
5028
+ }
5024
5029
  type TAClientEvents = {
5025
5030
  connectedToServer: Response_Connect;
5026
5031
  connectingToServer: {};
@@ -5057,11 +5062,14 @@ declare class TAClient extends CustomEventEmitter<TAClientEvents> {
5057
5062
  private _imageServer;
5058
5063
  stateManager: StateManager;
5059
5064
  private uiVersion;
5065
+ private logLevel;
5060
5066
  private client?;
5061
5067
  private token;
5062
5068
  private shouldHeartbeat;
5063
5069
  private heartbeatInterval;
5064
- constructor(uiVersion?: number | undefined);
5070
+ constructor(uiVersion?: number | undefined, logLevel?: LogLevel);
5071
+ private logInfo;
5072
+ private logError;
5065
5073
  get isConnected(): boolean;
5066
5074
  get isConnecting(): boolean;
5067
5075
  connect(serverAddress: string, port: string): Promise<Response>;
@@ -5143,7 +5151,7 @@ declare class TAClient extends CustomEventEmitter<TAClientEvents> {
5143
5151
  declare const masterAddress = "server.tournamentassistant.net";
5144
5152
  declare const masterPort = "8676";
5145
5153
  declare const masterApiPort = "8678";
5146
- declare const version = "1.2.2";
5147
- declare const versionCode = 1220;
5154
+ declare const version = "1.2.4";
5155
+ declare const versionCode = 1240;
5148
5156
 
5149
- export { Acknowledgement, Acknowledgement_AcknowledgementType, Beatmap, Channel, Characteristic, Command, Command_ModifyGameplay, Command_ModifyGameplay_Modifier, Command_PlaySong, Command_ShowColorForStreamSync, CoreServer, CustomEventEmitter, DiscordUser, Event, Event_MatchCreated, Event_MatchDeleted, Event_MatchUpdated, Event_QualifierCreated, Event_QualifierDeleted, Event_QualifierUpdated, Event_ServerAdded, Event_ServerDeleted, Event_TournamentCreated, Event_TournamentDeleted, Event_TournamentUpdated, Event_UserAdded, Event_UserLeft, Event_UserUpdated, ForwardingPacket, GameplayModifiers, GameplayModifiers_GameOptions, GameplayParameters, Guild, LeaderboardEntry, Map, Match, Packet, PlayerSpecificSettings, PlayerSpecificSettings_ArcVisibilityType, PlayerSpecificSettings_NoteJumpDurationTypeSettings, PlayerSpecificSettings_PlayerOptions, Push, Push_QualifierScoreSubmitted, Push_SongFinished, Push_SongFinished_CompletionType, QualifierEvent, QualifierEvent_EventSettings, QualifierEvent_LeaderboardSort, RealtimeScore, Request, Request_AddAuthorizedUser, Request_AddQualifierMaps, Request_AddServer, Request_AddTournamentPool, Request_AddTournamentPoolMaps, Request_AddTournamentRole, Request_AddTournamentTeam, Request_AddUserToMatch, Request_Connect, Request_CreateMatch, Request_CreateQualifierEvent, Request_CreateTournament, Request_DeleteMatch, Request_DeleteQualifierEvent, Request_DeleteTournament, Request_GenerateBotToken, Request_GetAuthorizedUsers, Request_GetBotTokensForUser, Request_GetDiscordInfo, Request_Join, Request_LoadSong, Request_PreloadImageForStreamSync, Request_QualifierScores, Request_RefundAttempts, Request_RemainingAttempts, Request_RemoveAuthorizedUser, Request_RemoveQualifierMap, Request_RemoveTournamentPool, Request_RemoveTournamentPoolMap, Request_RemoveTournamentRole, Request_RemoveTournamentTeam, Request_RemoveUserFromMatch, Request_RevokeBotToken, Request_SetMatchLeader, Request_SetMatchMap, Request_SetQualifierFlags, Request_SetQualifierImage, Request_SetQualifierInfoChannel, Request_SetQualifierLeaderboardSort, Request_SetQualifierName, Request_SetTournamentAllowUnauthorizedView, Request_SetTournamentBannedMods, Request_SetTournamentEnablePools, Request_SetTournamentEnableTeams, Request_SetTournamentImage, Request_SetTournamentName, Request_SetTournamentPoolImage, Request_SetTournamentPoolName, Request_SetTournamentRoleName, Request_SetTournamentRolePermissions, Request_SetTournamentScoreUpdateFrequency, Request_SetTournamentShowQualifierButton, Request_SetTournamentShowTournamentButton, Request_SetTournamentTeamImage, Request_SetTournamentTeamName, Request_ShowPrompt, Request_ShowPrompt_PromptOption, Request_SubmitQualifierScore, Request_UpdateAuthorizedUserRoles, Request_UpdateQualifierMap, Request_UpdateTournamentPoolMap, Request_UpdateUser, Response, type ResponseFromUser, Response_AddAuthorizedUser, Response_AddServer, Response_Connect, Response_Connect_ConnectFailReason, Response_CreateMatch, Response_CreateQualifierEvent, Response_CreateTournament, Response_DeleteMatch, Response_DeleteQualifierEvent, Response_DeleteTournament, Response_GenerateBotToken, Response_GetAuthorizedUsers, Response_GetAuthorizedUsers_AuthroizedUser, Response_GetBotTokensForUser, Response_GetBotTokensForUser_BotUser, Response_GetDiscordInfo, Response_Join, Response_Join_JoinFailReason, Response_LeaderboardEntries, Response_LoadSong, Response_PreloadImageForStreamSync, Response_RefundAttempts, Response_RemainingAttempts, Response_RemoveAuthorizedUser, Response_ResponseType, Response_RevokeBotToken, Response_ShowPrompt, Response_UpdateAuthorizedUser, Response_UpdateMatch, Response_UpdateQualifierEvent, Response_UpdateTournament, Response_UpdateUser, Role, ScoreTrackerHand, State, TAClient, Tournament, Tournament_TournamentSettings, Tournament_TournamentSettings_Pool, Tournament_TournamentSettings_Team, User, User_ClientTypes, User_DiscordInfo, User_DownloadStates, User_PlayStates, User_Point, getTournaments, masterAddress, masterApiPort, masterPort, version, versionCode };
5157
+ export { Acknowledgement, Acknowledgement_AcknowledgementType, Beatmap, Channel, Characteristic, Command, Command_ModifyGameplay, Command_ModifyGameplay_Modifier, Command_PlaySong, Command_ShowColorForStreamSync, CoreServer, CustomEventEmitter, DiscordUser, Event, Event_MatchCreated, Event_MatchDeleted, Event_MatchUpdated, Event_QualifierCreated, Event_QualifierDeleted, Event_QualifierUpdated, Event_ServerAdded, Event_ServerDeleted, Event_TournamentCreated, Event_TournamentDeleted, Event_TournamentUpdated, Event_UserAdded, Event_UserLeft, Event_UserUpdated, ForwardingPacket, GameplayModifiers, GameplayModifiers_GameOptions, GameplayParameters, Guild, LeaderboardEntry, LogLevel, Map, Match, Packet, PlayerSpecificSettings, PlayerSpecificSettings_ArcVisibilityType, PlayerSpecificSettings_NoteJumpDurationTypeSettings, PlayerSpecificSettings_PlayerOptions, Push, Push_QualifierScoreSubmitted, Push_SongFinished, Push_SongFinished_CompletionType, QualifierEvent, QualifierEvent_EventSettings, QualifierEvent_LeaderboardSort, RealtimeScore, Request, Request_AddAuthorizedUser, Request_AddQualifierMaps, Request_AddServer, Request_AddTournamentPool, Request_AddTournamentPoolMaps, Request_AddTournamentRole, Request_AddTournamentTeam, Request_AddUserToMatch, Request_Connect, Request_CreateMatch, Request_CreateQualifierEvent, Request_CreateTournament, Request_DeleteMatch, Request_DeleteQualifierEvent, Request_DeleteTournament, Request_GenerateBotToken, Request_GetAuthorizedUsers, Request_GetBotTokensForUser, Request_GetDiscordInfo, Request_Join, Request_LoadSong, Request_PreloadImageForStreamSync, Request_QualifierScores, Request_RefundAttempts, Request_RemainingAttempts, Request_RemoveAuthorizedUser, Request_RemoveQualifierMap, Request_RemoveTournamentPool, Request_RemoveTournamentPoolMap, Request_RemoveTournamentRole, Request_RemoveTournamentTeam, Request_RemoveUserFromMatch, Request_RevokeBotToken, Request_SetMatchLeader, Request_SetMatchMap, Request_SetQualifierFlags, Request_SetQualifierImage, Request_SetQualifierInfoChannel, Request_SetQualifierLeaderboardSort, Request_SetQualifierName, Request_SetTournamentAllowUnauthorizedView, Request_SetTournamentBannedMods, Request_SetTournamentEnablePools, Request_SetTournamentEnableTeams, Request_SetTournamentImage, Request_SetTournamentName, Request_SetTournamentPoolImage, Request_SetTournamentPoolName, Request_SetTournamentRoleName, Request_SetTournamentRolePermissions, Request_SetTournamentScoreUpdateFrequency, Request_SetTournamentShowQualifierButton, Request_SetTournamentShowTournamentButton, Request_SetTournamentTeamImage, Request_SetTournamentTeamName, Request_ShowPrompt, Request_ShowPrompt_PromptOption, Request_SubmitQualifierScore, Request_UpdateAuthorizedUserRoles, Request_UpdateQualifierMap, Request_UpdateTournamentPoolMap, Request_UpdateUser, Response, type ResponseFromUser, Response_AddAuthorizedUser, Response_AddServer, Response_Connect, Response_Connect_ConnectFailReason, Response_CreateMatch, Response_CreateQualifierEvent, Response_CreateTournament, Response_DeleteMatch, Response_DeleteQualifierEvent, Response_DeleteTournament, Response_GenerateBotToken, Response_GetAuthorizedUsers, Response_GetAuthorizedUsers_AuthroizedUser, Response_GetBotTokensForUser, Response_GetBotTokensForUser_BotUser, Response_GetDiscordInfo, Response_Join, Response_Join_JoinFailReason, Response_LeaderboardEntries, Response_LoadSong, Response_PreloadImageForStreamSync, Response_RefundAttempts, Response_RemainingAttempts, Response_RemoveAuthorizedUser, Response_ResponseType, Response_RevokeBotToken, Response_ShowPrompt, Response_UpdateAuthorizedUser, Response_UpdateMatch, Response_UpdateQualifierEvent, Response_UpdateTournament, Response_UpdateUser, Role, ScoreTrackerHand, State, TAClient, Tournament, Tournament_TournamentSettings, Tournament_TournamentSettings_Pool, Tournament_TournamentSettings_Team, User, User_ClientTypes, User_DiscordInfo, User_DownloadStates, User_PlayStates, User_Point, getTournaments, masterAddress, masterApiPort, masterPort, version, versionCode };
package/dist/index.esm.js CHANGED
@@ -16480,8 +16480,8 @@ init_process2();
16480
16480
  var masterAddress = "server.tournamentassistant.net";
16481
16481
  var masterPort = "8676";
16482
16482
  var masterApiPort = "8678";
16483
- var version = "1.2.2";
16484
- var versionCode = 1220;
16483
+ var version = "1.2.4";
16484
+ var versionCode = 1240;
16485
16485
 
16486
16486
  // src/tournament-assistant-client.ts
16487
16487
  var import_ws2 = __toESM(require_ws(), 1);
@@ -16575,18 +16575,37 @@ var Scraper = class extends CustomEventEmitter {
16575
16575
  };
16576
16576
 
16577
16577
  // src/tournament-assistant-client.ts
16578
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
16579
+ LogLevel2[LogLevel2["Quiet"] = 0] = "Quiet";
16580
+ LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
16581
+ LogLevel2[LogLevel2["Info"] = 2] = "Info";
16582
+ return LogLevel2;
16583
+ })(LogLevel || {});
16578
16584
  var TAClient = class extends CustomEventEmitter {
16579
16585
  _imageServer = `https://${masterAddress}:${masterApiPort}`;
16580
16586
  stateManager;
16581
16587
  uiVersion;
16588
+ logLevel;
16582
16589
  client;
16583
16590
  token = "";
16584
16591
  shouldHeartbeat = false;
16585
16592
  heartbeatInterval;
16586
- constructor(uiVersion = void 0) {
16593
+ constructor(uiVersion = void 0, logLevel = 0 /* Quiet */) {
16587
16594
  super();
16588
16595
  this.stateManager = new StateManager();
16589
16596
  this.uiVersion = uiVersion;
16597
+ this.logLevel = logLevel;
16598
+ }
16599
+ // --- Logging --- //
16600
+ logInfo(object) {
16601
+ if (this.logLevel >= 2 /* Info */) {
16602
+ console.log(object);
16603
+ }
16604
+ }
16605
+ logError(object) {
16606
+ if (this.logLevel >= 1 /* Debug */) {
16607
+ console.error(object);
16608
+ }
16590
16609
  }
16591
16610
  // --- State helpers --- //
16592
16611
  get isConnected() {
@@ -16604,11 +16623,11 @@ var TAClient = class extends CustomEventEmitter {
16604
16623
  this.client.on("packetReceived", this.handlePacket);
16605
16624
  this.client.on("disconnectedFromServer", () => {
16606
16625
  clearInterval(this.heartbeatInterval);
16607
- console.info("Disconnected from server!");
16626
+ this.logInfo("Disconnected from server!");
16608
16627
  this.emit("disconnectedFromServer", {});
16609
16628
  });
16610
16629
  this.client.on("failedToConnectToServer", () => {
16611
- console.error("Failed to connect to server!");
16630
+ this.logError("Failed to connect to server!");
16612
16631
  this.emit("failedToConnectToServer", {});
16613
16632
  });
16614
16633
  this.emit("connectingToServer", {});
@@ -16663,7 +16682,7 @@ var TAClient = class extends CustomEventEmitter {
16663
16682
  disconnect() {
16664
16683
  var _a;
16665
16684
  this.shouldHeartbeat = false;
16666
- console.info(`Disconnecting from server!`);
16685
+ this.logInfo(`Disconnecting from server!`);
16667
16686
  (_a = this.client) == null ? void 0 : _a.disconnect();
16668
16687
  }
16669
16688
  setAuthToken(token) {
@@ -16675,7 +16694,7 @@ var TAClient = class extends CustomEventEmitter {
16675
16694
  if (bytes.length < 3) {
16676
16695
  return "";
16677
16696
  }
16678
- const blob = new Blob([bytes], { type: "image/png" });
16697
+ const blob = new Blob([new Uint8Array(bytes)], { type: "image/png" });
16679
16698
  const file = new File([blob], "dummy.png", {
16680
16699
  type: "image/png"
16681
16700
  });
@@ -16720,76 +16739,71 @@ var TAClient = class extends CustomEventEmitter {
16720
16739
  }
16721
16740
  };
16722
16741
  const responseDictionary = [];
16723
- const responsesPromise = new Promise(
16724
- (resolve, reject) => {
16725
- const addListeners = () => {
16726
- this.on("responseReceived", onResponseReceived);
16727
- this.on("authorizationRequestedFromServer", onAuthorizationRequested);
16728
- };
16729
- const removeListeners = () => {
16730
- this.removeListener("responseReceived", onResponseReceived);
16731
- this.removeListener(
16732
- "authorizationRequestedFromServer",
16733
- onAuthorizationRequested
16734
- );
16735
- };
16736
- const getUnrespondedUsers = () => {
16737
- const responseUsers = responseDictionary.map((x) => x.userId);
16738
- const expectedUsers = to ?? ["00000000-0000-0000-0000-000000000000"];
16739
- if (responseUsers.length === expectedUsers.length) {
16740
- return [];
16742
+ const responsesPromise = new Promise((resolve, reject) => {
16743
+ const addListeners = () => {
16744
+ this.on("responseReceived", onResponseReceived);
16745
+ this.on("authorizationRequestedFromServer", onAuthorizationRequested);
16746
+ };
16747
+ const removeListeners = () => {
16748
+ this.removeListener("responseReceived", onResponseReceived);
16749
+ this.removeListener("authorizationRequestedFromServer", onAuthorizationRequested);
16750
+ };
16751
+ const getUnrespondedUsers = () => {
16752
+ const responseUsers = responseDictionary.map((x) => x.userId);
16753
+ const expectedUsers = to ?? ["00000000-0000-0000-0000-000000000000"];
16754
+ if (responseUsers.length === expectedUsers.length) {
16755
+ return [];
16756
+ }
16757
+ const sortedArr1 = responseUsers.slice().sort();
16758
+ const sortedArr2 = expectedUsers.slice().sort();
16759
+ let waitingForUsers = [];
16760
+ for (let i2 = 0; i2 < sortedArr2.length; i2++) {
16761
+ if (i2 > sortedArr1.length || sortedArr2[i2] !== sortedArr1[i2]) {
16762
+ waitingForUsers.push(sortedArr2[i2]);
16741
16763
  }
16742
- const sortedArr1 = responseUsers.slice().sort();
16743
- const sortedArr2 = expectedUsers.slice().sort();
16744
- let waitingForUsers = [];
16745
- for (let i2 = 0; i2 < sortedArr2.length; i2++) {
16746
- if (i2 > sortedArr1.length || sortedArr2[i2] !== sortedArr1[i2]) {
16747
- waitingForUsers.push(sortedArr2[i2]);
16748
- }
16764
+ }
16765
+ return waitingForUsers;
16766
+ };
16767
+ const onResponseReceived = (response) => {
16768
+ const expectedUsers = to ?? ["00000000-0000-0000-0000-000000000000"];
16769
+ if (response.response.respondingToPacketId === packet.id && expectedUsers.includes(response.userId)) {
16770
+ responseDictionary.push({
16771
+ userId: response.userId,
16772
+ response: response.response
16773
+ });
16774
+ if (getUnrespondedUsers().length === 0) {
16775
+ removeListeners();
16776
+ clearTimeout(timeoutTimer);
16777
+ resolve(responseDictionary);
16749
16778
  }
16750
- return waitingForUsers;
16751
- };
16752
- const onResponseReceived = (response) => {
16753
- const expectedUsers = to ?? ["00000000-0000-0000-0000-000000000000"];
16754
- if (response.response.respondingToPacketId === packet.id && expectedUsers.includes(response.userId)) {
16779
+ }
16780
+ };
16781
+ const createTimeout = (time) => {
16782
+ return setTimeout(() => {
16783
+ const unrespondedUsers = getUnrespondedUsers();
16784
+ for (let user of unrespondedUsers) {
16755
16785
  responseDictionary.push({
16756
- userId: response.userId,
16757
- response: response.response
16786
+ userId: user,
16787
+ response: {
16788
+ type: 0 /* Fail */,
16789
+ respondingToPacketId: packet.id,
16790
+ details: {
16791
+ oneofKind: void 0
16792
+ }
16793
+ }
16758
16794
  });
16759
- if (getUnrespondedUsers().length === 0) {
16760
- removeListeners();
16761
- clearTimeout(timeoutTimer);
16762
- resolve(responseDictionary);
16763
- }
16764
16795
  }
16765
- };
16766
- const createTimeout = (time) => {
16767
- return setTimeout(() => {
16768
- const unrespondedUsers = getUnrespondedUsers();
16769
- for (let user of unrespondedUsers) {
16770
- responseDictionary.push({
16771
- userId: user,
16772
- response: {
16773
- type: 0 /* Fail */,
16774
- respondingToPacketId: packet.id,
16775
- details: {
16776
- oneofKind: void 0
16777
- }
16778
- }
16779
- });
16780
- }
16781
- removeListeners();
16782
- resolve(responseDictionary);
16783
- }, time);
16784
- };
16785
- const timeoutTimer = createTimeout(timeout);
16786
- const onAuthorizationRequested = () => {
16787
- clearTimeout(timeoutTimer);
16788
- reject("Authorization token invalid or not provided");
16789
- };
16790
- addListeners();
16791
- }
16792
- );
16796
+ removeListeners();
16797
+ resolve(responseDictionary);
16798
+ }, time);
16799
+ };
16800
+ const timeoutTimer = createTimeout(timeout);
16801
+ const onAuthorizationRequested = () => {
16802
+ clearTimeout(timeoutTimer);
16803
+ reject("Authorization token invalid or not provided");
16804
+ };
16805
+ addListeners();
16806
+ });
16793
16807
  (_a = this.client) == null ? void 0 : _a.send(packet);
16794
16808
  return responsesPromise;
16795
16809
  }
@@ -17034,19 +17048,12 @@ var TAClient = class extends CustomEventEmitter {
17034
17048
  if (packet.packet.oneofKind === "command") {
17035
17049
  const command = packet.packet.command;
17036
17050
  if (command.type.oneofKind === "discordAuthorize") {
17037
- this.emit(
17038
- "authorizationRequestedFromServer",
17039
- command.type.discordAuthorize
17040
- );
17051
+ this.emit("authorizationRequestedFromServer", command.type.discordAuthorize);
17041
17052
  }
17042
17053
  } else if (packet.packet.oneofKind === "request") {
17043
17054
  const request = packet.packet.request;
17044
17055
  if (request.type.oneofKind === "loadSong") {
17045
- this.emit("loadSongRequested", [
17046
- packet.id,
17047
- packet.from,
17048
- request.type.loadSong
17049
- ]);
17056
+ this.emit("loadSongRequested", [packet.id, packet.from, request.type.loadSong]);
17050
17057
  }
17051
17058
  } else if (packet.packet.oneofKind === "response") {
17052
17059
  const response = packet.packet.response;
@@ -17057,118 +17064,100 @@ var TAClient = class extends CustomEventEmitter {
17057
17064
  if (response.details.oneofKind === "connect") {
17058
17065
  const connect = response.details.connect;
17059
17066
  if (response.type === 1 /* Success */) {
17060
- console.info(`Successfully connected to server!`);
17067
+ this.logInfo(`Successfully connected to server!`);
17061
17068
  this.emit("connectedToServer", connect);
17062
17069
  } else {
17063
- console.error(
17064
- `Failed to connect to server. Message: ${connect.message}`
17065
- );
17070
+ this.logError(`Failed to connect to server. Message: ${connect.message}`);
17066
17071
  this.emit("failedToConnectToServer", {});
17067
17072
  }
17068
17073
  } else if (response.details.oneofKind === "join") {
17069
17074
  const join = response.details.join;
17070
17075
  if (response.type === 1 /* Success */) {
17071
- console.info(`Successfully joined tournament!`);
17076
+ this.logInfo(`Successfully joined tournament!`);
17072
17077
  this.emit("joinedTournament", {});
17073
17078
  } else {
17074
- console.error(`Failed to join server. Message: ${join.message}`);
17079
+ this.logError(`Failed to join server. Message: ${join.message}`);
17075
17080
  this.emit("failedToJoinTournament", {});
17076
17081
  }
17077
17082
  } else if (response.details.oneofKind === "createTournament") {
17078
17083
  const createTournament = response.details.createTournament;
17079
17084
  if (response.type === 1 /* Success */) {
17080
- console.info(`Successfully created tournament!`);
17085
+ this.logInfo(`Successfully created tournament!`);
17081
17086
  this.emit("createdTournament", {});
17082
17087
  } else {
17083
- console.error(
17084
- `Failed to create tournament. Message: ${createTournament.message}`
17085
- );
17088
+ this.logError(`Failed to create tournament. Message: ${createTournament.message}`);
17086
17089
  this.emit("failedToCreateTournament", {});
17087
17090
  }
17088
17091
  } else if (response.details.oneofKind === "updateTournament") {
17089
17092
  const updateTournament = response.details.updateTournament;
17090
17093
  if (response.type === 1 /* Success */) {
17091
- console.info(`Successfully modified tournament!`);
17094
+ this.logInfo(`Successfully modified tournament!`);
17092
17095
  this.emit("updatedTournament", {});
17093
17096
  } else {
17094
- console.error(
17095
- `Failed update tournament. Message: ${updateTournament.message}`
17096
- );
17097
+ this.logError(`Failed update tournament. Message: ${updateTournament.message}`);
17097
17098
  this.emit("failedToUpdateTournament", {});
17098
17099
  }
17099
17100
  } else if (response.details.oneofKind === "deleteTournament") {
17100
17101
  const deleteTournament = response.details.deleteTournament;
17101
17102
  if (response.type === 1 /* Success */) {
17102
- console.info(`Successfully deleted tournament!`);
17103
+ this.logInfo(`Successfully deleted tournament!`);
17103
17104
  this.emit("deletedTournament", {});
17104
17105
  } else {
17105
- console.error(
17106
- `Failed to delete tournament. Message: ${deleteTournament.message}`
17107
- );
17106
+ this.logError(`Failed to delete tournament. Message: ${deleteTournament.message}`);
17108
17107
  this.emit("failedToDeleteTournament", {});
17109
17108
  }
17110
17109
  } else if (response.details.oneofKind === "createMatch") {
17111
17110
  const createMatch = response.details.createMatch;
17112
17111
  if (response.type === 1 /* Success */) {
17113
- console.info(`Successfully created match!`);
17112
+ this.logInfo(`Successfully created match!`);
17114
17113
  this.emit("createdMatch", {});
17115
17114
  } else {
17116
- console.error(
17117
- `Failed to create Match. Message: ${createMatch.message}`
17118
- );
17115
+ this.logError(`Failed to create Match. Message: ${createMatch.message}`);
17119
17116
  this.emit("failedToCreateMatch", {});
17120
17117
  }
17121
17118
  } else if (response.details.oneofKind === "updateMatch") {
17122
17119
  const updateMatch = response.details.updateMatch;
17123
17120
  if (response.type === 1 /* Success */) {
17124
- console.info(`Successfully modified match!`);
17121
+ this.logInfo(`Successfully modified match!`);
17125
17122
  this.emit("updatedMatch", {});
17126
17123
  } else {
17127
- console.error(`Failed update Match. Message: ${updateMatch.message}`);
17124
+ this.logError(`Failed update Match. Message: ${updateMatch.message}`);
17128
17125
  this.emit("failedToUpdateMatch", {});
17129
17126
  }
17130
17127
  } else if (response.details.oneofKind === "deleteMatch") {
17131
17128
  const deleteMatch = response.details.deleteMatch;
17132
17129
  if (response.type === 1 /* Success */) {
17133
- console.info(`Successfully deleted match!`);
17130
+ this.logInfo(`Successfully deleted match!`);
17134
17131
  this.emit("deletedMatch", {});
17135
17132
  } else {
17136
- console.error(
17137
- `Failed to delete Match. Message: ${deleteMatch.message}`
17138
- );
17133
+ this.logError(`Failed to delete Match. Message: ${deleteMatch.message}`);
17139
17134
  this.emit("failedToDeleteMatch", {});
17140
17135
  }
17141
17136
  } else if (response.details.oneofKind === "createQualifierEvent") {
17142
17137
  const createQualifierEvent = response.details.createQualifierEvent;
17143
17138
  if (response.type === 1 /* Success */) {
17144
- console.info(`Successfully created qualifier!`);
17139
+ this.logInfo(`Successfully created qualifier!`);
17145
17140
  this.emit("createdQualifier", {});
17146
17141
  } else {
17147
- console.error(
17148
- `Failed to create qualifier. Message: ${createQualifierEvent.message}`
17149
- );
17142
+ this.logError(`Failed to create qualifier. Message: ${createQualifierEvent.message}`);
17150
17143
  this.emit("failedToCreateQualifier", {});
17151
17144
  }
17152
17145
  } else if (response.details.oneofKind === "updateQualifierEvent") {
17153
17146
  const modifyQualifier = response.details.updateQualifierEvent;
17154
17147
  if (response.type === 1 /* Success */) {
17155
- console.info(`Successfully modified qualifier!`);
17148
+ this.logInfo(`Successfully modified qualifier!`);
17156
17149
  this.emit("updatedQualifier", {});
17157
17150
  } else {
17158
- console.error(
17159
- `Failed to update qualifier. Message: ${modifyQualifier.message}`
17160
- );
17151
+ this.logError(`Failed to update qualifier. Message: ${modifyQualifier.message}`);
17161
17152
  this.emit("failedToUpdateQualifier", {});
17162
17153
  }
17163
17154
  } else if (response.details.oneofKind === "deleteQualifierEvent") {
17164
17155
  const deleteQualifierEvent = response.details.deleteQualifierEvent;
17165
17156
  if (response.type === 1 /* Success */) {
17166
- console.info(`Successfully deleted qualifier!`);
17157
+ this.logInfo(`Successfully deleted qualifier!`);
17167
17158
  this.emit("deletedQualifier", {});
17168
17159
  } else {
17169
- console.error(
17170
- `Failed to delete qualifier. Message: ${deleteQualifierEvent.message}`
17171
- );
17160
+ this.logError(`Failed to delete qualifier. Message: ${deleteQualifierEvent.message}`);
17172
17161
  this.emit("failedToDeleteQualifier", {});
17173
17162
  }
17174
17163
  }
@@ -18055,6 +18044,7 @@ export {
18055
18044
  GameplayParameters,
18056
18045
  Guild,
18057
18046
  LeaderboardEntry,
18047
+ LogLevel,
18058
18048
  Map2 as Map,
18059
18049
  Match,
18060
18050
  Packet,
@@ -10,6 +10,11 @@ export type ResponseFromUser = {
10
10
  userId: string;
11
11
  response: Response;
12
12
  };
13
+ export declare enum LogLevel {
14
+ Quiet = 0,
15
+ Debug = 1,
16
+ Info = 2
17
+ }
13
18
  type TAClientEvents = {
14
19
  connectedToServer: Response_Connect;
15
20
  connectingToServer: {};
@@ -46,11 +51,14 @@ export declare class TAClient extends CustomEventEmitter<TAClientEvents> {
46
51
  private _imageServer;
47
52
  stateManager: StateManager;
48
53
  private uiVersion;
54
+ private logLevel;
49
55
  private client?;
50
56
  private token;
51
57
  private shouldHeartbeat;
52
58
  private heartbeatInterval;
53
- constructor(uiVersion?: number | undefined);
59
+ constructor(uiVersion?: number | undefined, logLevel?: LogLevel);
60
+ private logInfo;
61
+ private logError;
54
62
  get isConnected(): boolean;
55
63
  get isConnecting(): boolean;
56
64
  connect(serverAddress: string, port: string): Promise<Response>;
@@ -2,25 +2,44 @@ import { Client } from "./client.js";
2
2
  import { CustomEventEmitter } from "./custom-event-emitter.js";
3
3
  import { v4 as uuidv4 } from "uuid";
4
4
  import { StateManager } from "./state-manager.js";
5
- import { Response_ResponseType, } from "./models/responses.js";
5
+ import { Response_ResponseType } from "./models/responses.js";
6
6
  import { Command_ModifyGameplay_Modifier } from "./models/commands.js";
7
7
  import { masterAddress, masterApiPort, versionCode } from "./constants.js";
8
8
  import WebSocket from "ws";
9
9
  // Created by Moon on 6/12/2022
10
10
  export * from "./scraper.js";
11
11
  export * from "./models/models.js";
12
+ export var LogLevel;
13
+ (function (LogLevel) {
14
+ LogLevel[LogLevel["Quiet"] = 0] = "Quiet";
15
+ LogLevel[LogLevel["Debug"] = 1] = "Debug";
16
+ LogLevel[LogLevel["Info"] = 2] = "Info";
17
+ })(LogLevel = LogLevel || (LogLevel = {}));
12
18
  export class TAClient extends CustomEventEmitter {
13
19
  _imageServer = `https://${masterAddress}:${masterApiPort}`;
14
20
  stateManager;
15
21
  uiVersion;
22
+ logLevel;
16
23
  client;
17
24
  token = "";
18
25
  shouldHeartbeat = false;
19
26
  heartbeatInterval;
20
- constructor(uiVersion = undefined) {
27
+ constructor(uiVersion = undefined, logLevel = LogLevel.Quiet) {
21
28
  super();
22
29
  this.stateManager = new StateManager();
23
30
  this.uiVersion = uiVersion;
31
+ this.logLevel = logLevel;
32
+ }
33
+ // --- Logging --- //
34
+ logInfo(object) {
35
+ if (this.logLevel >= LogLevel.Info) {
36
+ console.log(object);
37
+ }
38
+ }
39
+ logError(object) {
40
+ if (this.logLevel >= LogLevel.Debug) {
41
+ console.error(object);
42
+ }
24
43
  }
25
44
  // --- State helpers --- //
26
45
  get isConnected() {
@@ -36,11 +55,11 @@ export class TAClient extends CustomEventEmitter {
36
55
  this.client.on("packetReceived", this.handlePacket);
37
56
  this.client.on("disconnectedFromServer", () => {
38
57
  clearInterval(this.heartbeatInterval);
39
- console.info("Disconnected from server!");
58
+ this.logInfo("Disconnected from server!");
40
59
  this.emit("disconnectedFromServer", {});
41
60
  });
42
61
  this.client.on("failedToConnectToServer", () => {
43
- console.error("Failed to connect to server!");
62
+ this.logError("Failed to connect to server!");
44
63
  this.emit("failedToConnectToServer", {});
45
64
  });
46
65
  this.emit("connectingToServer", {});
@@ -93,7 +112,7 @@ export class TAClient extends CustomEventEmitter {
93
112
  }
94
113
  disconnect() {
95
114
  this.shouldHeartbeat = false;
96
- console.info(`Disconnecting from server!`);
115
+ this.logInfo(`Disconnecting from server!`);
97
116
  this.client?.disconnect();
98
117
  }
99
118
  setAuthToken(token) {
@@ -106,7 +125,7 @@ export class TAClient extends CustomEventEmitter {
106
125
  if (bytes.length < 3) {
107
126
  return "";
108
127
  }
109
- const blob = new Blob([bytes], { type: "image/png" });
128
+ const blob = new Blob([new Uint8Array(bytes)], { type: "image/png" });
110
129
  const file = new File([blob], "dummy.png", {
111
130
  type: "image/png",
112
131
  });
@@ -176,8 +195,7 @@ export class TAClient extends CustomEventEmitter {
176
195
  // Add to the dictionary when the response is to this packet, and from an expected user
177
196
  const onResponseReceived = (response) => {
178
197
  const expectedUsers = to ?? ["00000000-0000-0000-0000-000000000000"]; // If we didn't forward this to any users, we should expect a response from the server
179
- if (response.response.respondingToPacketId === packet.id &&
180
- expectedUsers.includes(response.userId)) {
198
+ if (response.response.respondingToPacketId === packet.id && expectedUsers.includes(response.userId)) {
181
199
  responseDictionary.push({
182
200
  userId: response.userId,
183
201
  response: response.response,
@@ -472,11 +490,7 @@ export class TAClient extends CustomEventEmitter {
472
490
  else if (packet.packet.oneofKind === "request") {
473
491
  const request = packet.packet.request;
474
492
  if (request.type.oneofKind === "loadSong") {
475
- this.emit("loadSongRequested", [
476
- packet.id,
477
- packet.from,
478
- request.type.loadSong,
479
- ]);
493
+ this.emit("loadSongRequested", [packet.id, packet.from, request.type.loadSong]);
480
494
  }
481
495
  }
482
496
  else if (packet.packet.oneofKind === "response") {
@@ -488,121 +502,121 @@ export class TAClient extends CustomEventEmitter {
488
502
  if (response.details.oneofKind === "connect") {
489
503
  const connect = response.details.connect;
490
504
  if (response.type === Response_ResponseType.Success) {
491
- console.info(`Successfully connected to server!`);
505
+ this.logInfo(`Successfully connected to server!`);
492
506
  this.emit("connectedToServer", connect);
493
507
  }
494
508
  else {
495
- console.error(`Failed to connect to server. Message: ${connect.message}`);
509
+ this.logError(`Failed to connect to server. Message: ${connect.message}`);
496
510
  this.emit("failedToConnectToServer", {});
497
511
  }
498
512
  }
499
513
  else if (response.details.oneofKind === "join") {
500
514
  const join = response.details.join;
501
515
  if (response.type === Response_ResponseType.Success) {
502
- console.info(`Successfully joined tournament!`);
516
+ this.logInfo(`Successfully joined tournament!`);
503
517
  this.emit("joinedTournament", {});
504
518
  }
505
519
  else {
506
- console.error(`Failed to join server. Message: ${join.message}`);
520
+ this.logError(`Failed to join server. Message: ${join.message}`);
507
521
  this.emit("failedToJoinTournament", {});
508
522
  }
509
523
  }
510
524
  else if (response.details.oneofKind === "createTournament") {
511
525
  const createTournament = response.details.createTournament;
512
526
  if (response.type === Response_ResponseType.Success) {
513
- console.info(`Successfully created tournament!`);
527
+ this.logInfo(`Successfully created tournament!`);
514
528
  this.emit("createdTournament", {});
515
529
  }
516
530
  else {
517
- console.error(`Failed to create tournament. Message: ${createTournament.message}`);
531
+ this.logError(`Failed to create tournament. Message: ${createTournament.message}`);
518
532
  this.emit("failedToCreateTournament", {});
519
533
  }
520
534
  }
521
535
  else if (response.details.oneofKind === "updateTournament") {
522
536
  const updateTournament = response.details.updateTournament;
523
537
  if (response.type === Response_ResponseType.Success) {
524
- console.info(`Successfully modified tournament!`);
538
+ this.logInfo(`Successfully modified tournament!`);
525
539
  this.emit("updatedTournament", {});
526
540
  }
527
541
  else {
528
- console.error(`Failed update tournament. Message: ${updateTournament.message}`);
542
+ this.logError(`Failed update tournament. Message: ${updateTournament.message}`);
529
543
  this.emit("failedToUpdateTournament", {});
530
544
  }
531
545
  }
532
546
  else if (response.details.oneofKind === "deleteTournament") {
533
547
  const deleteTournament = response.details.deleteTournament;
534
548
  if (response.type === Response_ResponseType.Success) {
535
- console.info(`Successfully deleted tournament!`);
549
+ this.logInfo(`Successfully deleted tournament!`);
536
550
  this.emit("deletedTournament", {});
537
551
  }
538
552
  else {
539
- console.error(`Failed to delete tournament. Message: ${deleteTournament.message}`);
553
+ this.logError(`Failed to delete tournament. Message: ${deleteTournament.message}`);
540
554
  this.emit("failedToDeleteTournament", {});
541
555
  }
542
556
  }
543
557
  else if (response.details.oneofKind === "createMatch") {
544
558
  const createMatch = response.details.createMatch;
545
559
  if (response.type === Response_ResponseType.Success) {
546
- console.info(`Successfully created match!`);
560
+ this.logInfo(`Successfully created match!`);
547
561
  this.emit("createdMatch", {});
548
562
  }
549
563
  else {
550
- console.error(`Failed to create Match. Message: ${createMatch.message}`);
564
+ this.logError(`Failed to create Match. Message: ${createMatch.message}`);
551
565
  this.emit("failedToCreateMatch", {});
552
566
  }
553
567
  }
554
568
  else if (response.details.oneofKind === "updateMatch") {
555
569
  const updateMatch = response.details.updateMatch;
556
570
  if (response.type === Response_ResponseType.Success) {
557
- console.info(`Successfully modified match!`);
571
+ this.logInfo(`Successfully modified match!`);
558
572
  this.emit("updatedMatch", {});
559
573
  }
560
574
  else {
561
- console.error(`Failed update Match. Message: ${updateMatch.message}`);
575
+ this.logError(`Failed update Match. Message: ${updateMatch.message}`);
562
576
  this.emit("failedToUpdateMatch", {});
563
577
  }
564
578
  }
565
579
  else if (response.details.oneofKind === "deleteMatch") {
566
580
  const deleteMatch = response.details.deleteMatch;
567
581
  if (response.type === Response_ResponseType.Success) {
568
- console.info(`Successfully deleted match!`);
582
+ this.logInfo(`Successfully deleted match!`);
569
583
  this.emit("deletedMatch", {});
570
584
  }
571
585
  else {
572
- console.error(`Failed to delete Match. Message: ${deleteMatch.message}`);
586
+ this.logError(`Failed to delete Match. Message: ${deleteMatch.message}`);
573
587
  this.emit("failedToDeleteMatch", {});
574
588
  }
575
589
  }
576
590
  else if (response.details.oneofKind === "createQualifierEvent") {
577
591
  const createQualifierEvent = response.details.createQualifierEvent;
578
592
  if (response.type === Response_ResponseType.Success) {
579
- console.info(`Successfully created qualifier!`);
593
+ this.logInfo(`Successfully created qualifier!`);
580
594
  this.emit("createdQualifier", {});
581
595
  }
582
596
  else {
583
- console.error(`Failed to create qualifier. Message: ${createQualifierEvent.message}`);
597
+ this.logError(`Failed to create qualifier. Message: ${createQualifierEvent.message}`);
584
598
  this.emit("failedToCreateQualifier", {});
585
599
  }
586
600
  }
587
601
  else if (response.details.oneofKind === "updateQualifierEvent") {
588
602
  const modifyQualifier = response.details.updateQualifierEvent;
589
603
  if (response.type === Response_ResponseType.Success) {
590
- console.info(`Successfully modified qualifier!`);
604
+ this.logInfo(`Successfully modified qualifier!`);
591
605
  this.emit("updatedQualifier", {});
592
606
  }
593
607
  else {
594
- console.error(`Failed to update qualifier. Message: ${modifyQualifier.message}`);
608
+ this.logError(`Failed to update qualifier. Message: ${modifyQualifier.message}`);
595
609
  this.emit("failedToUpdateQualifier", {});
596
610
  }
597
611
  }
598
612
  else if (response.details.oneofKind === "deleteQualifierEvent") {
599
613
  const deleteQualifierEvent = response.details.deleteQualifierEvent;
600
614
  if (response.type === Response_ResponseType.Success) {
601
- console.info(`Successfully deleted qualifier!`);
615
+ this.logInfo(`Successfully deleted qualifier!`);
602
616
  this.emit("deletedQualifier", {});
603
617
  }
604
618
  else {
605
- console.error(`Failed to delete qualifier. Message: ${deleteQualifierEvent.message}`);
619
+ this.logError(`Failed to delete qualifier. Message: ${deleteQualifierEvent.message}`);
606
620
  this.emit("failedToDeleteQualifier", {});
607
621
  }
608
622
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moons-ta-client",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",