ClientReceived.from constructor

ClientReceived.from(
  1. dynamic data
)

Implementation

factory ClientReceived.from(data){
  if(data == 'pong' || data == 'welcome') {
    return ClientReceivedIgnore();
  }

  final Map<String,dynamic> messageMap = data is String ? jsonDecode(data) : data;
  if(messageMap["serverId"]==null) {
    throw 'Unknown: ${Map.from(messageMap)}';
  }
  if(messageMap[ServerConfirmReceiptCli.typeResponse]!=null) {
    return ClientReceivedServerConfirmReceipt(messageMap);
  }
  if(messageMap[NewDataForListener.type]!=null) {
    return ClientReceivedNewDataForListener(messageMap);
  }
  if(messageMap[InternalAsklessResponseModel.type]!=null) {
    return ClientReceivedResponse(messageMap);
  }
  if(messageMap[StopListeningEventEvent.type]!=null) {
    return ClientReceivedStopListeningEvent(messageMap);
  }

  throw "TODO: $messageMap";
}