init method

void init(
  1. MethodCall call
)

Implementation

void init(MethodCall call) {
  if (pusher != null) {
    pusher!.unbind_all();
    pusher!.disconnect();
  }
  var options = Options();
  if (call.arguments['cluster'] != null) {
    options.cluster = call.arguments['cluster'];
  }
  if (call.arguments['forceTLS'] != null) {
    options.forceTLS = call.arguments['forceTLS'];
  }
  if (call.arguments['pongTimeout'] != null) {
    options.pongTimeout = call.arguments['pongTimeout'];
  }
  if (call.arguments['enableStats'] != null) {
    options.enableStats = call.arguments['enableStats'];
  }
  if (call.arguments['disabledTransports'] != null) {
    options.disabledTransports = call.arguments['disabledTransports'];
  }
  if (call.arguments['enabledTransports'] != null) {
    options.enabledTransports = call.arguments['enabledTransports'];
  }
  if (call.arguments['ignoreNullOrigin'] != null) {
    options.ignoreNullOrigin = call.arguments['ignoreNullOrigin'];
  }
  if (call.arguments['authTransport'] != null) {
    options.authTransport = call.arguments['authTransport'];
  }
  if (call.arguments['authEndpoint'] != null) {
    options.authEndpoint = call.arguments['authEndpoint'];
  }
  if (call.arguments['authParams'] != null) {
    options.auth = call.arguments['authParams'];
  }
  if (call.arguments['logToConsole'] != null) {
    Pusher.logToConsole = call.arguments['logToConsole'];
  }
  if (call.arguments['authorizer'] != null) {
    options.authorizer = allowInterop(onAuthorizer);
  }
  pusher = Pusher(call.arguments['apiKey'], options);
  pusher!.connection.bind('error', allowInterop(onError));
  pusher!.connection.bind('message', allowInterop(onMessage));
  pusher!.connection.bind('state_change', allowInterop(onStateChange));
  pusher!.connection.bind('connected', allowInterop(onConnected));
  pusher!.connection.bind('disconnected', allowInterop(onDisconnected));
}