handleMessage method

void handleMessage({
  1. required ReceivedMessage message,
})

消息处理器

Implementation

void handleMessage({required ReceivedMessage message}) {
  try {
    var topic = message.topic.split('/');
    if (topic.length != 3) return;
    var payload = jsonDecode(message.payload) as Map<String, dynamic>;
    var action = topic[1];

    switch (action) {
      case MessageAction.state:
        handleStateMessage(payload);
        break;
      case MessageAction.debug:
        handleDebugMessage(payload);
        break;
      case MessageAction.command:
        handleCommandMessage(payload);
        break;
      case MessageAction.rename:
        handleRenameStateMessage(payload);
        break;
    }
  } catch (e, st) {
    log("[handleMessage] 消息处理失败", error: e, stackTrace: st);
  }
}