chivox_aiengine_method_channel.dart 2.97 KB
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'chivox_aiengine_platform_interface.dart';

/// An implementation of [ChivoxAienginePlatform] that uses method channels.
class MethodChannelChivoxAiengine extends ChivoxAienginePlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('com.chivox.aiengine/call');

  @override
  Future<String?> getPlatformVersion() async {
    final version =
        await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<String?> aiengineNew(String cfg) async {
    final engineId =
        await methodChannel.invokeMethod<String>('aiengineNew', [cfg]);
    return engineId;
  }

  @override
  Future<void> aiengineDelete(String engineId) async {
    await methodChannel.invokeMethod<void>('aiengineDelete', [engineId]);
    return;
  }

  @override
  Future<void> aiengineStart(String engineId, Map<String, dynamic> audioSrc,
      String param, String callbackId) async {
    await methodChannel.invokeMethod<String>(
        'aiengineStart', [engineId, audioSrc, param, callbackId]);
    return;
  }

  @override
  Future<void> aiengineFeed(
      String engineId, Uint8List bytes, int length) async {
    await methodChannel
        .invokeMethod<void>('aiengineFeed', [engineId, bytes, length]);
    return;
  }

  @override
  Future<void> aiengineStop(String engineId) async {
    await methodChannel.invokeMethod<void>('aiengineStop', [engineId]);
    return;
  }

  @override
  Future<void> aiengineCancel(String engineId) async {
    await methodChannel.invokeMethod<void>('aiengineCancel', [engineId]);
    return;
  }

  @override
  Future<String?> getDeviceId() async {
    final devId = await methodChannel.invokeMethod<String>(
      'getDeviceId',
    );
    return devId;
  }

  @override
  Future<String?> getSerialNumber(String? engineId, Map input) async {
    final output = await methodChannel
        .invokeMethod<String>('getSerialNumber', [engineId, input]);
    return output;
  }

  @override
  Future<bool?> clearSavedSerialNumber(String appKey) async {
    final ret = await methodChannel
        .invokeMethod<bool>('clearSavedSerialNumber', [appKey]);
    return ret;
  }

  @override
  Future<String?> getProvision(String? engineId, Map input) async {
    final output = await methodChannel
        .invokeMethod<String>('getProvision', [engineId, input]);
    return output;
  }

  @override
  Future<void> extractRes(String assetPrefix, List<String> assetNames,
      String targetDir, String callbackId) async {
    await methodChannel.invokeMethod<void>(
        'extractRes', [assetPrefix, assetNames, targetDir, callbackId]);
    return;
  }

  @override
  Future<String?> loadNativeCfg(
      String resRootDir, List<String> resNames) async {
    final cfgStr = await methodChannel
        .invokeMethod<String?>('loadNativeCfg', [resRootDir, resNames]);
    return cfgStr;
  }
}