decode static method
Null when message is not a frame this client can read. A malformed
message is dropped rather than thrown: one bad payload from a server or
a proxy is not a reason to tear down every channel on the socket.
Implementation
static RealtimeFrame? decode(Object? message) {
if (message is! String) return null;
final Object? envelope;
try {
envelope = jsonDecode(message);
} on FormatException {
return null;
}
if (envelope is! Map) return null;
final event = envelope['event'];
if (event is! String) return null;
final channel = envelope['channel'];
return RealtimeFrame(
event,
_inner(envelope['data']),
channel: channel is String ? channel : null,
);
}