mapMessageHandle method

  1. @override
Future<void> mapMessageHandle(
  1. Map<String, dynamic> data,
  2. SocketConnect socketConnect
)
override

json类型的数据处理

Implementation

@override
Future<void> mapMessageHandle(
    Map<String, dynamic> data, SocketConnect socketConnect) async {
  try {
    final action = HivePluginAction.fromJson(data);
    final type = action.handleType.keyType;
    if(type == HiveGetTypes.getBoxList.keyType){
      socketConnect.sendMap(
          PublicSendModel.arr(
              type: type,
              data: getBoxNames.map((e) => e.boxName).toList())
              .toJson(),
          'hive_$type');
    }else if(type == HiveGetTypes.getKeys.keyType){
      final obj = action as HiveGetKeys;
      if (socketConnect.appProjectName == obj.projectName) {
        final box = await findBox(obj.boxName);
        if (box != null) {
          final sendModel = PublicSendModel.arr(
              type: type,
              data: box.keys.map((e) => e.toString()).toList());
          socketConnect.sendMap(sendModel.toJson(), 'hive_$type');
        }
      }
    }else if(type == HiveGetTypes.getValue.keyType){
      final obj = action as HiveGetValue;
      if (socketConnect.appProjectName == obj.projectName) {
        final box = await findBox(obj.boxName);
        if (box != null) {
          final keys = box.keys;
          try {
            final find =
            keys.firstWhere((element) => element.toString() == obj.key);
            var getValue = box.get(find);

            try {
              jsonEncode(getValue);
            } catch (e) {
              getValue = getValue.toString();
            }

            final makeModel =
            PublicSendModel.any(type: type, data: getValue);
            socketConnect.sendMap(
                makeModel.toJson(), 'hive_$type');
          } catch (e, s) {
            ddCheckPluginLog('send data fail : ${obj.toJson()}  \n$e\n$s');
          }
        }
      }
    }
  } on CheckedFromJsonException catch (_) {
    ddCheckPluginLog('Unable to process this request: ${jsonEncode(data)}');
  }
}