Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async methods for requesting packets #53

Closed
mkapal opened this issue Aug 6, 2024 · 0 comments
Closed

Async methods for requesting packets #53

mkapal opened this issue Aug 6, 2024 · 0 comments
Assignees

Comments

@mkapal
Copy link
Member

mkapal commented Aug 6, 2024

As suggested in #51 (comment)

Problem

There are cases when a request packet is sent and then a response is received in another packet. When doing that, you must keep several things in mind:

  • keep the ReqI of the request packet in sync with the check in the reply packet event listener
  • make sure the ReqI is unique so the listener will only handle the correct request and not a different one

Example:

const REQUEST_ID = 255;

this.send(
  new IS_TINY({
    ReqI: REQUEST_ID,
    SubT: TinyType.TINY_GTH,
  }),
);

this.once(PacketType.ISP_SMALL, (packet) => {
  if (packet.ReqI === REQUEST_ID && packet.SubT === SmallType.SMALL_RTP) {
    // Do something with packet.UVal
  }
});

Solution

Create new public async methods in the InSim class.

Example usage:

const sessionTime = await inSim.getCurrentSessionTime();

Requirements

The ReqI must be unique in such a way that if multiple requests are sent at the same time, they both get resolved independently.

Requests

Name Request packet Reply packet
Ping IS_TINY
SubT: TinyType.TINY_PING
IS_TINY
SubT: TinyType.TINY_REPLY
Get current session time IS_TINY
SubT: TinyType.TINY_GTH
IS_SMALL
SubT: SmallType.SMALL_RTP
TODO
@mkapal mkapal added enhancement New feature or request draft labels Aug 6, 2024
@mkapal mkapal self-assigned this Aug 6, 2024
@mkapal mkapal added the scope:insim InSim label Nov 26, 2024
@mkapal mkapal removed the enhancement New feature or request label Feb 9, 2025
@mkapal mkapal closed this as not planned Won't fix, can't repro, duplicate, stale Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant