TinyBase logoTinyBase

getStats

The getStats method provides a set of statistics about the WsServer, and is used for debugging purposes.

getStats(): WsServerStats
returnsWsServerStats

A WsServerStats object containing statistics.

The WsServerStats object contains the number of paths and clients that are active on the WsServer and is intended to be used during development.

Example

This example creates a WsServer that facilitates some synchronization, demonstrating the statistics of the paths and clients handled as a result.

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

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

console.log(server.getStats());
// -> {paths: 1, clients: 2}

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

Since

v5.0.0