init method

void init({
  1. dynamic onEvent(
    1. PusherEvent
    )?,
  2. dynamic onConnectionStateChange(
    1. String,
    2. String
    )?,
  3. dynamic onError(
    1. String,
    2. int?,
    3. dynamic
    )?,
  4. dynamic onSubscriptionSucceeded(
    1. String,
    2. dynamic
    )?,
  5. dynamic onSubscriptionError(
    1. String,
    2. dynamic
    )?,
  6. dynamic onDecryptionFailure(
    1. String,
    2. String
    )?,
  7. dynamic onMemberAdded(
    1. String,
    2. PusherMember
    )?,
  8. dynamic onMemberRemoved(
    1. String,
    2. PusherMember
    )?,
  9. String channelName = "",
  10. String apiKey = "",
})

Implementation

void init(
    {Function(PusherEvent)? onEvent,
      Function(String, String)? onConnectionStateChange,
      Function(String, int?, dynamic)? onError,
      Function(String, dynamic)? onSubscriptionSucceeded,
      Function(String, dynamic)? onSubscriptionError,
      Function(String, String)? onDecryptionFailure,
      Function(String, PusherMember)? onMemberAdded,
      Function(String, PusherMember)? onMemberRemoved,
      String channelName = "" ,
      String apiKey = "" ,
    }) async {

  if(channelName == "" ){
    throw Exception('Error : channelName needed ');
  }

  if(apiKey == "" ){
    throw Exception('Error : apiKey needed ');
  }
  final token = AltibbiService.authToken;
  final baseURL = AltibbiService.url;
  try {
    await pusher.init(
        apiKey: apiKey,
        cluster: "eu",
        onEvent: onEvent,
        onConnectionStateChange: onConnectionStateChange,
        onError: onError,
        onSubscriptionSucceeded: onSubscriptionSucceeded,
        onSubscriptionError: onSubscriptionError,
        onDecryptionFailure: onDecryptionFailure,
        onMemberAdded: onMemberAdded,
        onMemberRemoved: onMemberRemoved,
        authEndpoint: "$baseURL/v1/auth/pusher?access-token=$token");
    await pusher.subscribe(channelName: channelName);
    await pusher.connect();
  } catch (e) {
    throw Exception('ERROR 12: $e');
  }
}