baseConnectNotification function
Implementation
Future baseConnectNotification({BuildContext? context, String? ntfUrl}) async {
try {
var permission = await getPermissionNotificationWithoutCtx(
context: context,
);
List<String> allowedRoutes = [];
allowedRoutes = List.from(permission['allowed_routes']);
allowedRoutes.add(':private');
var register = await registerForGetTokenWithoutCtx(
context: context, formValue: permission);
final SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('notify_token', register['token']);
await subscribeBatch(context: context);
await unStash(context: context);
var myStream = Sse.connect(
uri: Uri.parse('${ntfUrl}sse?token=${prefs.getString('notify_token')}'),
types: allowedRoutes,
closeOnError: true,
withCredentials: false,
reConnect: () {
baseConnectNotification(context: context);
}).stream;
myStream.listen((event) {
// print('Received:' + DateTime.now().millisecondsSinceEpoch.toString() + ' : ' + event.toString());
_showNotification(title: event.toString(), body: '');
});
} catch (e) {
print('eBaseConnectNotification ===> $e');
} finally {}
}