TinyBase logoTinyBase

onMessage

The onMessage method is called when the server receives a message from a client.

onMessage(
  message: string,
  connection: Connection,
): Promise<void>
TypeDescription
messagestring
connectionConnection
returnsPromise<void>

This has no return value.

If you choose to implement additional functionality in this method, you must remember to call the super implementation to ensure the TinyBase synchronization stays supported.

import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';

export class MyServer extends TinyBasePartyKitServer {
  async onMessage(message, connection) {
    await super.onMessage(message, connection);
    // custom onMessage code
  }
}

See the PartyKit server API documentation for more details.

Since

v4.3.0