TinyBase logoTinyBase

getPathIds

The getPathIds method returns the active paths that the WsServer is handling.

getPathIds(): Ids
returnsIds

An array of the paths that have clients connected to them.

These will be all the paths that have at least one active client connected to them.

Example

This example creates a WsServer, sets some clients up to connect to it, and then enumerates the paths being used.

import {WebSocket, WebSocketServer} from 'ws';
import {createMergeableStore} from 'tinybase';
import {createWsServer} from 'tinybase/synchronizers/synchronizer-ws-server';
import {createWsSynchronizer} from 'tinybase/synchronizers/synchronizer-ws-client';

const server = createWsServer(new WebSocketServer({port: 8047}));
console.log(server.getPathIds());
// -> []

const synchronizer1 = await createWsSynchronizer(
  createMergeableStore(),
  new WebSocket('ws://localhost:8047/roomA'),
);
const synchronizer2 = await createWsSynchronizer(
  createMergeableStore(),
  new WebSocket('ws://localhost:8047/roomA'),
);
const synchronizer3 = await createWsSynchronizer(
  createMergeableStore(),
  new WebSocket('ws://localhost:8047/roomB'),
);

console.log(server.getPathIds());
// -> ['roomA', 'roomB']

synchronizer3.destroy();
// ...
console.log(server.getPathIds());
// -> ['roomA']

synchronizer1.destroy();
synchronizer2.destroy();
server.destroy();

Since

v5.0.0