setMessageChannel static method

void setMessageChannel()

Implementation

static void setMessageChannel() {
  channel = channel ?? const BasicMessageChannel("plotline", JSONMessageCodec());
  channel?.setMessageHandler((message) async {
    Map<String, dynamic> messageMap = message;
    plotlineDebugLog("Plotline Basic Message Channel: message received $message");
    switch (messageMap["method"]) {
      case "getAllElements":
        double pixRatio = double.parse(messageMap["pixelRatio"].toString());
        getAllElements(messageMap["listenerId"], pixRatio,
            messageMap["screenWidth"], messageMap["screenHeight"]);
        break;
      case "areViewsPresent":
        double pixRatio = double.parse(messageMap["pixelRatio"].toString());
        areViewsPresent(
            messageMap["listenerId"],
            messageMap["searchElements"],
            pixRatio,
            messageMap["screenWidth"],
            messageMap["screenHeight"]);
        break;
      case "getViewPosition":
        double pixRatio = double.parse(messageMap["pixelRatio"].toString());
        getViewPosition(
            messageMap["listenerId"],
            messageMap["clientElementId"],
            pixRatio,
            messageMap["screenWidth"],
            messageMap["screenHeight"]);
        break;
      case "setPlotlineEventsListener":
        try {
          _callback(messageMap["eventName"], messageMap["properties"]);
        } catch (e) {
          plotlineDebugLog("Error in passing Plotline Events: $e");
        }
        break;
      case "setPlotlineNotificationClickListener":
        try {
          _notificationClickListener(messageMap["customData"]);
        } catch (e) {
          plotlineDebugLog("Error in passing Plotline Notification Click Listener: $e");
        }
        break;
      case "setPlotlineRedirectListener":
        try {
          _redirectCallback(messageMap["properties"]);
        } catch (e) {
          plotlineDebugLog("Error in passing Plotline Redirect Listener: $e");
        }
        break;
      case "initSuccessfulCallback":
        try {
          _initSuccessfulCallback();
        } catch(e) {
          plotlineDebugLog("Error in passing initSuccessfulCallback: $e");
        }
        break;
      case "initFailureCallback":
        try {
          _initFailureCallback(messageMap["error"]);
        } catch(e) {
          plotlineDebugLog("Error in passing initSuccessfulCallback: $e");
        }
        break;
    }
  });
}