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.

Methods

cancel (onComplete)

api/OnDisconnect.js, line 56

Cancelling any {api.OnDisconnect#set set()}, {api.OnDisconnect#update update()} or {api.OnDisconnect#remove remove()} actions at current location.

Name Type 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 previoulsy event (set() in this case)
ref.onDisconnect().cancel();

remove (onComplete)

api/OnDisconnect.js, line 77

Remove data at current location when a disconnection event occurs.

Name Type 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 (newVal, onComplete)

api/OnDisconnect.js, line 98

Set data at current location when a disconnection event occurs.

Name Type Description
newVal Object | String | Number | Boolean | Null

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, onComplete)

api/OnDisconnect.js, line 148

Update data at current location when a disconnection event occurs.

Name Type 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'});