TinyBase logoTinyBase

delListener

The delListener method removes a listener that was previously added to the WsServer.

delListener(listenerId: string): WsServer
TypeDescription
listenerIdstring

The Id of the listener to remove.

returnsWsServer

A reference to the WsServer.

Use the Id returned by whichever method was used to add the listener. Note that the WsServer may re-use this Id for future listeners added to it.

Example

This example registers a listener to a WsServer and then removes it.

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 listenerId = server.addPathIdsListener(() => {
  console.log('Paths changed');
});

const synchronizer = await createWsSynchronizer(
  createMergeableStore(),
  new WebSocket('ws://localhost:8047/roomA'),
);
// -> 'Paths changed'

server.delListener(listenerId);

synchronizer.destroy();
// -> undefined
// The listener is not called.

server.destroy();

Since

v5.0.0