HeadlessService constructor
HeadlessService({
- String backendUrl = 'https://api.novu.co',
- String socketUrl = 'https://ws.novu.co',
- required String applicationIdentifier,
- String? subscriberId,
- String? subscriberHash,
- int? retry,
- int retryDelay = 10000,
- dynamic onUnreadChanged()?,
- dynamic onUnseenChanged()?,
- dynamic onReceived()?,
- 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));
}