Reconnect Callback v7 - nodeGame/nodegame GitHub Wiki

  • status: complete
  • version: 7.x
  • follows from: PushManager

The Reconnect Callback

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.

Default callback

The default callback is enabled by setting this option to true, and it will resend all messages sent in the current step.

Custom callback

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, the done 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.

Example

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;
        };
    }
});

Next

Go Back to

⚠️ **GitHub.com Fallback** ⚠️