HeadlessService constructor

HeadlessService({
  1. String backendUrl = 'https://api.novu.co',
  2. String socketUrl = 'https://ws.novu.co',
  3. required String applicationIdentifier,
  4. String? subscriberId,
  5. String? subscriberHash,
  6. int? retry,
  7. int retryDelay = 10000,
  8. dynamic onUnreadChanged(
    1. int
    )?,
  9. dynamic onUnseenChanged(
    1. int
    )?,
  10. dynamic onReceived(
    1. Notification
    )?,
  11. List<InboxTab> tabs = const [],
})

Implementation

HeadlessService({
  this.backendUrl = 'https://api.novu.co',
  this.socketUrl = 'https://ws.novu.co',
  required this.applicationIdentifier,
  this.subscriberId,
  this.subscriberHash,
  this.retry,
  this.retryDelay = 10000,
  this.onUnreadChanged,
  this.onUnseenChanged,
  this.onReceived,
  this.tabs = const [],
}) {
  var api = BaseApi(backendUrl);
  api.request(method: ApiMethod.POST, endpoint: 'inbox/session', data: {'applicationIdentifier': applicationIdentifier, 'subscriberId': subscriberId}).then((response) {
    var value = response['data'];
    prefs.setString('novu_token', value['token']);
    initializeSocket(value['token']);
    _token = value['token'];

    _client = Dio();
    _client.options.baseUrl = '$backendUrl/v1/inbox/';
    if (_token != null) {
      _client.options.headers['Authorization'] = 'Bearer $_token';
    }

    if (onUnreadChanged != null) {
      countNotifications(read: false).then((value) => onUnreadChanged!(value));
    }
  });
  // _socket = WebSocketChannel.connect(Uri.parse(socketUrl));
}