handleWebSocketConnection method

  1. @protected
void handleWebSocketConnection(
  1. Channel id,
  2. NetworkerSocketInfo info,
  3. WebSocket socket
)
inherited

Sets up listeners for a WebSocket connection.

Override this method to customize how messages from the socket are processed, or to add custom error handling per connection.

Implementation

@protected
void handleWebSocketConnection(
  Channel id,
  NetworkerSocketInfo info,
  WebSocket socket,
) {
  socket.listen(
    (event) {
      try {
        if (event is String) {
          event = Uint8List.fromList(event.codeUnits);
        }
        handleData(event, id);
      } catch (_) {}
    },
    onDone: () {
      removeConnection(id);
    },
  );
}