fromJson static method

Message? fromJson(
  1. Map<String, dynamic> json
)

Deserialize a shared message (PingMessage, PongMessage, ErrorMessage) from a JSON string.

Returns null for every other type code, so it can be chained after a mode-specific decoder that handles that mode's own frames.

Implementation

static Message? fromJson(Map<String, dynamic> json) {
  final type = json['type'] as int;
  if (type == MessageType.ping.value) {
    return PingMessage.fromJson(json);
  }
  if (type == MessageType.pong.value) {
    return PongMessage.fromJson(json);
  }
  if (type == MessageType.error.value) {
    return ErrorMessage.fromJson(json);
  }
  return null;
}