-
Notifications
You must be signed in to change notification settings - Fork 18
Reconnect Callback v7
- status: complete
- version: 7.x
- follows from: PushManager
The reconnect callback is a fine-grained recovery method for bringing reconnecting clients back into the game. For instance, it may send back any message missed while disconnected or execute a custom function on the reconnecting clients to re-init the game before resuming.
The reconnect callback is specified as a step property of the logic and may accept the following values.
The default callback is enabled by setting this option to true
, and it will resend all messages sent in the current step.
It is a user-defined function that receives two input parameters:
- player: the object representation of the player that just reconnected,
- reconOptions: a pre-initialized object containing the reconnection options to be sent to the reconnecting client.
The reconnect callback must decorate the reconOptions object with the properties necessary to resume the game properly. The following properties have a special meaning:
-
plot: an object whose properties will replace the step properties of current step. It is prefilled with the following properties:
- "timer": the time left in current step,
- "role": the role of the client in current step (if any),
- "partner": the partner of the client in current step (if any).
-
cb: a function called in the reconnecting client to prepare it for
resuming the game. It receives the reconOptions object as input parameter. -
targetStep: this option is preset by the server, and should not be modified. The step of reconnection for the client. Default: the step in which the client disconnected, or the step at which the logic currently is, if more advanced.
-
willBeDone: this option is preset by the server, and should not be modified. If TRUE, the client calls
node.done()
immediately after resuming. However, thedone
handler is not invoked, and no "set" message is sent to the server (supposedly, the client disconnected while being DONE in current step and this information has already been sent to the server). -
beDone: this option is preset by the server, and should not be modified. If TRUE, it makes game done immediately when entering a step (no frame loaded, no callback executed like in
willBeDone
).
Finally, if the reconnect callback returns FALSE, then the reconnection procedure is ended immediately and the client is disposed.
If the reconnecting client is expecting to access a value stored in a previous step (e.g., node.game.counter
), the reconnect callback would decorate the reconOptions object as follows:
stager.extendStep('game', {
reconnect: function(player, reconOpts) {
reconOpts.counter = 100;
reconOpts.cb = function(reconOpts) {
node.game.counter = reconOpts.counter;
};
}
});
Go back to the wiki Home.
Copyright (C) 2021 Stefano Balietti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.