@ -33,6 +33,7 @@ class AppProvider extends ChangeNotifier {
listenNetworkConnectivity ( ) ;
listenAudioPlayerEvents ( ) ;
getTheWidgetsConfigurationsEveryMidnight ( ) ;
/ / await callPatientsAPI ( ) ;
}
SignalRHelper signalRHelper = SignalRHelper ( ) ;
@ -163,7 +164,8 @@ class AppProvider extends ChangeNotifier {
RssFeedModel currentRssFeedModel = RssFeedModel ( ) ;
Future < void > getRssFeedDetailsFromServer ( ) async {
RssFeedModel ? rssFeedModel = await API . getRssFeedDetailsFromServer ( languageId: 0 , onFailure: ( error ) = > log ( " Api call failed with this error: ${ error . toString ( ) } " ) ) ;
RssFeedModel ? rssFeedModel =
await API . getRssFeedDetailsFromServer ( languageId: 0 , onFailure: ( error ) = > log ( " Api call failed with this error: ${ error . toString ( ) } " ) ) ;
if ( rssFeedModel ! = null ) {
currentRssFeedModel = rssFeedModel ;
@ -180,7 +182,7 @@ class AppProvider extends ChangeNotifier {
await getWeatherDetailsFromServer ( ) ;
}
if ( currentWidgetsConfigModel ! . isPrayerTimeReq ! ) {
/ / await getPrayerDetailsFromServer ( ) ;
await getPrayerDetailsFromServer ( ) ;
}
if ( currentWidgetsConfigModel ! . isRssFeedReq ! ) {
await getRssFeedDetailsFromServer ( ) ;
@ -250,6 +252,7 @@ class AppProvider extends ChangeNotifier {
}
Future < void > callPatientsAPI ( ) async {
log ( " calling callPatientsAPI " ) ;
patientTickets . clear ( ) ;
API . getCallRequestInfoByClinicInfo ( currentDeviceIp ,
onSuccess: ( waitingCalls , isQueuePatientsCalls , callConfigs ) async {
@ -259,11 +262,15 @@ class AppProvider extends ChangeNotifier {
} else {
patientTickets = waitingCalls ;
}
isQueuePatients = isQueuePatientsCalls ;
if ( isQueuePatientsCalls . length > patientCallConfigurations . screenMaxDisplayPatients ) {
isQueuePatients = isQueuePatientsCalls . sublist ( 0 , patientCallConfigurations . screenMaxDisplayPatients ) ;
} else {
isQueuePatients = isQueuePatientsCalls ;
}
notifyListeners ( ) ;
if ( patientTickets . isNotEmpty ) {
updateCurrentScreenRotation ( patientTickets . first . screenRotationEnum ) ;
voiceCallPatientTicket ( patientTickets . first ) ;
voiceCallPatientTicket ( patientTickets . first , " callPatientsAPI " );
updatePatientTicket ( patientTickets . first ) ;
}
} ,
@ -271,7 +278,8 @@ class AppProvider extends ChangeNotifier {
}
onPingReceived ( data ) async {
log ( " isCallingInProgress: $ isCallingInProgress " ) ;
log ( " A new Ping Received " ) ;
log ( " isCallingInProgress from onPingReceived: $ isCallingInProgress " ) ;
log ( " isApiCallNeeded: $ isApiCallNeeded " ) ;
if ( patientTickets . isNotEmpty ) {
if ( isCallingInProgress ) {
@ -316,15 +324,22 @@ class AppProvider extends ChangeNotifier {
/ / await voiceCaller ! . startCalling ( true ) ;
/ / }
voiceCallPatientTicket ( PatientTicketModel patientTicket ) async {
voiceCallPatientTicket ( PatientTicketModel patientTicket , String calledFrom ) async {
log ( " voiceCallPatientTicket calledFrom : $ calledFrom " ) ;
currentPatient = patientTicket ;
isCallingInProgress = true ;
log ( " Setting isCallingInProgress : $ isCallingInProgress " ) ;
log ( " isVoiceReq: ${ patientTicket . isVoiceReq } " ) ;
log ( " voiceCaller: ${ voiceCaller = = null } " ) ;
log ( " isQueue: ${ patientTicket . isQueue } " ) ;
log ( " isToneReq: ${ patientTicket . isToneReq } " ) ;
if ( patientTicket . isToneReq & & ! patientTicket . isQueue ) {
audioPlayer . setAsset ( " assets/tones/call_tone.mp3 " ) ;
await audioPlayer . play ( ) ;
await Future . delayed ( const Duration ( seconds: 3 ) ) ;
Future . delayed ( const Duration ( seconds: 3 ) ) ;
}
if ( patientTicket . isVoiceReq & & voiceCaller = = null & & ! patientTicket . isQueue ) {
@ -337,13 +352,16 @@ class AppProvider extends ChangeNotifier {
lang: patientTicket . voiceLanguage = = 1 ? " en " : " ar " ,
flutterTts: flutterTts ,
) ;
await voiceCaller ! . startCalling ( patientTicket . queueNo . trim ( ) . toString ( ) ! = patientTicket . callNoStr . trim ( ) . toString ( ) ) ;
voiceCaller = null ;
if ( isQueuePatients . isNotEmpty ) {
isQueuePatients . removeAt ( 0 ) ;
}
voiceCaller ! . startCalling ( patientTicket . queueNo . trim ( ) . toString ( ) ! = patientTicket . callNoStr . trim ( ) . toString ( ) ) . whenComplete ( ( ) {
voiceCaller = null ;
/ / if ( isQueuePatients . isNotEmpty ) {
/ / isQueuePatients . removeAt ( 0 ) ;
/ / }
} ) ;
} else {
isCallingInProgress = false ;
log ( " Setting isCallingInProgress : $ isCallingInProgress " ) ;
if ( isApiCallNeeded ) {
Timer ( Duration ( seconds: patientCallConfigurations . concurrentCallDelaySec ) , ( ) async {
await callPatientsAPI ( ) ;
@ -362,6 +380,7 @@ class AppProvider extends ChangeNotifier {
}
if ( isQueuePatients . isNotEmpty ) {
log ( " i am here on line 375 " ) ;
final length = isQueuePatients . length ;
for ( int i = 0 ; i < length ; i + + ) {
await Future . delayed ( Duration ( seconds: patientCallConfigurations . concurrentCallDelaySec ) ) . whenComplete ( ( ) async {
@ -374,12 +393,14 @@ class AppProvider extends ChangeNotifier {
isQueuePatients . removeAt ( 0 ) ;
patientTickets . add ( temp ) ;
notifyListeners ( ) ;
await voiceCallPatientTicket ( patientTickets . first );
await voiceCallPatientTicket ( patientTickets . first , " listenAudioPlayerEvents " );
updatePatientTicket ( patientTickets . first ) ;
} ) ;
}
}
isCallingInProgress = false ;
log ( " Setting isCallingInProgress : $ isCallingInProgress " ) ;
if ( isApiCallNeeded ) {
Timer ( Duration ( seconds: patientCallConfigurations . concurrentCallDelaySec ) , ( ) async {
await callPatientsAPI ( ) ;
@ -391,26 +412,33 @@ class AppProvider extends ChangeNotifier {
flutterTts . setCompletionHandler ( ( ) async {
log ( " My Value is in setCompletionHandler: $ isVoiceActualCompletedGlobally " ) ;
if ( ! isVoiceActualCompletedGlobally ) { }
log ( " isQueuePatients.length in setCompletionHandler: ${ isQueuePatients . length } " ) ;
if ( ! isVoiceActualCompletedGlobally ) {
return ;
}
if ( isQueuePatients . isNotEmpty ) {
final length = isQueuePatients . length ;
for ( int i = 0 ; i < length ; i + + ) {
await Future . delayed ( Duration ( seconds: patientCallConfigurations . concurrentCallDelaySec ) ) . whenComplete ( ( ) async {
PatientTicketModel temp = PatientTicketModel ( ) ;
if ( patientTickets . isNotEmpty ) {
temp = patientTickets . elementAt ( 0 ) ;
patientTickets . removeAt ( 0 ) ;
}
notifyListeners ( ) ;
/ / final length = isQueuePatients . length ;
/ / for ( int i = 0 ; i < length ; i + + ) {
await Future . delayed ( Duration ( seconds: patientCallConfigurations . concurrentCallDelaySec ) ) . whenComplete ( ( ) async {
PatientTicketModel temp = PatientTicketModel ( ) ;
if ( patientTickets . isNotEmpty ) {
temp = patientTickets . elementAt ( 0 ) ;
patientTickets . removeAt ( 0 ) ;
}
notifyListeners ( ) ;
if ( isQueuePatients . isNotEmpty ) {
isQueuePatients . removeAt ( 0 ) ;
patientTickets . add ( temp ) ;
notifyListeners ( ) ;
await voiceCallPatientTicket ( patientTickets . first ) ;
updatePatientTicket ( patientTickets . first ) ;
} ) ;
}
}
patientTickets . add ( temp ) ;
notifyListeners ( ) ;
await voiceCallPatientTicket ( patientTickets . first , " setCompletionHandler " ) ;
updatePatientTicket ( patientTickets . first ) ;
} ) ;
/ / }
}
isCallingInProgress = false ;
log ( " Setting isCallingInProgress : $ isCallingInProgress " ) ;
if ( isApiCallNeeded ) {
Timer ( Duration ( seconds: patientCallConfigurations . concurrentCallDelaySec ) , ( ) async {
await callPatientsAPI ( ) ;
@ -447,7 +475,8 @@ class AppProvider extends ChangeNotifier {
onDisconnect ( exception ) {
log ( " SignalR: onDisconnect " ) ;
signalRHelper . startSignalRConnection ( currentDeviceIp , onUpdateAvailable: onPingReceived , onConnect: onConnect , onConnecting: onConnecting , onDisconnect: onDisconnect ) ;
signalRHelper . startSignalRConnection ( currentDeviceIp ,
onUpdateAvailable: onPingReceived , onConnect: onConnect , onConnecting: onConnecting , onDisconnect: onDisconnect ) ;
}
onConnecting ( ) {