TinyBase logoTinyBase β

getWebSocket

The getWebSocket method returns a reference to the WebSocket being used for synchronization.

getWebSocket(): WebSocketType
returnsWebSocketType

The WebSocket reference.

Example

This example creates a server and WsSynchronizer object for a newly-created MergeableStore and then gets the WebSocket reference back out again.

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

const store = createMergeableStore();
const webSocket = new WebSocket('ws://localhost:8046');
const synchronizer = await createWsSynchronizer(store, webSocket);

console.log(synchronizer.getWebSocket() == webSocket);
// -> true

synchronizer.destroy();
server.destroy();

Since

v5.0.0