Class: OnDisconnect

OnDisconnect

Useful class to write and remove data if user lost connection with server. It can be a connection problem or an app crash. Registered actions are executed only once. Register again your actions if you need it.

Managing presence is a common use case. You can prevent other friends if you are connected or not.

Set OnDisconnect actions as soon as possible to catch early connection problems.

Objects of this class are not intended to be constructed directly, they are rather expected to be built using the Webcom#onDisconnect method.

Methods

cancel(onCompleteopt)

Cancelling any OnDisconnect#set, OnDisconnect#update or OnDisconnect#remove actions at current location.

Parameters:
Name Type Attributes Description
onComplete function <optional>

function called when server has canceled actions. An error can be passed in parameter if something goes wrong.

Example
// Get a reference to John critical data
var ref = new Webcom("/base/contacts/friends/john/temporary");
ref.onDisconnect().set('I disconnected');

// Cancel the previously event (set() in this case)
ref.onDisconnect().cancel();

remove(onCompleteopt)

Remove data at current location when a disconnection event occurs.

Parameters:
Name Type Attributes Description
onComplete function <optional>

function called when server has registered remove action. An error can be passed in parameter if something goes wrong.

Example
// Get a reference to John critical data
var ref = new Webcom("/base/contacts/friends/john/criticalData");

ref.onDisconnect().remove();

set(newValnullable, onCompleteopt)

Set data at current location when a disconnection event occurs.

Parameters:
Name Type Attributes Description
newVal object | string | number | boolean <nullable>

new value

onComplete function <optional>

function called when server has registered set action. An error can be passed in parameter if something goes wrong.

Example
// Get a reference to John connected status
var ref = new Webcom("/base/contacts/friends/john/status");

ref.onDisconnect().set('I disconnected');

update(newVal, onCompleteopt)

Update data at current location when a disconnection event occurs.

Parameters:
Name Type Attributes Description
newVal Object

children to be added

onComplete function <optional>

function called when server has registered update action. An error can be passed in parameter if something goes wrong.

Example
Get a reference to John connected status
var ref = new Webcom("/base/contacts/friends/john/status");

ref.onDisconnect().update({message:'I disconnected'});
show
deprecated