import 'dart:convert';
import 'dart:typed_data';

import 'package:flyinsono/js_platform/methods.dart';
import 'package:flyinsono/managers/interfaces/entities/single_frame_params.dart';
import 'package:flyinsono/managers/interfaces/flyinsono_college.dart';
import 'package:flyinsono/managers/interfaces/local_rtmp.dart';
import 'package:get/get.dart';

import 'base.dart';

class SingleFrameReceivedHandler extends MethodHandlerBase {
  SingleFrameReceivedHandler()
      : super(TargetMethodName.OnSingleFrameImageReceive);
  @override
  void execute(List<String> args) {
    var url = args[0];
    Uint8List byteData = base64.decode(url);
    Get.find<ILocalRtmpManager>().onSingleFrameImageReceive.emit(this,
        SingleFrameParams(byteData, int.parse(args[1]), int.parse(args[2])));
  }
}

class ScreenshotHandler extends MethodHandlerBase {
  ScreenshotHandler() : super(TargetMethodName.Screenshot);
  @override
  void execute(List<String> args) {
    Get.find<ILocalRtmpManager>().onCaptureFrame.emit(this, true);
  }
}

class RecordHandler extends MethodHandlerBase {
  RecordHandler() : super(TargetMethodName.Record);
  @override
  void execute(List<String> args) {
    bool isStart = false;
    if (args[0] == "true" || args[0] == "True") {
      isStart = true;
    }
    Get.find<ILocalRtmpManager>().onRecord.emit(this, isStart);
  }
}
