Skip to content
Discussion options

You must be logged in to vote

Hi!

To prevent duplicates, you can include an ID when sending your event, for example:

function randomId() {
  return Math.random().toString(36).substring(2, 11);
}

socket.emit("my-event", randomId());

And then on the server:

socket.on("my-event", (offset) => {
  // store the offset, either on the socket object itself or in a database
});

You can check the step 8 of the tutorial for a complete example: https://socket.io/docs/v4/tutorial/step-8

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ayyanar-finstein
Comment options

Answer selected by darrachequesne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants