Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
1.2 kB
1
Indexable
Never
  void initializedSignalR() {
    final AuthenticationManager authManager = Get.find();
    authManager.signalR = SignalR(BASE_URL, 'notificationHub',
        hubMethods: ['broadcastNotification'],
        queryString:
            'token=${authManager.getToken()}&${authManager.appUser.value.id}',
        statusChangeCallback: (status) {}, hubCallback: (methodName, message) {
      if (authManager.isLogged.value &&
          authManager.appUser.value.phoneNumberConfirmed == true &&
          authManager.appUser.value.userCategory != GUEST_USER_CATEGORY) {
        authManager.api.getNotificationsCount();

        if (message['MessageType'] == 5.0) {
          final DashboardController dashboardController = Get.find();

          dashboardController.fetchNewChats();

          if ((dashboardController.currentPage.value != 3) &&
              !(Get.currentRoute.contains(message['TransId']))) {
            print('ok');
            dashboardController.unReadChat.value =
                UnReadChat(chatId: message['TransId']);
          }
        }
      }
    });
    authManager.signalR.isConnected.then((value) {
      if (value == true) {
        authManager.signalR.stop();
      }
    });
  }