onMessage method

  1. @override
void onMessage(
  1. ClientSession session,
  2. Message message
)
override

Called when a message is received from a client, after it has been decoded.

This method is called for all messages, not just custom messages handled by this plugin.

The plugin can then react to the message, for example by sending a response to the client.

If the session terminates, this method will not be called again.

Implementation

@override
void onMessage(ClientSession session, Message message) {
  if (message is! AwarenessMessage) {
    return;
  }

  switch (message.type) {
    case AwarenessMessageType.awarenessUpdate:
      _handleAwarenessUpdate(
        session,
        message as AwarenessUpdateMessage,
      );
      return;
    case AwarenessMessageType.awarenessQuery:
      _handleAwarenessQuery(
        session,
        message as AwarenessQueryMessage,
      );
      return;

    // server should not receive awareness state messages
    case AwarenessMessageType.awarenessState:
      return;
  }
}