Jump to top

OnDisconnect

interface

The onDisconnect class allows you to write or clear data when your client disconnects from the Database server. These updates occur whether your client disconnects cleanly or not, so you can rely on them to clean up data even if a connection is dropped or a client crashes.

The onDisconnect class is most commonly used to manage presence in applications where it is useful to detect how many clients are connected and when other clients disconnect.

To avoid problems when a connection is dropped before the requests can be transferred to the Database server, these functions should be called before writing any data.

Note that onDisconnect operations are only triggered once. If you want an operation to occur each time a disconnect occurs, you'll need to re-establish the onDisconnect operations each time you reconnect.

Methods

cancel

</>

Cancels all previously queued onDisconnect() set or update events for this location and all children.

cancel(onComplete?: Function): Promise<void>;

remove

</>

Ensures the data at this location is deleted when the client is disconnected (due to closing the browser, navigating to a new page, or network issues).

remove(onComplete?: Function): Promise<void>;

set

</>

Ensures the data at this location is set to the specified value when the client is disconnected (due to closing the app, navigating to a new view, or network issues).

set(value: any, onComplete?: Function): Promise<void>;

setWithPriority

</>

Ensures the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues).

setWithPriority(value: any, priority: string | number | null, onComplete?: Function): Promise<void>;

update

</>

Writes multiple values at this location when the client is disconnected (due to closing the browser, navigating to a new page, or network issues).

update(values: { [key: string]: value }, onComplete?: Function): Promise<void>;