onMessage method

void onMessage(
  1. dynamic callback(
    1. dynamic
    )
)

Adds a callback handler to this WebSocket sent data.

On each data event from this WebSocket, the subscriber's onMessage handler is called. If onMessage is null, nothing happens.

If you received any message before setting this callback handler you are not going to received past data.

Implementation

void onMessage(Function(dynamic) callback) {
  _messageCallback = callback;
  _startMessageServices().then((_) {
    _onMessage();
  });
}