moons-ta-client 1.1.3 → 1.1.5

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.
@@ -156,11 +156,11 @@ export interface Response {
156
156
  */
157
157
  preloadImageForStreamSync: Response_PreloadImageForStreamSync;
158
158
  } | {
159
- oneofKind: "showModal";
159
+ oneofKind: "showPrompt";
160
160
  /**
161
- * @generated from protobuf field: proto.packets.Response.ShowModal show_modal = 19;
161
+ * @generated from protobuf field: proto.packets.Response.ShowPrompt show_prompt = 19;
162
162
  */
163
- showModal: Response_ShowModal;
163
+ showPrompt: Response_ShowPrompt;
164
164
  } | {
165
165
  oneofKind: "remainingAttempts";
166
166
  /**
@@ -512,13 +512,13 @@ export interface Response_PreloadImageForStreamSync {
512
512
  fileId: string;
513
513
  }
514
514
  /**
515
- * @generated from protobuf message proto.packets.Response.ShowModal
515
+ * @generated from protobuf message proto.packets.Response.ShowPrompt
516
516
  */
517
- export interface Response_ShowModal {
517
+ export interface Response_ShowPrompt {
518
518
  /**
519
- * @generated from protobuf field: string modal_id = 1;
519
+ * @generated from protobuf field: string prompt_id = 1;
520
520
  */
521
- modalId: string;
521
+ promptId: string;
522
522
  /**
523
523
  * @generated from protobuf field: string value = 2;
524
524
  */
@@ -776,16 +776,16 @@ declare class Response_PreloadImageForStreamSync$Type extends MessageType<Respon
776
776
  * @generated MessageType for protobuf message proto.packets.Response.PreloadImageForStreamSync
777
777
  */
778
778
  export declare const Response_PreloadImageForStreamSync: Response_PreloadImageForStreamSync$Type;
779
- declare class Response_ShowModal$Type extends MessageType<Response_ShowModal> {
779
+ declare class Response_ShowPrompt$Type extends MessageType<Response_ShowPrompt> {
780
780
  constructor();
781
- create(value?: PartialMessage<Response_ShowModal>): Response_ShowModal;
782
- internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Response_ShowModal): Response_ShowModal;
783
- internalBinaryWrite(message: Response_ShowModal, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
781
+ create(value?: PartialMessage<Response_ShowPrompt>): Response_ShowPrompt;
782
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Response_ShowPrompt): Response_ShowPrompt;
783
+ internalBinaryWrite(message: Response_ShowPrompt, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
784
784
  }
785
785
  /**
786
- * @generated MessageType for protobuf message proto.packets.Response.ShowModal
786
+ * @generated MessageType for protobuf message proto.packets.Response.ShowPrompt
787
787
  */
788
- export declare const Response_ShowModal: Response_ShowModal$Type;
788
+ export declare const Response_ShowPrompt: Response_ShowPrompt$Type;
789
789
  declare class Response_RemainingAttempts$Type extends MessageType<Response_RemainingAttempts> {
790
790
  constructor();
791
791
  create(value?: PartialMessage<Response_RemainingAttempts>): Response_RemainingAttempts;
@@ -72,7 +72,7 @@ class Response$Type extends MessageType {
72
72
  { no: 16, name: "leaderboard_entries", kind: "message", oneof: "details", T: () => Response_LeaderboardEntries },
73
73
  { no: 17, name: "load_song", kind: "message", oneof: "details", T: () => Response_LoadSong },
74
74
  { no: 18, name: "preload_image_for_stream_sync", kind: "message", oneof: "details", T: () => Response_PreloadImageForStreamSync },
75
- { no: 19, name: "show_modal", kind: "message", oneof: "details", T: () => Response_ShowModal },
75
+ { no: 19, name: "show_prompt", kind: "message", oneof: "details", T: () => Response_ShowPrompt },
76
76
  { no: 20, name: "remaining_attempts", kind: "message", oneof: "details", T: () => Response_RemainingAttempts }
77
77
  ]);
78
78
  }
@@ -220,10 +220,10 @@ class Response$Type extends MessageType {
220
220
  preloadImageForStreamSync: Response_PreloadImageForStreamSync.internalBinaryRead(reader, reader.uint32(), options, message.details.preloadImageForStreamSync)
221
221
  };
222
222
  break;
223
- case /* proto.packets.Response.ShowModal show_modal */ 19:
223
+ case /* proto.packets.Response.ShowPrompt show_prompt */ 19:
224
224
  message.details = {
225
- oneofKind: "showModal",
226
- showModal: Response_ShowModal.internalBinaryRead(reader, reader.uint32(), options, message.details.showModal)
225
+ oneofKind: "showPrompt",
226
+ showPrompt: Response_ShowPrompt.internalBinaryRead(reader, reader.uint32(), options, message.details.showPrompt)
227
227
  };
228
228
  break;
229
229
  case /* proto.packets.Response.RemainingAttempts remaining_attempts */ 20:
@@ -313,9 +313,9 @@ class Response$Type extends MessageType {
313
313
  /* proto.packets.Response.PreloadImageForStreamSync preload_image_for_stream_sync = 18; */
314
314
  if (message.details.oneofKind === "preloadImageForStreamSync")
315
315
  Response_PreloadImageForStreamSync.internalBinaryWrite(message.details.preloadImageForStreamSync, writer.tag(18, WireType.LengthDelimited).fork(), options).join();
316
- /* proto.packets.Response.ShowModal show_modal = 19; */
317
- if (message.details.oneofKind === "showModal")
318
- Response_ShowModal.internalBinaryWrite(message.details.showModal, writer.tag(19, WireType.LengthDelimited).fork(), options).join();
316
+ /* proto.packets.Response.ShowPrompt show_prompt = 19; */
317
+ if (message.details.oneofKind === "showPrompt")
318
+ Response_ShowPrompt.internalBinaryWrite(message.details.showPrompt, writer.tag(19, WireType.LengthDelimited).fork(), options).join();
319
319
  /* proto.packets.Response.RemainingAttempts remaining_attempts = 20; */
320
320
  if (message.details.oneofKind === "remainingAttempts")
321
321
  Response_RemainingAttempts.internalBinaryWrite(message.details.remainingAttempts, writer.tag(20, WireType.LengthDelimited).fork(), options).join();
@@ -1574,15 +1574,15 @@ class Response_PreloadImageForStreamSync$Type extends MessageType {
1574
1574
  */
1575
1575
  export const Response_PreloadImageForStreamSync = new Response_PreloadImageForStreamSync$Type();
1576
1576
  // @generated message type with reflection information, may provide speed optimized methods
1577
- class Response_ShowModal$Type extends MessageType {
1577
+ class Response_ShowPrompt$Type extends MessageType {
1578
1578
  constructor() {
1579
- super("proto.packets.Response.ShowModal", [
1580
- { no: 1, name: "modal_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
1579
+ super("proto.packets.Response.ShowPrompt", [
1580
+ { no: 1, name: "prompt_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
1581
1581
  { no: 2, name: "value", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
1582
1582
  ]);
1583
1583
  }
1584
1584
  create(value) {
1585
- const message = { modalId: "", value: "" };
1585
+ const message = { promptId: "", value: "" };
1586
1586
  globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
1587
1587
  if (value !== undefined)
1588
1588
  reflectionMergePartial(this, message, value);
@@ -1593,8 +1593,8 @@ class Response_ShowModal$Type extends MessageType {
1593
1593
  while (reader.pos < end) {
1594
1594
  let [fieldNo, wireType] = reader.tag();
1595
1595
  switch (fieldNo) {
1596
- case /* string modal_id */ 1:
1597
- message.modalId = reader.string();
1596
+ case /* string prompt_id */ 1:
1597
+ message.promptId = reader.string();
1598
1598
  break;
1599
1599
  case /* string value */ 2:
1600
1600
  message.value = reader.string();
@@ -1611,9 +1611,9 @@ class Response_ShowModal$Type extends MessageType {
1611
1611
  return message;
1612
1612
  }
1613
1613
  internalBinaryWrite(message, writer, options) {
1614
- /* string modal_id = 1; */
1615
- if (message.modalId !== "")
1616
- writer.tag(1, WireType.LengthDelimited).string(message.modalId);
1614
+ /* string prompt_id = 1; */
1615
+ if (message.promptId !== "")
1616
+ writer.tag(1, WireType.LengthDelimited).string(message.promptId);
1617
1617
  /* string value = 2; */
1618
1618
  if (message.value !== "")
1619
1619
  writer.tag(2, WireType.LengthDelimited).string(message.value);
@@ -1624,9 +1624,9 @@ class Response_ShowModal$Type extends MessageType {
1624
1624
  }
1625
1625
  }
1626
1626
  /**
1627
- * @generated MessageType for protobuf message proto.packets.Response.ShowModal
1627
+ * @generated MessageType for protobuf message proto.packets.Response.ShowPrompt
1628
1628
  */
1629
- export const Response_ShowModal = new Response_ShowModal$Type();
1629
+ export const Response_ShowPrompt = new Response_ShowPrompt$Type();
1630
1630
  // @generated message type with reflection information, may provide speed optimized methods
1631
1631
  class Response_RemainingAttempts$Type extends MessageType {
1632
1632
  constructor() {
@@ -2,7 +2,7 @@ import { CustomEventEmitter } from "./custom-event-emitter.js";
2
2
  import { User, Match, QualifierEvent, CoreServer, Tournament, GameplayParameters, Map, QualifierEvent_EventSettings, QualifierEvent_LeaderboardSort, Tournament_TournamentSettings_Team, Tournament_TournamentSettings_Pool, Permissions, RealtimeScore } from "./models/models.js";
3
3
  import { StateManager } from "./state-manager.js";
4
4
  import { Response, Response_Connect } from "./models/responses.js";
5
- import { Request_LoadSong } from "./models/requests.js";
5
+ import { Request_LoadSong, Request_ShowPrompt_PromptOption } from "./models/requests.js";
6
6
  import { Channel, Push_SongFinished } from "./models/index.js";
7
7
  export * from "./scraper.js";
8
8
  export * from "./models/models.js";
@@ -66,6 +66,7 @@ export declare class TAClient extends CustomEventEmitter<TAClientEvents> {
66
66
  getLeaderboard: (tournamentId: string, qualifierId: string, mapId: string) => Promise<Response>;
67
67
  loadSong: (levelId: string, userIds: string[], timeout?: number) => Promise<ResponseFromUser[]>;
68
68
  loadImage: (bitmap: Uint8Array, userIds: string[]) => Promise<ResponseFromUser[]>;
69
+ showPrompt: (userIds: string[], titleText: string, bodyText: string, canClose: boolean, options: Request_ShowPrompt_PromptOption[], timer?: number) => Promise<ResponseFromUser[]>;
69
70
  private handlePacket;
70
71
  updateUser: (tournamentId: string, user: User) => Promise<Response>;
71
72
  createMatch: (tournamentId: string, match: Match) => Promise<Response>;
@@ -166,16 +166,6 @@ export class TAClient extends CustomEventEmitter {
166
166
  }
167
167
  return waitingForUsers;
168
168
  };
169
- // Check that we got responses from all expected users
170
- const checkResponses = () => {
171
- const waitingForUsers = getUnrespondedUsers();
172
- if (waitingForUsers.length === 0) {
173
- // All responses are received, clean up and resolve
174
- removeListeners();
175
- clearTimeout(timeoutTimer);
176
- resolve(responseDictionary);
177
- }
178
- };
179
169
  // Add to the dictionary when the response is to this packet, and from an expected user
180
170
  const onResponseReceived = (response) => {
181
171
  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
@@ -185,7 +175,12 @@ export class TAClient extends CustomEventEmitter {
185
175
  userId: response.userId,
186
176
  response: response.response,
187
177
  });
188
- checkResponses();
178
+ if (getUnrespondedUsers().length === 0) {
179
+ // All responses are received, clean up and resolve
180
+ removeListeners();
181
+ clearTimeout(timeoutTimer);
182
+ resolve(responseDictionary);
183
+ }
189
184
  }
190
185
  };
191
186
  // Return what we have after 30 seconds, inject errors for users that haven't responded yet
@@ -218,15 +213,12 @@ export class TAClient extends CustomEventEmitter {
218
213
  addListeners();
219
214
  });
220
215
  // Assume forwardToUsers emits the 'responseReceived' event asynchronously
221
- const sendRequest = () => {
222
- if (to) {
223
- this.forwardToUsers(packet, to);
224
- }
225
- else {
226
- this.client?.send(packet, to);
227
- }
228
- };
229
- sendRequest();
216
+ if (to) {
217
+ this.forwardToUsers(packet, to);
218
+ }
219
+ else {
220
+ this.client?.send(packet, to);
221
+ }
230
222
  return responsesPromise;
231
223
  }
232
224
  async sendResponse(response, to) {
@@ -344,6 +336,26 @@ export class TAClient extends CustomEventEmitter {
344
336
  }
345
337
  return response;
346
338
  };
339
+ showPrompt = async (userIds, titleText, bodyText, canClose, options, timer) => {
340
+ const response = await this.sendRequest({
341
+ type: {
342
+ oneofKind: "showPrompt",
343
+ showPrompt: {
344
+ promptId: uuidv4(),
345
+ messageTitle: titleText,
346
+ messageText: bodyText,
347
+ showTimer: !!timer,
348
+ timeout: timer ?? 0,
349
+ canClose: canClose,
350
+ options
351
+ },
352
+ },
353
+ }, userIds, timer ? timer * 1000 : timer);
354
+ if (response.length <= 0) {
355
+ throw new Error("Server timed out, or no users responded");
356
+ }
357
+ return response;
358
+ };
347
359
  // --- Packet Handler --- //
348
360
  handlePacket = (packet) => {
349
361
  this.stateManager.handlePacket(packet);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moons-ta-client",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",