Class: OnDisconnect

OnDisconnect(repo, path, name)

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.

Constructor

new OnDisconnect(repo, path, name)

OnDisconnect constructor

Parameters:
Name Type Description
repo core.Repo
path core.util.Path
name String

Methods

cancel(onCompleteopt)

Cancelling any {api.OnDisconnect#set set()}, {api.OnDisconnect#update update()} or {api.OnDisconnect#remove 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 previoulsy 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(newVal, onCompleteopt)

Set data at current location when a disconnection event occurs.

Parameters:
Name Type Attributes 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');

setWithPriority(newVal, priority, onCompleteopt)

Set data and its priority at current location when a disconnection event occurs.

Parameters:
Name Type Attributes Description
newVal Object | String | Number | Boolean | Null

new value

priority String | Number

priority value for new value

onComplete function <optional>

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

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

ref.onDisconnect().setWithPriority('I disconnected',5);

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