cordis-lib / cordis

Modular, micro-service based Discord API wrapper written in TS.
https://cordis.js.org
Other
29 stars 1 forks source link

feat(gateway): resuming when connecting for the first time #60

Closed didinele closed 3 years ago

didinele commented 3 years ago

Please describe the changes this PR makes and why it should be merged: This PR introduces support for resuming when initially connecting to the websocket.

This can be really useful in case of a gateway process crash, it allows reducing packet loss significantly and is overall a faster recovery.

Example:

// get some data from something like Redis with up-to-date sequence and sessionId for each shard
// your data should be in the following format:
// [
//   { sessionId: 'this_is_totally_valid', sequence: 129 },
//   { sessionId: 'this_is_also_valid', sequence: 200 }
// ]
// Where the index of the object is the index of the shard *local* to this cluster.
// To clarify, if you have 2 clusters - each 3 shards and this code is running in your second cluster,
// your arrray indeces should be 0, 1, 2 - representing Discord shards 3, 4 and 5
const data = getData();
await clusterInstance.connect(data);

Status and versioning classification: