satanch / node-livesplit-client

Zero-dependency Node.js client library for the LiveSplit Server.
https://satanch.github.io/node-livesplit-client/
MIT License
12 stars 3 forks source link

Use a nonce to guarantee message responses #7

Closed jhobz closed 8 months ago

jhobz commented 2 years ago

LiveSplit.Server is not guaranteed to respond to messages in the same order they are received. This change uses the "nonce" field in the new JSON messaging standard to provide a unique identifier against which to match incoming and outgoing messages.

Currently, the class member this._openRequests added by this change is not actually used for anything. But it does provide a useful method for investigating errors or commands that never receive a response.

It also may be desired in the future to change the listening behavior of this library to use a single listener that looks up the appropriate Promise resolver in this._openRequests instead of the current behavior -- subscribing a new listener for every message. Another alternative would be to extend EventEmitter2 instead of EventEmitter, which would allow for namespacing events and subscribing listeners to only events emitted with their nonce. But as this would create a new dependency and be a larger change, I felt it made more sense to make the simpler change first.

Note that this PR depends on #6.

satanch commented 8 months ago

This PR is pretty outdated. Let's coma back to this issue when server changes would be applied.