cuppsResponseHandler static method

dynamic cuppsResponseHandler(
  1. CuppsBase response,
  2. String rawXML
)

Implementation

static cuppsResponseHandler(CuppsBase response, String rawXML) async {
  switch (response.messageName) {
    case CuppsMessageID.applicationStopCommandResponse:
      {
        ApplicationStopCommandResponse res = ApplicationStopCommandResponse.fromXML(rawXML);
        log(res.toXML());
        break;
      }
    case CuppsMessageID.applicationStopCommandRequest:
      {
        ApplicationStopCommandRequest req = ApplicationStopCommandRequest.fromXML(rawXML);
        ApplicationStopCommandResponse stopRes = ApplicationStopCommandResponse(
            messageID: req.messageID, messageName: "applicationStopCommandResponse", result: "defer");
        _instance.autoClosing = true;
        await respond(xml: stopRes.toXML());
        if (_instance.onStopCommand == null) {
          log("Please define on Stop Command");
        }
        if (req.canDefer == "true") {
          _instance.onStopCommand?.call(
              canDefer: true,
              onForceClose: () {
                _instance.autoClosing = false;
                disconnectFromPlatform();
              },
              onDefer: () {
                _instance.autoClosing = false;
              });

          /// defer called
          /// defer or close pop op => force close=> disconnect else nothing
          /// only stop if user select defer
          Future.delayed(const Duration(seconds: 30), () {
            if (_instance.autoClosing) {
              disconnectFromPlatform();
            }
          });
        } else {
          _instance.onStopCommand?.call(
              canDefer: false,
              onForceClose: () {
                _instance.autoClosing = false;
                disconnectFromPlatform();
              },
              onDefer: () {});

          /// defer called
          /// show timer 30 sec after dc => if user force close => disconnect
          Future.delayed(const Duration(seconds: 30), () {
            if (_instance.autoClosing) {
              disconnectFromPlatform();
            }
          });
        }
        break;
      }
    case CuppsMessageID.notify:
      {
        Notify res = Notify.fromXML(rawXML);
        switch (res.notificationType) {
          case NotificationType.deviceStatus:
            {
              // DeviceLockRequest req = DeviceLockRequest(messageID: currentMessageID, lockMethod: "byConnection",renew: "false");
              // send(xml: req.toXML());
              log("RECEIVED Device Status Notification");
              break;
            }
          case NotificationType.sessionErrorEvent:
            {
              onPlatformClose();
              // DeviceLockRequest req = DeviceLockRequest(messageID: currentMessageID, lockMethod: "byConnection",renew: "false");
              // send(xml: req.toXML());
              log("RECEIVED sessionErrorEvent Notification");
              break;
            }
          case NotificationType.illogicalMessageErrorEvent:
            {
              onPlatformClose();
              // DeviceLockRequest req = DeviceLockRequest(messageID: currentMessageID, lockMethod: "byConnection",renew: "false");
              // send(xml: req.toXML());
              log("RECEIVED illogicalMessageErrorEvent Notification");
              break;
            }
          case NotificationType.messageIDErrorEvent:
            {
              onPlatformClose();
              // DeviceLockRequest req = DeviceLockRequest(messageID: currentMessageID, lockMethod: "byConnection",renew: "false");
              // send(xml: req.toXML());
              log("RECEIVED messageIDErrorEvent Notification");
              break;
            }
          default:
            {
              log("${res.notificationType.name} Notification Received on Platform");
            }
        }

        break;
      }
    case CuppsMessageID.bye:
      {
        ByeResponse res = ByeResponse.fromXML(rawXML);
        log("Bye Response Received ${res.result}");
        // closeSocket();
        break;
      }
    default:
      {
        log(rawXML);
      }
  }
  _instance.notifier!();
}