initializeV2Ray method

  1. @override
Future<void> initializeV2Ray({
  1. required void onStatusChanged(
    1. V2RayStatus status
    ),
  2. required String notificationIconResourceType,
  3. required String notificationIconResourceName,
})
override

Initializes the V2Ray client with a status change callback and notification settings. onStatusChanged is a callback that will be invoked when the V2Ray status changes. notificationIconResourceType specifies the type of the notification icon resource (e.g., 'mipmap'). notificationIconResourceName specifies the name of the notification icon resource (e.g., 'ic_launcher'). Returns a Future that completes when initialization is done.

Implementation

@override
Future<void> initializeV2Ray({
  required void Function(V2RayStatus status) onStatusChanged,
  required String notificationIconResourceType,
  required String notificationIconResourceName,
}) async {
  eventChannel.receiveBroadcastStream().distinct().cast().listen((event) {
    if (event != null) {
      onStatusChanged.call(V2RayStatus(
        duration: event[0],
        uploadSpeed: int.parse(event[1]),
        downloadSpeed: int.parse(event[2]),
        upload: int.parse(event[3]),
        download: int.parse(event[4]),
        state: event[5],
      ));
    }
  });
  await methodChannel.invokeMethod(
    'initializeV2Ray',
    {
      'notificationIconResourceType': notificationIconResourceType,
      'notificationIconResourceName': notificationIconResourceName,
    },
  );
}