TinyBase logoTinyBase

onPathId

The onPathId method is called when the first client connects to, or the last client disconnects from, the server with a given path Id.

onPathId(
  pathId: string,
  addedOrRemoved: IdAddedOrRemoved,
): void
TypeDescription
pathIdstring

The Id of the path being served by the Durable Object.

addedOrRemovedIdAddedOrRemoved

Whether the path had the first joiner, or the last leaver.

returnsvoid

This has no return value.

This method is called with the path Id and an IdAddedOrRemoved flag indicating whether it this is being triggered by the first client joining (1) or the last client leaving (-1).

Example

This example logs the Id of the path being served by the Durable Object when the first client joins (the path Id is 'added'), and when the last client leaves (the path Id is 'removed').

import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';

export class MyDurableObject extends WsServerDurableObject {
  onPathId(pathId, addedOrRemoved) {
    console.info(
      (addedOrRemoved ? 'Added' : 'Removed') + ` path ${pathId}`,
    );
  }
}

Since

v5.4.0