setPriPush method

Future<bool> setPriPush({
  1. bool pushEnable = true,
  2. bool videoEnable = true,
  3. int videoDuration = 15,
  4. int autoRecordMode = 0,
  5. int timeout = 5,
})

Implementation

Future<bool> setPriPush(
    {bool pushEnable = true,
    bool videoEnable = true,
    int videoDuration = 15,
    int autoRecordMode = 0,
    int timeout = 5}) async {
  pushEnable = (pushEnable ?? pirPushEnable) ?? false;
  videoEnable = (videoEnable ?? pirPushVideoEnable) ?? false;
  videoDuration = (videoDuration ?? pirCloudVideoDuration) ?? 15;
  autoRecordMode = (autoRecordMode ?? autoRecordVideoMode) ?? 0;
  String cgi =
      "trans_cmd_string.cgi?cmd=2106&command=9&pirPushSwitch=${pushEnable ? 1 : 0}&pirPushSwitchVideo=${videoEnable ? 1 : 0}&";
  if (videoDuration != -1) {
    cgi =
        "trans_cmd_string.cgi?cmd=2106&command=9&pirPushSwitch=${pushEnable ? 1 : 0}&pirPushSwitchVideo=${videoEnable ? 1 : 0}&CloudVideoDuration=${videoDuration ?? 15}&autoRecordMode=${autoRecordMode ?? 0}&";
  }
  bool ret = await writeCgi(cgi, timeout: timeout);
  if (ret) {
    CommandResult result = await waitCommandResult((int cmd, Uint8List data) {
      if (cmd == 24785) {
        String str = utf8.decode(data);
        return str.contains("cmd=2106;") && str.contains("command=9;");
      }
      return false;
    }, timeout);
    if (result.isSuccess) {
      Map data = result.getMap();
      if (data["result"] == "0") {
        pirPushEnable = pushEnable;
        pirPushVideoEnable = videoEnable;
        pirCloudVideoDuration = videoDuration;
        autoRecordVideoMode = autoRecordMode;
        return true;
      }
    }
  }
  return false;
}