From 50bb10e6102f3d017c13bb6268be7f1c90733100 Mon Sep 17 00:00:00 2001 From: delanierlucas Date: Fri, 18 Nov 2022 23:35:57 +0100 Subject: [PATCH] chat with socket.io on a js server --- .idea/libraries/Dart_Packages.xml | 692 ------------------ .idea/libraries/Dart_SDK.xml | 38 +- Sources/dafl_project_flutter/ios/Podfile.lock | 73 -- .../ios/Runner.xcodeproj/project.pbxproj | 78 +- .../lib/controller/controller.dart | 23 + .../lib/views/pages/main/p_conversation.dart | 5 +- .../lib/views/pages/main/p_main.dart | 8 +- Sources/dafl_project_flutter/pubspec.lock | 14 + Sources/dafl_project_flutter/pubspec.yaml | 1 + 9 files changed, 105 insertions(+), 827 deletions(-) delete mode 100644 .idea/libraries/Dart_Packages.xml delete mode 100644 Sources/dafl_project_flutter/ios/Podfile.lock diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml deleted file mode 100644 index c2384f5..0000000 --- a/.idea/libraries/Dart_Packages.xml +++ /dev/null @@ -1,692 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index 6ae284f..b6e6985 100644 --- a/.idea/libraries/Dart_SDK.xml +++ b/.idea/libraries/Dart_SDK.xml @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/Sources/dafl_project_flutter/ios/Podfile.lock b/Sources/dafl_project_flutter/ios/Podfile.lock deleted file mode 100644 index e18955c..0000000 --- a/Sources/dafl_project_flutter/ios/Podfile.lock +++ /dev/null @@ -1,73 +0,0 @@ -PODS: - - Flutter (1.0.0) - - flutter_inappwebview (0.0.1): - - Flutter - - flutter_inappwebview/Core (= 0.0.1) - - OrderedSet (~> 5.0) - - flutter_inappwebview/Core (0.0.1): - - Flutter - - OrderedSet (~> 5.0) - - flutter_native_splash (0.0.1): - - Flutter - - fluttertoast (0.0.2): - - Flutter - - Toast - - geolocator_apple (1.2.0): - - Flutter - - home_indicator (0.0.1): - - Flutter - - OrderedSet (5.0.0) - - path_provider_ios (0.0.1): - - Flutter - - Toast (4.0.0) - - vibration (1.7.5): - - Flutter - -DEPENDENCIES: - - Flutter (from `Flutter`) - - flutter_inappwebview (from `.symlinks/plugins/flutter_inappwebview/ios`) - - flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`) - - fluttertoast (from `.symlinks/plugins/fluttertoast/ios`) - - geolocator_apple (from `.symlinks/plugins/geolocator_apple/ios`) - - home_indicator (from `.symlinks/plugins/home_indicator/ios`) - - path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`) - - vibration (from `.symlinks/plugins/vibration/ios`) - -SPEC REPOS: - trunk: - - OrderedSet - - Toast - -EXTERNAL SOURCES: - Flutter: - :path: Flutter - flutter_inappwebview: - :path: ".symlinks/plugins/flutter_inappwebview/ios" - flutter_native_splash: - :path: ".symlinks/plugins/flutter_native_splash/ios" - fluttertoast: - :path: ".symlinks/plugins/fluttertoast/ios" - geolocator_apple: - :path: ".symlinks/plugins/geolocator_apple/ios" - home_indicator: - :path: ".symlinks/plugins/home_indicator/ios" - path_provider_ios: - :path: ".symlinks/plugins/path_provider_ios/ios" - vibration: - :path: ".symlinks/plugins/vibration/ios" - -SPEC CHECKSUMS: - Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 - flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721 - flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef - fluttertoast: 74526702fea2c060ea55dde75895b7e1bde1c86b - geolocator_apple: cc556e6844d508c95df1e87e3ea6fa4e58c50401 - home_indicator: 60c6a4b60d17173cd164c112eb9be37055b23af8 - OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c - path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02 - Toast: 91b396c56ee72a5790816f40d3a94dd357abc196 - vibration: 7d883d141656a1c1a6d8d238616b2042a51a1241 - -PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 - -COCOAPODS: 1.11.3 diff --git a/Sources/dafl_project_flutter/ios/Runner.xcodeproj/project.pbxproj b/Sources/dafl_project_flutter/ios/Runner.xcodeproj/project.pbxproj index 5651d52..080c127 100644 --- a/Sources/dafl_project_flutter/ios/Runner.xcodeproj/project.pbxproj +++ b/Sources/dafl_project_flutter/ios/Runner.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 56603186FD0491FFC157C451 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9F96A939E72163035AC6113 /* Pods_Runner.framework */; }; + 7123E589E36F2A19292958EB /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D2A87B24F967E02E3AD8C23 /* Pods_Runner.framework */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -30,13 +30,16 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 05FB6061F1FF29B3B9E4D028 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; + 0A23FC45634EB07CAB0988E0 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 275ABD2DE0015FE53EA67016 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7A594B0F7D8FF0743F35FBAA /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 7D2A87B24F967E02E3AD8C23 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -44,9 +47,6 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - AA4D0BF17C9CFE7BC6080122 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; - D9F96A939E72163035AC6113 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - DF9436B870BC50F36A3F1BC8 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,7 +54,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 56603186FD0491FFC157C451 /* Pods_Runner.framework in Frameworks */, + 7123E589E36F2A19292958EB /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -78,8 +78,8 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, - C12164027BBF046CA7CA1CE9 /* Pods */, - D041563FF6043A51C062CD22 /* Frameworks */, + B7E0DB4BE4F23040C6127914 /* Pods */, + D1F3815DE0E6B5B41D0FE2D8 /* Frameworks */, ); sourceTree = ""; }; @@ -106,21 +106,21 @@ path = Runner; sourceTree = ""; }; - C12164027BBF046CA7CA1CE9 /* Pods */ = { + B7E0DB4BE4F23040C6127914 /* Pods */ = { isa = PBXGroup; children = ( - AA4D0BF17C9CFE7BC6080122 /* Pods-Runner.debug.xcconfig */, - DF9436B870BC50F36A3F1BC8 /* Pods-Runner.release.xcconfig */, - 05FB6061F1FF29B3B9E4D028 /* Pods-Runner.profile.xcconfig */, + 7A594B0F7D8FF0743F35FBAA /* Pods-Runner.debug.xcconfig */, + 0A23FC45634EB07CAB0988E0 /* Pods-Runner.release.xcconfig */, + 275ABD2DE0015FE53EA67016 /* Pods-Runner.profile.xcconfig */, ); name = Pods; path = Pods; sourceTree = ""; }; - D041563FF6043A51C062CD22 /* Frameworks */ = { + D1F3815DE0E6B5B41D0FE2D8 /* Frameworks */ = { isa = PBXGroup; children = ( - D9F96A939E72163035AC6113 /* Pods_Runner.framework */, + 7D2A87B24F967E02E3AD8C23 /* Pods_Runner.framework */, ); name = Frameworks; sourceTree = ""; @@ -132,14 +132,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - 0CDF21A3B58AC238E2266285 /* [CP] Check Pods Manifest.lock */, + F244868EE2BE1C55CDAEA7FA /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - 9E2222998A7DFB19CABF432B /* [CP] Embed Pods Frameworks */, + C8941F7290B9FCCA72A5780E /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -198,28 +198,6 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 0CDF21A3B58AC238E2266285 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -248,7 +226,7 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; - 9E2222998A7DFB19CABF432B /* [CP] Embed Pods Frameworks */ = { + C8941F7290B9FCCA72A5780E /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -265,6 +243,28 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; + F244868EE2BE1C55CDAEA7FA /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/Sources/dafl_project_flutter/lib/controller/controller.dart b/Sources/dafl_project_flutter/lib/controller/controller.dart index e08e080..740e05c 100644 --- a/Sources/dafl_project_flutter/lib/controller/controller.dart +++ b/Sources/dafl_project_flutter/lib/controller/controller.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'package:dafl_project_flutter/main.dart'; import 'package:http/http.dart' as http; import '../persistence/database_loader.dart'; import '../persistence/database_saver.dart'; @@ -7,6 +8,7 @@ import '../persistence/loader.dart'; import '../persistence/saver.dart'; import '../model/user.dart'; import '../persistence/searcher.dart'; +import 'package:socket_io_client/socket_io_client.dart' as IO; class Controller { static Saver saver = DatabaseSaver(); @@ -15,6 +17,26 @@ class Controller { late User currentUser; + late IO.Socket _socket; + + void _connectChat() { + _socket = IO.io( + "http://localhost:3000", + IO.OptionBuilder().setTransports(['websocket']).setQuery( + {'username': MyApp.controller.currentUser}).build()); + _socket.onConnect((data) => print('Connection established')); + _socket.onConnectError((data) => print('Connect Error: $data')); + _socket.onDisconnect((data) => print('Socket.io server disconnected')); + _socket.on('message', (data) => print(data)); + } + + sendMessage(String message, User destinataire) { + _socket.emit('message', { + 'message': message.trim(), + 'sender': destinataire.usernameDafl, + }); + } + Controller() { currentUser = User('', ''); //TODO : remove this line } @@ -25,6 +47,7 @@ class Controller { load(String username, String password) async { _changeCurrentUser(await loader.load(username, password)); + _connectChat(); } _changeCurrentUser(User user) { diff --git a/Sources/dafl_project_flutter/lib/views/pages/main/p_conversation.dart b/Sources/dafl_project_flutter/lib/views/pages/main/p_conversation.dart index 6667407..b8b15f1 100644 --- a/Sources/dafl_project_flutter/lib/views/pages/main/p_conversation.dart +++ b/Sources/dafl_project_flutter/lib/views/pages/main/p_conversation.dart @@ -18,11 +18,12 @@ class _ConversationPageState extends State { final messageTextField = TextEditingController(); - void sendMessage(String content) { + void sendMessage(String content, User destinataire) { setState(() { messages .add(messageWidget(Message(MyApp.controller.currentUser, content))); }); + MyApp.controller.sendMessage(content, destinataire); } Widget messageWidget(Message message) { @@ -218,7 +219,7 @@ class _ConversationPageState extends State { onTap: isNull ? null : () { - sendMessage(messageTextField.text); + sendMessage(messageTextField.text, destinataire); if (listScrollController.hasClients) { final position = listScrollController.position.maxScrollExtent; diff --git a/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart b/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart index 326e293..543d8f0 100644 --- a/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart +++ b/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart @@ -7,8 +7,7 @@ import './w_discovery.dart'; import './w_profile.dart'; import './w_messages.dart'; import 'w_top.dart'; - - +import 'package:socket_io_client/socket_io_client.dart' as IO; class MainPage extends StatefulWidget { const MainPage({Key? key}) : super(key: key); @@ -30,6 +29,11 @@ class _MainPageState extends State { const SettingsWidget(), ]; + @override + void initState() { + super.initState(); + } + @override Widget build(BuildContext context) { MyApp.controller.currentUser.getListSpots(); diff --git a/Sources/dafl_project_flutter/pubspec.lock b/Sources/dafl_project_flutter/pubspec.lock index 0662299..b9b0020 100644 --- a/Sources/dafl_project_flutter/pubspec.lock +++ b/Sources/dafl_project_flutter/pubspec.lock @@ -488,6 +488,20 @@ packages: description: flutter source: sdk version: "0.0.99" + socket_io_client: + dependency: "direct main" + description: + name: socket_io_client + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + socket_io_common: + dependency: transitive + description: + name: socket_io_common + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" source_span: dependency: transitive description: diff --git a/Sources/dafl_project_flutter/pubspec.yaml b/Sources/dafl_project_flutter/pubspec.yaml index 96ede70..3c9285d 100644 --- a/Sources/dafl_project_flutter/pubspec.yaml +++ b/Sources/dafl_project_flutter/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: home_indicator: ^2.0.2 geolocator: ^9.0.2 flutter_styled_toast: ^2.1.3 + socket_io_client: ^2.0.0 dev_dependencies: flutter_test: