diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 9d6e575..b05708b 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -104,7 +104,6 @@ class ApiConsts { static String adsPhotoOfficeAppointmentCreate = "${baseUrlServices}api/Advertisement/PhotoOfficeAppointment_Create"; static String adsMCBankAccountAdGet = "${baseUrlServices}api/Advertisement/MCBankAccountAd_Get"; - //Subscription static String getAllSubscriptions = "${baseUrlServices}api/Common/Subscription_Get"; @@ -134,6 +133,9 @@ class ApiConsts { static String getRequest = "${baseUrlServices}api/RequestManagement/Request_Get"; static String getRequestOffers = "${baseUrlServices}api/RequestManagement/ReqOffer_Get"; + //Chat + static String chatHubUrl = "$baseUrlServices/McHub"; + static List closingUrls = ["PayFortResponse"]; } diff --git a/lib/config/dependencies.dart b/lib/config/dependencies.dart index 846c2e0..2d7b1f8 100644 --- a/lib/config/dependencies.dart +++ b/lib/config/dependencies.dart @@ -6,6 +6,7 @@ import 'package:mc_common_app/api/api_client.dart'; import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/repositories/ads_repo.dart'; import 'package:mc_common_app/repositories/appointment_repo.dart'; +import 'package:mc_common_app/repositories/chat_repo.dart'; import 'package:mc_common_app/repositories/common_repo.dart'; import 'package:mc_common_app/repositories/payments_repo.dart'; import 'package:mc_common_app/repositories/provider_repo.dart'; @@ -33,5 +34,6 @@ class AppDependencies { injector.registerSingleton(() => RequestRepoImp()); injector.registerSingleton(() => ProviderRepoImp()); injector.registerSingleton(() => AppointmentRepoImp()); + injector.registerSingleton(() => ChatRepoImp()); } } diff --git a/lib/repositories/chat_repo.dart b/lib/repositories/chat_repo.dart new file mode 100644 index 0000000..2f379cb --- /dev/null +++ b/lib/repositories/chat_repo.dart @@ -0,0 +1,60 @@ +import 'package:mc_common_app/classes/app_state.dart'; +import 'package:mc_common_app/classes/consts.dart'; +import 'package:mc_common_app/main.dart'; +import 'package:mc_common_app/utils/utils.dart'; +import 'package:signalr_netcore/http_connection_options.dart'; +import 'package:signalr_netcore/hub_connection.dart'; +import 'package:signalr_netcore/hub_connection_builder.dart'; +import 'package:logging/logging.dart'; + +abstract class ChatRepo { + Future buildChatHubConnection(); +} + +class ChatRepoImp implements ChatRepo { + @override + Future buildChatHubConnection() async { + final userId = AppState().getUser.data!.userInfo!.userId ?? ""; + HttpConnectionOptions httpOptions = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); + HubConnection hubConnection = HubConnectionBuilder() + .withUrl( + "${ApiConsts.chatHubUrl}?userID=$userId", + options: httpOptions, + ) + .withAutomaticReconnect( + retryDelays: [2000, 5000, 10000, 20000], + ) + .configureLogging( + Logger("configureLogging"), + ) + .build(); + hubConnection.onclose( + ({Exception? error}) { + logger.i("onClose"); + }, + ); + hubConnection.onreconnecting( + ({Exception? error}) { + logger.i("onReconnecting"); + }, + ); + hubConnection.onreconnected( + ({String? connectionId}) { + logger.i("onReconnected"); + }, + ); + if (hubConnection.state != HubConnectionState.Connected) { + await hubConnection.start(); + logger.i("Started HubConnection"); + + try { + hubConnection.on("ReceiveMessageRequestOffer", (List? arguments) { + Utils.showToast("I received ping : ${arguments.toString()}"); + }); + } catch (e) { + logger.i("Error in OnSendQuestionToParticipant"); + } + } + return hubConnection; + } +} diff --git a/lib/view_models/chat_view_model.dart b/lib/view_models/chat_view_model.dart new file mode 100644 index 0000000..5d0c70a --- /dev/null +++ b/lib/view_models/chat_view_model.dart @@ -0,0 +1,39 @@ +import 'package:flutter/cupertino.dart'; +import 'package:mc_common_app/repositories/chat_repo.dart'; +import 'package:mc_common_app/utils/utils.dart'; +import 'package:signalr_netcore/hub_connection.dart'; + + class ChatVM extends ChangeNotifier { + final ChatRepo chatRepo; + + ChatVM({required this.chatRepo}); + + HubConnection? hubConnection; + + Future buildHubConnection() async { + hubConnection = await chatRepo.buildChatHubConnection(); + notifyListeners(); + } + + Future onSendMessageForRequestOffer() async { + if (hubConnection == null || hubConnection!.state != HubConnectionState.Connected) { + await buildHubConnection(); + } + if (hubConnection != null) { + hubConnection!.invoke( + "SendMessageRequestOffer", + args: [ + // { + // "employeeNumber": AppState().memberInformationList!.eMPLOYEENUMBER ?? "", + // "employeeName": AppState().memberInformationList!.eMPLOYEENAME ?? "", + // "marathonId": AppState().getMarathonProjectId, + // "prizeId": "8577B2E8-5DD7-43F0-10DD-08DACB0AC064", + // } + ], + ).catchError((e) { + Utils.showToast(e.toString()); + return null; + }); + } + } +} diff --git a/pubspec.lock b/pubspec.lock index e131506..09c3a03 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -589,6 +589,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.0" + logging: + dependency: "direct main" + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" matcher: dependency: transitive description: @@ -605,6 +613,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.0" + message_pack_dart: + dependency: transitive + description: + name: message_pack_dart + sha256: "71b9f0ff60e5896e60b337960bb535380d7dba3297b457ac763ccae807385b59" + url: "https://pub.dev" + source: hosted + version: "2.0.1" meta: dependency: transitive description: @@ -773,6 +789,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.6" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" provider: dependency: "direct main" description: @@ -853,6 +877,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.1" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" shimmer: dependency: "direct main" description: @@ -861,6 +893,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + signalr_netcore: + dependency: "direct main" + description: + name: signalr_netcore + sha256: "8f84b4b516c03f3a6872f94e9729d1441d5d223a77c81d0a7d7dae5dd0ce1f2f" + url: "https://pub.dev" + source: hosted + version: "1.3.6" simple_gesture_detector: dependency: transitive description: @@ -890,14 +930,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.9.1" - sprintf: - dependency: transitive - description: - name: sprintf - sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" - url: "https://pub.dev" - source: hosted - version: "7.0.0" sqflite: dependency: transitive description: @@ -914,6 +946,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.5.0" + sse: + dependency: transitive + description: + name: sse + sha256: "3ff9088cac3f45aa8b91336f1962e3ea6c81baaba0bbba361c05f8aa7fb59442" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + sse_channel: + dependency: transitive + description: + name: sse_channel + sha256: ba2b1382b9423c58fa83e1f01a3a40fbaa16a0594aa984870c88bad0b45d4ca4 + url: "https://pub.dev" + source: hosted + version: "0.0.3" stack_trace: dependency: transitive description: @@ -978,6 +1026,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.1" + tuple: + dependency: transitive + description: + name: tuple + sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151 + url: "https://pub.dev" + source: hosted + version: "2.0.2" typed_data: dependency: transitive description: @@ -1062,10 +1118,10 @@ packages: dependency: transitive description: name: uuid - sha256: e03928880bdbcbf496fb415573f5ab7b1ea99b9b04f669c01104d085893c3134 + sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "3.0.7" vector_math: dependency: transitive description: @@ -1074,6 +1130,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + url: "https://pub.dev" + source: hosted + version: "2.4.0" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 2ffccc7..d19a6e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,6 +39,8 @@ dependencies: country_code_picker: ^3.0.0 table_calendar: ^3.0.9 intl: any + signalr_netcore: ^1.3.6 + logging: ^1.2.0 # google