├── .gitignore
├── .gitmodules
├── CHANGELOG.md
├── LICENSE
├── README.md
├── analysis_options.yaml
├── android
├── .gitignore
├── build.gradle
├── gradle.properties
├── settings.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── tvd12
│ └── ezyfoxserver
│ └── client
│ └── flutter
│ ├── EzyClientProxy.java
│ ├── EzyFlutterClientPlugin.java
│ ├── EzyMethodNames.java
│ ├── exception
│ └── EzyMethodCallException.java
│ ├── proxy
│ ├── EzyConnectMethod.java
│ ├── EzyCreateClientMethod.java
│ ├── EzyDisconnectMethod.java
│ ├── EzyGenerateKeyPairMethod.java
│ ├── EzyLogMethod.java
│ ├── EzyMethodProxy.java
│ ├── EzyReconnectMethod.java
│ ├── EzyRsaDecryptMethod.java
│ ├── EzySendMethod.java
│ ├── EzySetSessionKeyMethod.java
│ ├── EzySetStatusMethod.java
│ └── EzyStartPingScheduleMethod.java
│ └── serializer
│ ├── EzyClientConfigSerializer.java
│ ├── EzyEventSerializer.java
│ ├── EzyNativeDataDeserializer.java
│ ├── EzyNativeDataSerializer.java
│ └── EzyNativeSerializers.java
├── example
├── .gitignore
├── README.md
├── analysis_options.yaml
├── android
│ ├── .gitignore
│ ├── app
│ │ ├── build.gradle
│ │ └── src
│ │ │ ├── debug
│ │ │ └── AndroidManifest.xml
│ │ │ ├── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── tvd12
│ │ │ │ │ └── hello_flutter
│ │ │ │ │ └── MainActivity.java
│ │ │ └── res
│ │ │ │ ├── drawable-v21
│ │ │ │ └── launch_background.xml
│ │ │ │ ├── drawable
│ │ │ │ └── launch_background.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── values-night
│ │ │ │ └── styles.xml
│ │ │ │ └── values
│ │ │ │ └── styles.xml
│ │ │ └── profile
│ │ │ └── AndroidManifest.xml
│ ├── build.gradle
│ ├── gradle.properties
│ └── settings.gradle
├── images
│ └── flutter-sdk.png
├── ios
│ ├── .gitignore
│ ├── Flutter
│ │ ├── AppFrameworkInfo.plist
│ │ ├── Debug.xcconfig
│ │ └── Release.xcconfig
│ ├── Podfile
│ ├── Runner.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ ├── IDEWorkspaceChecks.plist
│ │ │ │ └── WorkspaceSettings.xcsettings
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── IDEWorkspaceChecks.plist
│ │ │ └── WorkspaceSettings.xcsettings
│ └── Runner
│ │ ├── AppDelegate.swift
│ │ ├── Assets.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ ├── Contents.json
│ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ ├── Icon-App-20x20@1x.png
│ │ │ ├── Icon-App-20x20@2x.png
│ │ │ ├── Icon-App-20x20@3x.png
│ │ │ ├── Icon-App-29x29@1x.png
│ │ │ ├── Icon-App-29x29@2x.png
│ │ │ ├── Icon-App-29x29@3x.png
│ │ │ ├── Icon-App-40x40@1x.png
│ │ │ ├── Icon-App-40x40@2x.png
│ │ │ ├── Icon-App-40x40@3x.png
│ │ │ ├── Icon-App-60x60@2x.png
│ │ │ ├── Icon-App-60x60@3x.png
│ │ │ ├── Icon-App-76x76@1x.png
│ │ │ ├── Icon-App-76x76@2x.png
│ │ │ └── Icon-App-83.5x83.5@2x.png
│ │ └── LaunchImage.imageset
│ │ │ ├── Contents.json
│ │ │ ├── LaunchImage.png
│ │ │ ├── LaunchImage@2x.png
│ │ │ ├── LaunchImage@3x.png
│ │ │ └── README.md
│ │ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ │ ├── Info.plist
│ │ ├── Runner-Bridging-Header.h
│ │ └── main.m
├── lib
│ ├── main.dart
│ └── socket_proxy.dart
└── pubspec.yaml
├── images
└── flutter-sdk.png
├── ios
├── .gitignore
├── Assets
│ └── .gitkeep
├── EzyClient
│ ├── EzyClientProxy.h
│ ├── EzyClientProxy.mm
│ ├── EzyFlutterClientPlugin.h
│ ├── EzyFlutterClientPlugin.m
│ ├── EzyMethodNames.h
│ ├── EzyMethodNames.mm
│ ├── Prefix.pch
│ ├── codec
│ │ ├── EzyEncryptionProxy.h
│ │ └── EzyEncryptionProxy.mm
│ ├── exception
│ │ ├── EzyMethodCallException.h
│ │ └── EzyMethodCallException.mm
│ ├── math
│ │ ├── EzyNSNumber.h
│ │ └── EzyNSNumber.m
│ ├── proxy
│ │ ├── EzyMethodProxy.h
│ │ └── EzyMethodProxy.mm
│ ├── serializer
│ │ ├── EzyClientConfigSerializer.h
│ │ ├── EzyClientConfigSerializer.mm
│ │ ├── EzyEventSerializer.h
│ │ ├── EzyEventSerializer.mm
│ │ ├── EzyNativeDataDeserializer.h
│ │ ├── EzyNativeDataDeserializer.mm
│ │ ├── EzyNativeDataSerializer.h
│ │ ├── EzyNativeDataSerializer.mm
│ │ ├── EzyNativeSerializers.h
│ │ └── EzyNativeSerializers.mm
│ └── util
│ │ ├── EzyNativeStrings.h
│ │ ├── EzyNativeStrings.mm
│ │ ├── NSByArray.m
│ │ └── NSByteArray.h
└── ezyfox_server_flutter_client.podspec
├── lib
├── ezy_client.dart
├── ezy_clients.dart
├── ezy_codec.dart
├── ezy_config.dart
├── ezy_constants.dart
├── ezy_entities.dart
├── ezy_handlers.dart
├── ezy_logger.dart
├── ezy_managers.dart
├── ezy_proxy.dart
├── ezy_setup.dart
└── ezy_util.dart
├── pubspec.yaml
└── test
└── ezyfox_server_flutter_client_test.dart
/.gitignore:
--------------------------------------------------------------------------------
1 | gradle/
2 | */gradle/
3 | **/gradle/
4 |
5 | .iml
6 | *.iml
7 |
8 | .lock
9 | *.lock
10 | .idea/
11 | */.idea/
12 | **/.idea/
13 | .metadata
14 | *.metadata
15 |
16 | .DS_Store
17 | .dart_tool/
18 |
19 | .packages
20 | .pub/
21 |
22 | build/
23 | */build/
24 | **/build/
25 | logs/
26 | */logs/
27 | **/logs/
28 | bin/
29 | */bin/
30 | **/bin/
31 | .project
32 | */.project
33 | **/.project
34 | .classpath
35 | */.classpath
36 | **/.classpath
37 | .settings/
38 | */.settings/
39 | **/.settings/
40 |
41 | obj/
42 | */obj/
43 | **/obj/
44 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "cpp-client-sdk"]
2 | path = ios/EzyClient/socket
3 | url = https://github.com/youngmonkeys/ezyfox-server-cpp-client.git
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 1.0.0
2 |
3 | * Send and receive message
4 | * SSL encryption
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ezyfox-server-flutter-client
2 |
3 | flutter client for [ezyfox server](https://github.com/youngmonkeys/ezyfox-server)
4 |
5 | # Architecture
6 |
7 |
8 |
9 | # Official documentation
10 |
11 | [https://youngmonkeys.org/ezyfox-flutter-client-sdk/](https://youngmonkeys.org/ezyfox-flutter-client-sdk/)
12 |
13 | # Prepare
14 |
15 | 1. Download and install [JDK 8](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html)
16 | 2. Download and install [Android Studio](https://developer.android.com/studio)
17 | 3. Download and install [Xcode](https://developer.apple.com/xcode)
18 | 4. Download and install [Intellij and Flutter plugin](https://www.jetbrains.com/idea/download)
19 | 5. Download and install [Flutter SDK](https://flutter.dev/docs/get-started/install)
20 |
21 | # How to test?
22 |
23 | ### 1. Clone source code
24 |
25 | ```
26 | git clone --recurse-submodules https://github.com/youngmonkeys/ezyfox-server-flutter-client.git ezyfox_server_flutter_client
27 | ```
28 |
29 | ### 2. Import source code
30 |
31 | You need import `ezyfox_server_flutter_client/example` to your IDEs
32 |
33 | - To IntelliJ IDE: for all
34 | - To Xcode: for iOS
35 | - To Android studio: for Android
36 |
37 | ### 3. You can run
38 |
39 | - [main.dart](https://github.com/youngmonkeys/ezyfox-server-flutter-client/blob/master/example/lib/main.dart) on Intellij
40 | - Build and Run on Xcode for iOS, don't for get run `pod install`
41 | - Build and run on Android Studio for Android
42 |
43 | ### 4. Where need I click?
44 |
45 | - Tap to plus button in bottom right corner
46 | - When you see `Greet Flutter's developer!`, congratulation, you've just run and connect to server successfully
47 |
48 | # Contact us
49 |
50 | - Touch us on [Facebook](https://www.facebook.com/youngmonkeys.org)
51 | - Ask us on [stackask.com](https://stackask.com)
52 | - Email to me [Dzung](mailto:itprono3@gmail.com)
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:flutter_lints/flutter.yaml
2 |
3 | # Additional information about this file can be found at
4 | # https://dart.dev/guides/language/analysis-options
5 |
--------------------------------------------------------------------------------
/android/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | import java.nio.file.Paths
2 |
3 | group 'com.tvd12'
4 | version '1.0'
5 |
6 | buildscript {
7 | repositories {
8 | google()
9 | mavenCentral()
10 | }
11 | }
12 |
13 | rootProject.allprojects {
14 | repositories {
15 | google()
16 | mavenCentral()
17 | }
18 | }
19 |
20 | apply plugin: 'com.android.library'
21 |
22 | android {
23 | compileSdkVersion 31
24 |
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 |
30 | defaultConfig {
31 | minSdkVersion 25
32 | }
33 | }
34 |
35 | def localProperties = new Properties()
36 | def localPropertiesFile = rootProject.file('local.properties')
37 | if (localPropertiesFile.exists()) {
38 | localPropertiesFile.withReader('UTF-8') { reader ->
39 | localProperties.load(reader)
40 | }
41 | }
42 |
43 | def flutterRoot = localProperties.getProperty('flutter.sdk')
44 | if (flutterRoot == null) {
45 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
46 | }
47 |
48 | String engineVersion = Paths
49 | .get(flutterRoot, "bin", "internal", "engine.version")
50 | .toFile()
51 | .text.trim()
52 |
53 | dependencies {
54 | implementation("com.tvd12:ezyfox-server-android-client:1.0.5")
55 | compileOnly("androidx.core:core:1.1.0")
56 | compileOnly("io.flutter:flutter_embedding_debug:1.0.0-$engineVersion")
57 | }
58 |
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'ezyfox_server_flutter_client'
2 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/EzyClientProxy.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter;
2 |
3 | import android.util.Log;
4 |
5 | import androidx.annotation.NonNull;
6 |
7 | import com.tvd12.ezyfoxserver.client.flutter.exception.EzyMethodCallException;
8 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzyConnectMethod;
9 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzyCreateClientMethod;
10 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzyDisconnectMethod;
11 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzyGenerateKeyPairMethod;
12 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzyLogMethod;
13 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzyMethodProxy;
14 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzyReconnectMethod;
15 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzyRsaDecryptMethod;
16 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzySendMethod;
17 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzySetSessionKeyMethod;
18 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzySetStatusMethod;
19 | import com.tvd12.ezyfoxserver.client.flutter.proxy.EzyStartPingScheduleMethod;
20 | import com.tvd12.ezyfoxserver.client.socket.EzyMainEventsLoop;
21 |
22 | import java.util.HashMap;
23 | import java.util.Map;
24 | import java.util.concurrent.atomic.AtomicBoolean;
25 |
26 | import io.flutter.plugin.common.BinaryMessenger;
27 | import io.flutter.plugin.common.MethodCall;
28 | import io.flutter.plugin.common.MethodChannel;
29 |
30 | public class EzyClientProxy {
31 |
32 | private MethodChannel methodChannel;
33 | private final AtomicBoolean registered;
34 | private final Map methods;
35 | private final EzyMainEventsLoop mainEventsLoop;
36 |
37 | public static final String CHANNEL = "com.tvd12.ezyfoxserver.client";
38 | private static final EzyClientProxy INSTANCE = new EzyClientProxy();
39 |
40 | private EzyClientProxy() {
41 | this.methods = new HashMap<>();
42 | this.registered = new AtomicBoolean(false);
43 | this.mainEventsLoop = new EzyMainEventsLoop();
44 | }
45 |
46 | public static EzyClientProxy getInstance() {
47 | return INSTANCE;
48 | }
49 |
50 | public void register(BinaryMessenger messenger) {
51 | if(registered.compareAndSet(false, true)) {
52 | doRegister(messenger);
53 | }
54 | }
55 |
56 | public void unregister() {
57 | if(methodChannel != null) {
58 | methodChannel.setMethodCallHandler(null);
59 | }
60 | }
61 |
62 | private void doRegister(BinaryMessenger messenger) {
63 | methodChannel = new MethodChannel(
64 | messenger,
65 | CHANNEL
66 | );
67 | methodChannel.setMethodCallHandler(new MethodChannel.MethodCallHandler() {
68 | @Override
69 | public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
70 | EzyClientProxy.this.run(call.method, (Map) call.arguments, result);
71 | }
72 | });
73 | this.addDefaultMethods();
74 | this.mainEventsLoop.start();
75 | }
76 |
77 | public void run(String method, Map params, MethodChannel.Result callback) {
78 | EzyMethodProxy func = methods.get(method);
79 | if(func == null)
80 | throw new IllegalArgumentException("has no method: " + method);
81 | try {
82 | func.validate(params);
83 | Object result = func.invoke(params);
84 | callback.success(result);
85 | }
86 | catch (EzyMethodCallException e) {
87 | if(callback != null) {
88 | Log.w("ezyfox-client", "call method: " + method + " with params: " + params + " error: " + e.getMessage());
89 | callback.error(e.getCode(), e.getMessage(), e.toString());
90 | }
91 | }
92 | catch (Exception e) {
93 | Log.e("ezyfox-client", "fatal error when call method: " + method, e);
94 | }
95 | }
96 |
97 | private void addDefaultMethods() {
98 | addMethod(new EzyCreateClientMethod(methodChannel));
99 | addMethod(new EzyConnectMethod());
100 | addMethod(new EzyReconnectMethod());
101 | addMethod(new EzyDisconnectMethod());
102 | addMethod(new EzySendMethod());
103 | addMethod(new EzySetStatusMethod());
104 | addMethod(new EzyStartPingScheduleMethod());
105 | addMethod(new EzyGenerateKeyPairMethod());
106 | addMethod(new EzyRsaDecryptMethod());
107 | addMethod(new EzyLogMethod());
108 | addMethod(new EzySetSessionKeyMethod());
109 | }
110 |
111 | private void addMethod(EzyMethodProxy method) {
112 | methods.put(method.getName(), method);
113 | }
114 | }
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/EzyFlutterClientPlugin.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter;
2 |
3 | import androidx.annotation.NonNull;
4 |
5 | import io.flutter.embedding.engine.plugins.FlutterPlugin;
6 |
7 | public class EzyFlutterClientPlugin implements FlutterPlugin {
8 |
9 | @Override
10 | public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
11 | EzyClientProxy.getInstance().register(
12 | flutterPluginBinding.getBinaryMessenger()
13 | );
14 | }
15 |
16 | @Override
17 | public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
18 | EzyClientProxy.getInstance().unregister();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/EzyMethodNames.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter;
2 |
3 | /**
4 | * Created by tavandung12 on 10/24/18.
5 | */
6 |
7 | public final class EzyMethodNames {
8 |
9 | public static final String METHOD_INIT = "init";
10 | public static final String METHOD_CONNECT = "connect";
11 | public static final String METHOD_DISCONNECT = "disconnect";
12 | public static final String METHOD_SEND = "send";
13 | public static final String METHOD_RECONNECT = "reconnect";
14 | public static final String METHOD_SET_STATUS = "setStatus";
15 | public static final String METHOD_START_PING_SCHEDULE = "startPingSchedule";
16 | public static final String METHOD_GENERATE_KEY_PAIR = "generateKeyPair";
17 | public static final String METHOD_RSA_DECRYPT = "rsaDecrypt";
18 | public static final String METHOD_LOG = "log";
19 | public static final String METHOD_SET_SESSION_KEY = "setSessionKey";
20 |
21 | private EzyMethodNames() {
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/exception/EzyMethodCallException.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.exception;
2 |
3 | /**
4 | * Created by tavandung12 on 10/24/18.
5 | */
6 |
7 | public class EzyMethodCallException extends RuntimeException {
8 | private final String code;
9 | private final String message;
10 |
11 | public EzyMethodCallException(String code, String message) {
12 | super(message);
13 | this.code = code;
14 | this.message = message;
15 | }
16 |
17 | public EzyMethodCallException(String code, String message, Throwable ex) {
18 | super(message, ex);
19 | this.code = code;
20 | this.message = message;
21 | }
22 |
23 | public String getCode() {
24 | return code;
25 | }
26 |
27 | @Override
28 | public String getMessage() {
29 | return message;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzyConnectMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
4 | import com.tvd12.ezyfoxserver.client.EzyClient;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * Created by tavandung12 on 10/24/18.
10 | */
11 |
12 | public class EzyConnectMethod extends EzyMethodProxy {
13 |
14 | @Override
15 | public void validate(Map params) {
16 | if(!params.containsKey("host"))
17 | throw new IllegalArgumentException("must specific host");
18 | if(!params.containsKey("port"))
19 | throw new IllegalArgumentException("must specific port");
20 | }
21 |
22 | @Override
23 | public Object invoke(Map params) {
24 | String host = (String) params.get("host");
25 | int port = (int) params.get("port");
26 | EzyClient client = getClient(params);
27 | client.connect(host, port);
28 | return Boolean.TRUE;
29 | }
30 |
31 | @Override
32 | public String getName() {
33 | return EzyMethodNames.METHOD_CONNECT;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzyCreateClientMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.config.EzyPingConfig;
4 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
5 | import com.tvd12.ezyfoxserver.client.flutter.serializer.EzyNativeSerializers;
6 | import com.tvd12.ezyfoxserver.client.EzyClient;
7 | import com.tvd12.ezyfoxserver.client.setup.EzySetup;
8 | import com.tvd12.ezyfoxserver.client.config.EzyClientConfig;
9 | import com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig;
10 | import com.tvd12.ezyfoxserver.client.constant.EzyCommand;
11 | import com.tvd12.ezyfoxserver.client.constant.EzyConstant;
12 | import com.tvd12.ezyfoxserver.client.entity.EzyArray;
13 | import com.tvd12.ezyfoxserver.client.event.EzyEvent;
14 | import com.tvd12.ezyfoxserver.client.event.EzyEventType;
15 | import com.tvd12.ezyfoxserver.client.handler.EzyDataHandler;
16 | import com.tvd12.ezyfoxserver.client.handler.EzyEventHandler;
17 |
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import java.util.Map;
21 |
22 | import io.flutter.plugin.common.MethodChannel;
23 |
24 | /**
25 | * Created by tavandung12 on 10/24/18.
26 | */
27 |
28 | public class EzyCreateClientMethod extends EzyMethodProxy {
29 |
30 | private final MethodChannel methodChannel;
31 |
32 | public EzyCreateClientMethod(MethodChannel methodChannel) {
33 | this.methodChannel = methodChannel;
34 | }
35 |
36 | @Override
37 | public void validate(Map params) {
38 | if(params == null)
39 | throw new NullPointerException("the config is null, can't create an client");
40 | if(!params.containsKey("zoneName"))
41 | throw new IllegalArgumentException("must specific zone name");
42 | }
43 |
44 | @Override
45 | public Object invoke(Map params) {
46 | EzyClientConfig config = newConfig(params);
47 | EzyClient client = getClient(config.getClientName());
48 | if(client == null) {
49 | client = clients.newClient(config);
50 | setupClient(client);
51 | }
52 | Map configMap = EzyNativeSerializers.serialize(config);
53 | return configMap;
54 | }
55 |
56 | private EzyClientConfig newConfig(Map params) {
57 | EzyClientConfig.Builder configBuilder = EzyClientConfig.builder();
58 | if(params.containsKey("clientName"))
59 | configBuilder.clientName((String) params.get("clientName"));
60 | if(params.containsKey("zoneName"))
61 | configBuilder.zoneName((String) params.get("zoneName"));
62 | if(params.containsKey("enableSSL"))
63 | configBuilder.enableSSL((Boolean) params.get("enableSSL"));
64 | if(params.containsKey("enableDebug"))
65 | configBuilder.enableDebug((Boolean) params.get("enableDebug"));
66 | if(params.containsKey("ping")) {
67 | Map ping = (Map) params.get("ping");
68 | EzyPingConfig.Builder pingConfigBuilder = configBuilder.pingConfigBuilder();
69 | if(ping.containsKey("pingPeriod"))
70 | pingConfigBuilder.pingPeriod((Integer) ping.get("pingPeriod"));
71 | if(ping.containsKey("maxLostPingCount"))
72 | pingConfigBuilder.maxLostPingCount((Integer) ping.get("maxLostPingCount"));
73 | }
74 | if(params.containsKey("reconnect")) {
75 | Map reconnect = (Map) params.get("reconnect");
76 | EzyReconnectConfig.Builder reconnectConfigBuilder = configBuilder.reconnectConfigBuilder();
77 | if (reconnect.containsKey("enable"))
78 | reconnectConfigBuilder.enable((Boolean) reconnect.get("enable"));
79 | if (reconnect.containsKey("reconnectPeriod"))
80 | reconnectConfigBuilder.reconnectPeriod((Integer) reconnect.get("reconnectPeriod"));
81 | if (reconnect.containsKey("maxReconnectCount"))
82 | reconnectConfigBuilder.maxReconnectCount((Integer) reconnect.get("maxReconnectCount"));
83 | }
84 | EzyClientConfig config = configBuilder.build();
85 | return config;
86 | }
87 |
88 | public void setupClient(EzyClient client) {
89 | EzySetup setup = client.setup();
90 | for(EzyEventType eventType : EzyEventType.values())
91 | setup.addEventHandler(eventType, new EzyNativeEventHandler(client, methodChannel));
92 | for(EzyCommand command : EzyCommand.values())
93 | setup.addDataHandler(command, new EzyNativeDataHandler(client, methodChannel, command));
94 | }
95 |
96 | @Override
97 | public String getName() {
98 | return EzyMethodNames.METHOD_INIT;
99 | }
100 | }
101 |
102 | class EzyNativeEventHandler implements EzyEventHandler {
103 | private final EzyClient client;
104 | private final MethodChannel methodChannel;
105 |
106 | public EzyNativeEventHandler(EzyClient client, MethodChannel methodChannel) {
107 | this.client = client;
108 | this.methodChannel = methodChannel;
109 | }
110 |
111 | @Override
112 | public void handle(EzyEvent event) {
113 | String eventTypeName = event.getType().getName();
114 | Map params = new HashMap<>();
115 | Map eventData = EzyNativeSerializers.serialize(event);
116 | params.put("clientName", client.getName());
117 | params.put("eventType", eventTypeName);
118 | params.put("data", eventData);
119 | methodChannel.invokeMethod("ezy.event", params);
120 | }
121 | }
122 |
123 | class EzyNativeDataHandler implements EzyDataHandler {
124 | private final EzyClient client;
125 | private final MethodChannel methodChannel;
126 | private final EzyConstant command;
127 |
128 | public EzyNativeDataHandler(EzyClient client,
129 | MethodChannel methodChannel,
130 | EzyConstant command) {
131 | this.client = client;
132 | this.methodChannel = methodChannel;
133 | this.command = command;
134 | }
135 |
136 | @Override
137 | public void handle(EzyArray data) {
138 | String commandName = command.getName();
139 | Map params = new HashMap<>();
140 | List commandData = EzyNativeSerializers.toList(data);
141 | params.put("clientName", client.getName());
142 | params.put("command", commandName);
143 | params.put("data", commandData);
144 | methodChannel.invokeMethod("ezy.data", params);
145 | }
146 | }
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzyDisconnectMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
4 | import com.tvd12.ezyfoxserver.client.EzyClient;
5 | import com.tvd12.ezyfoxserver.client.constant.EzyDisconnectReason;
6 |
7 | import java.util.Map;
8 |
9 | public class EzyDisconnectMethod extends EzyMethodProxy {
10 |
11 | @Override
12 | public Object invoke(Map params) {
13 | EzyClient client = getClient(params);
14 | int reason = EzyDisconnectReason.CLOSE.getId();
15 | if(params.containsKey("reason"))
16 | reason = (int) params.get("reason");
17 | client.disconnect(reason);
18 | return Boolean.TRUE;
19 | }
20 |
21 | @Override
22 | public String getName() {
23 | return EzyMethodNames.METHOD_DISCONNECT;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzyGenerateKeyPairMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import android.util.Base64;
4 |
5 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
6 | import com.tvd12.ezyfoxserver.client.security.EzyKeysGenerator;
7 |
8 | import java.security.KeyPair;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | /**
13 | * Created by tavandung12 on 10/25/18.
14 | */
15 |
16 | public class EzyGenerateKeyPairMethod extends EzyMethodProxy {
17 | @Override
18 | public Object invoke(Map params) {
19 | KeyPair keyPair = EzyKeysGenerator.builder()
20 | .build()
21 | .generate();
22 | byte[] publicKey = keyPair.getPublic().getEncoded();
23 | byte[] privateKey = keyPair.getPrivate().getEncoded();
24 | Map answer = new HashMap<>();
25 | answer.put("publicKey", Base64.encodeToString(publicKey, Base64.NO_WRAP));
26 | answer.put("privateKey", privateKey);
27 | return answer;
28 | }
29 |
30 | @Override
31 | public String getName() {
32 | return EzyMethodNames.METHOD_GENERATE_KEY_PAIR;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzyLogMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
4 | import com.tvd12.ezyfoxserver.client.logger.EzyLogger;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * Created by tavandung12 on 10/25/18.
10 | */
11 |
12 | public class EzyLogMethod extends EzyMethodProxy {
13 | @Override
14 | public Object invoke(Map params) throws Exception {
15 | String level = (String)params.getOrDefault("level", "i");
16 | String message = (String)params.get("message");
17 | if(level.equals("w")) {
18 | EzyLogger.warn(message);
19 | }
20 | else if(level.equals("e")) {
21 | EzyLogger.error(message);
22 | }
23 | else if(level.equals("d")) {
24 | EzyLogger.debug(message);
25 | }
26 | else {
27 | EzyLogger.info(message);
28 | }
29 | return Boolean.TRUE;
30 | }
31 |
32 | @Override
33 | public String getName() {
34 | return EzyMethodNames.METHOD_LOG;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzyMethodProxy.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.EzyClient;
4 | import com.tvd12.ezyfoxserver.client.EzyClients;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * Created by tavandung12 on 10/24/18.
10 | */
11 |
12 | public abstract class EzyMethodProxy {
13 |
14 | protected EzyClients clients = EzyClients.getInstance();
15 |
16 | public abstract Object invoke(Map params) throws Exception;
17 | public abstract String getName();
18 |
19 | public void validate(Map params) {}
20 |
21 | protected EzyClient getClient(String name) {
22 | EzyClient client = clients.getClient(name);
23 | return client;
24 | }
25 |
26 | protected EzyClient getClient(Map params) {
27 | if(!params.containsKey("clientName"))
28 | throw new IllegalArgumentException("must specific client name");
29 | String clientName = (String)params.get("clientName");
30 | EzyClient client = getClient(clientName);
31 | return client;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzyReconnectMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
4 | import com.tvd12.ezyfoxserver.client.EzyClient;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * Created by tavandung12 on 10/25/18.
10 | */
11 |
12 | public class EzyReconnectMethod extends EzyMethodProxy {
13 | @Override
14 | public Object invoke(Map params) {
15 | EzyClient client = getClient(params);
16 | boolean answer = client.reconnect();
17 | return answer;
18 | }
19 |
20 | @Override
21 | public String getName() {
22 | return EzyMethodNames.METHOD_RECONNECT;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzyRsaDecryptMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
4 | import com.tvd12.ezyfoxserver.client.security.EzyAsyCrypt;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * Created by tavandung12 on 10/25/18.
10 | */
11 |
12 | public class EzyRsaDecryptMethod extends EzyMethodProxy {
13 | @Override
14 | public Object invoke(Map params) throws Exception {
15 | byte[] message = (byte[])params.get("message");
16 | byte[] privateKey = (byte[])params.get("privateKey");
17 | return EzyAsyCrypt.builder()
18 | .privateKey(privateKey)
19 | .build()
20 | .decrypt(message);
21 | }
22 |
23 | @Override
24 | public String getName() {
25 | return EzyMethodNames.METHOD_RSA_DECRYPT;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzySendMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
4 | import com.tvd12.ezyfoxserver.client.flutter.serializer.EzyNativeSerializers;
5 | import com.tvd12.ezyfoxserver.client.EzyClient;
6 | import com.tvd12.ezyfoxserver.client.constant.EzyCommand;
7 | import com.tvd12.ezyfoxserver.client.entity.EzyArray;
8 |
9 | import java.util.List;
10 | import java.util.Map;
11 |
12 | /**
13 | * Created by tavandung12 on 10/25/18.
14 | */
15 |
16 | public class EzySendMethod extends EzyMethodProxy {
17 | @Override
18 | public void validate(Map params) {
19 | if(!params.containsKey("request"))
20 | throw new IllegalArgumentException("must specific request to send to server");
21 | }
22 |
23 | @Override
24 | public Object invoke(Map params) {
25 | EzyClient client = getClient(params);
26 | Map request = (Map) params.get("request");
27 | String cmd = (String) request.get("command");
28 | List data = (List) request.get("data");
29 | boolean encrypted = (Boolean)request.getOrDefault("encrypted", false);
30 | EzyArray array = EzyNativeSerializers.fromList(data);
31 | client.send(EzyCommand.valueOf(cmd), array, encrypted);
32 | return Boolean.TRUE;
33 | }
34 |
35 | @Override
36 | public String getName() {
37 | return EzyMethodNames.METHOD_SEND;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzySetSessionKeyMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
4 | import com.tvd12.ezyfoxserver.client.EzyClient;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * Created by tavandung12 on 10/25/18.
10 | */
11 |
12 | public class EzySetSessionKeyMethod extends EzyMethodProxy {
13 | @Override
14 | public Object invoke(Map params) throws Exception {
15 | EzyClient client = getClient(params);
16 | byte[] sessionKey = (byte[])params.get("sessionKey");
17 | client.setSessionKey(sessionKey);
18 | return Boolean.TRUE;
19 | }
20 |
21 | @Override
22 | public String getName() {
23 | return EzyMethodNames.METHOD_SET_SESSION_KEY;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzySetStatusMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
4 | import com.tvd12.ezyfoxserver.client.EzyClient;
5 | import com.tvd12.ezyfoxserver.client.constant.EzyConnectionStatus;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | * Created by tavandung12 on 10/25/18.
11 | */
12 |
13 | public class EzySetStatusMethod extends EzyMethodProxy {
14 | @Override
15 | public Object invoke(Map params) {
16 | EzyClient client = getClient(params);
17 | String statusName = (String) params.get("status");
18 | client.setStatus(EzyConnectionStatus.valueOf(statusName));
19 | return Boolean.TRUE;
20 | }
21 |
22 | @Override
23 | public String getName() {
24 | return EzyMethodNames.METHOD_SET_STATUS;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/proxy/EzyStartPingScheduleMethod.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.proxy;
2 |
3 | import com.tvd12.ezyfoxserver.client.flutter.EzyMethodNames;
4 | import com.tvd12.ezyfoxserver.client.EzyClient;
5 | import com.tvd12.ezyfoxserver.client.socket.EzyPingSchedule;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | * Created by tavandung12 on 10/25/18.
11 | */
12 |
13 | public class EzyStartPingScheduleMethod extends EzyMethodProxy {
14 | @Override
15 | public Object invoke(Map params) {
16 | EzyClient client = getClient(params);
17 | EzyPingSchedule pingSchedule = client.getPingSchedule();
18 | pingSchedule.start();
19 | return Boolean.TRUE;
20 | }
21 |
22 | @Override
23 | public String getName() {
24 | return EzyMethodNames.METHOD_START_PING_SCHEDULE;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/serializer/EzyClientConfigSerializer.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.serializer;
2 |
3 | import com.tvd12.ezyfoxserver.client.config.EzyClientConfig;
4 | import com.tvd12.ezyfoxserver.client.config.EzyPingConfig;
5 | import com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig;
6 |
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | /**
11 | * Created by tavandung12 on 10/25/18.
12 | */
13 |
14 | public class EzyClientConfigSerializer {
15 |
16 | public Map serialize(EzyClientConfig config) {
17 | Map map = new HashMap<>();
18 | map.put("clientName", config.getClientName());
19 | map.put("zoneName", config.getZoneName());
20 |
21 | EzyPingConfig pingConfig = config.getPing();
22 | Map pingMap = new HashMap<>();
23 | pingMap.put("maxLostPingCount", pingConfig.getMaxLostPingCount());
24 | pingMap.put("pingPeriod", pingConfig.getPingPeriod());
25 | map.put("ping", pingMap);
26 |
27 |
28 | EzyReconnectConfig reconnectConfig = config.getReconnect();
29 | Map reconnectMap = new HashMap<>();
30 | reconnectMap.put("maxReconnectCount", reconnectConfig.getMaxReconnectCount());
31 | reconnectMap.put("reconnectPeriod", reconnectConfig.getReconnectPeriod());
32 | reconnectMap.put("enable", reconnectConfig.isEnable());
33 | map.put("reconnect", reconnectMap);
34 | return map;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/serializer/EzyEventSerializer.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.serializer;
2 |
3 | import com.tvd12.ezyfoxserver.client.event.EzyConnectionFailureEvent;
4 | import com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent;
5 | import com.tvd12.ezyfoxserver.client.event.EzyEvent;
6 | import com.tvd12.ezyfoxserver.client.event.EzyEventType;
7 | import com.tvd12.ezyfoxserver.client.event.EzyLostPingEvent;
8 | import com.tvd12.ezyfoxserver.client.event.EzyTryConnectEvent;
9 | import com.tvd12.ezyfoxserver.client.function.EzyFunction;
10 |
11 | import java.util.HashMap;
12 | import java.util.Map;
13 |
14 | /**
15 | * Created by tavandung12 on 10/25/18.
16 | */
17 |
18 | public class EzyEventSerializer {
19 |
20 | private final Map> appliers;
21 |
22 | public EzyEventSerializer() {
23 | this.appliers = newAppliers();
24 | }
25 |
26 | public Map serialize(EzyEvent event) {
27 | EzyEventType eventType = event.getType();
28 | EzyFunction func = getApplier(eventType);
29 | Map answer = func.apply(event);
30 | return answer;
31 | }
32 |
33 | private EzyFunction getApplier(EzyEventType eventType) {
34 | if(appliers.containsKey(eventType))
35 | return appliers.get(eventType);
36 | throw new IllegalArgumentException("has no serializer for event type: " + eventType);
37 | }
38 |
39 | private Map> newAppliers() {
40 | Map> answer = new HashMap<>();
41 | answer.put(EzyEventType.CONNECTION_SUCCESS, new EzyFunction() {
42 | @Override
43 | public Map apply(EzyEvent event) {
44 | return new HashMap<>();
45 | }
46 | });
47 | answer.put(EzyEventType.CONNECTION_FAILURE, new EzyFunction() {
48 | @Override
49 | public Map apply(EzyEvent event) {
50 | EzyConnectionFailureEvent mevent = (EzyConnectionFailureEvent)event;
51 | Map map = new HashMap<>();
52 | map.put("reason", mevent.getReason().getId());
53 | return map;
54 | }
55 | });
56 | answer.put(EzyEventType.DISCONNECTION, new EzyFunction() {
57 | @Override
58 | public Map apply(EzyEvent event) {
59 | EzyDisconnectionEvent mevent = (EzyDisconnectionEvent)event;
60 | Map map = new HashMap<>();
61 | map.put("reason", mevent.getReason());
62 | return map;
63 | }
64 | });
65 | answer.put(EzyEventType.LOST_PING, new EzyFunction() {
66 | @Override
67 | public Map apply(EzyEvent event) {
68 | EzyLostPingEvent mevent = (EzyLostPingEvent)event;
69 | Map map = new HashMap<>();
70 | map.put("count", mevent.getCount());
71 | return map;
72 | }
73 | });
74 | answer.put(EzyEventType.TRY_CONNECT, new EzyFunction() {
75 | @Override
76 | public Map apply(EzyEvent event) {
77 | EzyTryConnectEvent mevent = (EzyTryConnectEvent)event;
78 | Map map = new HashMap<>();
79 | map.put("count", mevent.getCount());
80 | return map;
81 | }
82 | });
83 | return answer;
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/serializer/EzyNativeDataDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.serializer;
2 |
3 | import com.tvd12.ezyfoxserver.client.entity.EzyArray;
4 | import com.tvd12.ezyfoxserver.client.entity.EzyObject;
5 | import com.tvd12.ezyfoxserver.client.factory.EzyEntityFactory;
6 |
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | /**
11 | * Created by tavandung12 on 10/25/18.
12 | */
13 |
14 | public class EzyNativeDataDeserializer {
15 |
16 | public EzyArray fromList(List value) {
17 | EzyArray answer = EzyEntityFactory.newArray();
18 | answer.add(value);
19 | return answer;
20 | }
21 |
22 | public EzyObject fromMap(Map value) {
23 | EzyObject answer = EzyEntityFactory.newObject();
24 | answer.putAll(value);
25 | return answer;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/serializer/EzyNativeDataSerializer.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.serializer;
2 |
3 | import com.tvd12.ezyfoxserver.client.entity.EzyArray;
4 | import com.tvd12.ezyfoxserver.client.entity.EzyObject;
5 |
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | /**
10 | * Created by tavandung12 on 10/25/18.
11 | */
12 |
13 | public class EzyNativeDataSerializer {
14 |
15 | public List toList(EzyArray value) {
16 | if(value == null)
17 | return null;
18 | return value.toList();
19 | }
20 |
21 | public Map toMap(EzyObject value) {
22 | if(value == null)
23 | return null;
24 | return value.toMap();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/android/src/main/java/com/tvd12/ezyfoxserver/client/flutter/serializer/EzyNativeSerializers.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.ezyfoxserver.client.flutter.serializer;
2 |
3 | import com.tvd12.ezyfoxserver.client.config.EzyClientConfig;
4 | import com.tvd12.ezyfoxserver.client.entity.EzyArray;
5 | import com.tvd12.ezyfoxserver.client.event.EzyEvent;
6 |
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | /**
11 | * Created by tavandung12 on 10/25/18.
12 | */
13 |
14 | public final class EzyNativeSerializers {
15 |
16 | private static final EzyEventSerializer EVENT_SERIALIZER = new EzyEventSerializer();
17 | private static final EzyNativeDataSerializer DATA_SERIALIZER = new EzyNativeDataSerializer();
18 | private static final EzyNativeDataDeserializer DATA_DESERIALIZER = new EzyNativeDataDeserializer();
19 | private static final EzyClientConfigSerializer CLIENT_CONFIG_SERIALIZER = new EzyClientConfigSerializer();
20 |
21 | private EzyNativeSerializers() { }
22 |
23 | public static Map serialize(EzyEvent event) {
24 | Map answer = EVENT_SERIALIZER.serialize(event);
25 | return answer;
26 | }
27 |
28 | public static List toList(EzyArray array) {
29 | List answer = DATA_SERIALIZER.toList(array);
30 | return answer;
31 | }
32 |
33 | public static EzyArray fromList(List array) {
34 | EzyArray answer = DATA_DESERIALIZER.fromList(array);
35 | return answer;
36 | }
37 |
38 | public static Map serialize(EzyClientConfig config) {
39 | Map answer = CLIENT_CONFIG_SERIALIZER.serialize(config);
40 | return answer;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | Podfile.lock
2 | # Miscellaneous
3 | *.class
4 | *.log
5 | *.pyc
6 | *.swp
7 | .DS_Store
8 | .atom/
9 | .buildlog/
10 | .history
11 | .svn/
12 |
13 | # IntelliJ related
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # The .vscode folder contains launch configuration and tasks you configure in
20 | # VS Code which you may wish to be included in version control, so this line
21 | # is commented out by default.
22 | #.vscode/
23 |
24 | # Flutter/Dart/Pub related
25 | **/doc/api/
26 | **/ios/Flutter/.last_build_id
27 | .dart_tool/
28 | .flutter-plugins
29 | .flutter-plugins-dependencies
30 | .packages
31 | .pub-cache/
32 | .pub/
33 | /build/
34 |
35 | # Web related
36 | lib/generated_plugin_registrant.dart
37 |
38 | # Symbolication related
39 | app.*.symbols
40 |
41 | # Obfuscation related
42 | app.*.map.json
43 |
44 | # Android Studio will place build artifacts here
45 | /android/app/debug
46 | /android/app/profile
47 | /android/app/release
48 | pubspec.lock
49 | build/
50 | */build/
51 | target/
52 | */target/
53 | web/
54 | test/
55 | .metadata
56 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # ezyfox-server-flutter-client
2 |
3 | flutter client for [ezyfox server](https://github.com/youngmonkeys/ezyfox-server)
4 |
5 | # Architecture
6 |
7 |
8 |
9 | # Prepare
10 |
11 | 1. Download and install [JDK 8](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html)
12 | 2. Download and install [Android Studio](https://developer.android.com/studio)
13 | 3. Download and install [Xcode](https://developer.apple.com/xcode/)
14 | 4. Download and install [Intellij and Flutter plugin](https://www.jetbrains.com/idea/download)
15 | 5. Download and instal [Flutter SDK](https://flutter.dev/docs/get-started/install)
16 |
17 | # How to test?
18 |
19 | ### 1. Clone source code
20 |
21 | ```
22 | git@github.com:youngmonkeys/ezyfox-server-flutter-client.git
23 | ```
24 |
25 | ### 2. Pull submodules
26 |
27 | ```
28 | git submodule update --remote --recursive
29 | ```
30 |
31 | ### 3. Import source code
32 |
33 | - To IntelliJ IDE: for all
34 | - To Xcode: for iOS
35 | - To Android studio: for Android
36 |
37 | ### 4. You can run
38 |
39 | - [main.dart](https://github.com/youngmonkeys/ezyfox-server-flutter-client/blob/master/lib/main.dart) on Intellij
40 | - Build and Run on Xcode for iOS, don't for get run `pod install`
41 | - Build and run on Android Studio for Android
42 |
43 | ### 5. Where need I click?
44 |
45 | - Tap to plus button in bottom right corner
46 | - When you see `Greet Flutter's developer!`, congratulation, you've just run and connect to server successfully
47 |
48 | # Contact us
49 |
50 | - Touch us on [Facebook](https://www.facebook.com/youngmonkeys.org)
51 | - Email to me [Dzung](mailto:itprono3@gmail.com)
--------------------------------------------------------------------------------
/example/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | # This file configures the analyzer, which statically analyzes Dart code to
2 | # check for errors, warnings, and lints.
3 | #
4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6 | # invoked from the command line by running `flutter analyze`.
7 |
8 | # The following line activates a set of recommended lints for Flutter apps,
9 | # packages, and plugins designed to encourage good coding practices.
10 | include: package:flutter_lints/flutter.yaml
11 |
12 | linter:
13 | # The lint rules applied to this project can be customized in the
14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml`
15 | # included above or to enable additional rules. A list of all available lints
16 | # and their documentation is published at
17 | # https://dart-lang.github.io/linter/lints/index.html.
18 | #
19 | # Instead of disabling a lint rule for the entire project in the
20 | # section below, it can also be suppressed for a single line of code
21 | # or a specific dart file by using the `// ignore: name_of_lint` and
22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file
23 | # producing the lint.
24 | rules:
25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule
26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27 |
28 | # Additional information about this file can be found at
29 | # https://dart.dev/guides/language/analysis-options
30 |
--------------------------------------------------------------------------------
/example/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 | gradle/
9 |
10 | # Remember to never publicly share your keystore.
11 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
12 | key.properties
13 | **/*.keystore
14 | **/*.jks
15 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.application"
3 | id "kotlin-android"
4 | id "dev.flutter.flutter-gradle-plugin"
5 | }
6 |
7 | def localProperties = new Properties()
8 | def localPropertiesFile = rootProject.file("local.properties")
9 | if (localPropertiesFile.exists()) {
10 | localPropertiesFile.withReader("UTF-8") { reader ->
11 | localProperties.load(reader)
12 | }
13 | }
14 |
15 | def flutterRoot = localProperties.getProperty('flutter.sdk')
16 | if (flutterRoot == null) {
17 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
18 | }// in case of error here delete keyword 'new'
19 |
20 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
21 | if (flutterVersionCode == null) {
22 | flutterVersionCode = "1"
23 | }
24 |
25 | def flutterVersionName = localProperties.getProperty("flutter.versionName")
26 | if (flutterVersionName == null) {
27 | flutterVersionName = "1.0"
28 | }
29 |
30 | android {
31 | compileSdkVersion 31
32 |
33 | compileOptions {
34 | sourceCompatibility JavaVersion.VERSION_1_8
35 | targetCompatibility JavaVersion.VERSION_1_8
36 | }
37 |
38 | defaultConfig {
39 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
40 | applicationId "com.tvd12.hello_flutter"
41 | minSdkVersion 25
42 | targetSdkVersion 33
43 | versionCode flutterVersionCode.toInteger()
44 | versionName flutterVersionName
45 | }
46 |
47 | buildTypes {
48 | release {
49 | // TODO: Add your own signing config for the release build.
50 | // Signing with the debug keys for now, so `flutter run --release` works.
51 | signingConfig signingConfigs.debug
52 | }
53 | }
54 | }
55 |
56 | flutter {
57 | source '../..'
58 | }
59 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
14 |
18 |
22 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
38 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/tvd12/hello_flutter/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tvd12.hello_flutter;
2 |
3 | import androidx.annotation.NonNull;
4 |
5 | import com.tvd12.ezyfoxserver.client.flutter.EzyClientProxy;
6 |
7 | import io.flutter.embedding.android.FlutterActivity;
8 | import io.flutter.embedding.engine.FlutterEngine;
9 |
10 | public class MainActivity extends FlutterActivity {
11 |
12 | @Override
13 | public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
14 | super.configureFlutterEngine(flutterEngine);
15 | EzyClientProxy.getInstance().register(
16 | flutterEngine.getDartExecutor().getBinaryMessenger()
17 | );
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable-v21/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/example/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | allprojects {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | }
6 | }
7 |
8 | rootProject.buildDir = "../build"
9 | subprojects {
10 | project.buildDir = "${rootProject.buildDir}/${project.name}"
11 | }
12 | subprojects {
13 | project.evaluationDependsOn(":app")
14 | }
15 |
16 | tasks.register("clean", Delete) {
17 | delete rootProject.buildDir
18 | }
19 |
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | def flutterSdkPath = {
3 | def properties = new Properties()
4 | file("local.properties").withInputStream { properties.load(it) }
5 | def flutterSdkPath = properties.getProperty("flutter.sdk")
6 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7 | return flutterSdkPath
8 | }()
9 |
10 | includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
11 |
12 | repositories {
13 | google()
14 | mavenCentral()
15 | gradlePluginPortal()
16 | }
17 | }
18 |
19 | plugins {
20 | id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21 | id "com.android.application" version "7.3.0" apply false
22 | id "org.jetbrains.kotlin.android" version "1.7.10" apply false
23 | }
24 |
25 | include ':app'
26 |
--------------------------------------------------------------------------------
/example/images/flutter-sdk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/images/flutter-sdk.png
--------------------------------------------------------------------------------
/example/ios/.gitignore:
--------------------------------------------------------------------------------
1 | *.mode1v3
2 | *.mode2v3
3 | *.moved-aside
4 | *.pbxuser
5 | *.perspectivev3
6 | **/*sync/
7 | .sconsign.dblite
8 | .tags*
9 | **/.vagrant/
10 | **/DerivedData/
11 | Icon?
12 | **/Pods/
13 | **/.symlinks/
14 | profile
15 | xcuserdata
16 | **/.generated/
17 | Flutter/App.framework
18 | Flutter/Flutter.framework
19 | Flutter/Flutter.podspec
20 | Flutter/Generated.xcconfig
21 | Flutter/ephemeral/
22 | Flutter/app.flx
23 | Flutter/app.zip
24 | Flutter/flutter_assets/
25 | Flutter/flutter_export_environment.sh
26 | ServiceDefinitions.json
27 | Runner/GeneratedPluginRegistrant.*
28 |
29 | # Exceptions to above rules.
30 | !default.mode1v3
31 | !default.mode2v3
32 | !default.pbxuser
33 | !default.perspectivev3
34 |
--------------------------------------------------------------------------------
/example/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 8.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/ios/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment the next line to define a global platform for your project
2 | # platform :ios, '9.0'
3 |
4 | target 'Runner' do
5 | # Comment the next line if you don't want to use dynamic frameworks
6 | use_frameworks!
7 |
8 | # Pods for Runner
9 |
10 | pod 'OpenSSL-Universal'
11 |
12 | end
13 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
12 | EzyClientProxy.getInstance().registration(controller.binaryMessenger)
13 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/eb1dd0e6692afb1ab081bb88cbbfd6cb0099d059/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | hello_flutter
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | $(FLUTTER_BUILD_NAME)
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UISupportedInterfaceOrientations
30 |
31 | UIInterfaceOrientationPortrait
32 | UIInterfaceOrientationLandscapeLeft
33 | UIInterfaceOrientationLandscapeRight
34 |
35 | UISupportedInterfaceOrientations~ipad
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationPortraitUpsideDown
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 | UIViewControllerBasedStatusBarAppearance
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/example/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 | #import "EzyClientProxy.h"
3 | #import "EzyEncryptionProxy.h"
4 |
--------------------------------------------------------------------------------
/example/ios/Runner/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // ezyfox-server-react-native-client
4 | //
5 | // Created by Dung Ta Van on 10/25/18.
6 | // Copyright © 2018 Young Monkeys. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/example/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'socket_proxy.dart';
3 |
4 | void main() {
5 | runApp(const MyApp());
6 | }
7 |
8 | class MyApp extends StatelessWidget {
9 | const MyApp({Key? key}) : super(key: key);
10 |
11 | // This widget is the root of your application.
12 | @override
13 | Widget build(BuildContext context) {
14 | return MaterialApp(
15 | title: 'Flutter Demo',
16 | theme: ThemeData(
17 | primarySwatch: Colors.blue,
18 | ),
19 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
20 | );
21 | }
22 | }
23 |
24 | class MyHomePage extends StatefulWidget {
25 | const MyHomePage({Key? key, required this.title}) : super(key: key);
26 |
27 | final String title;
28 |
29 | @override
30 | State createState() => _MyHomePageState();
31 | }
32 |
33 | class _MyHomePageState extends State {
34 | int _counter = 0;
35 |
36 | String socketState = 'Socket has not connected yet';
37 | String sslMessage = '';
38 |
39 | Future setup() async {
40 | SocketProxy socketProxy = SocketProxy.getInstance();
41 | socketProxy.onDisconnected(() => {
42 | setState(() {
43 | socketState = 'Disconnected, retry ...';
44 | sslMessage = '';
45 | })
46 | });
47 | socketProxy.onConnectionFailed(() => {
48 | setState(() {
49 | socketState = 'Can not connect to server';
50 | sslMessage = '';
51 | })
52 | });
53 | socketProxy.onGreet((message) => {
54 | setState(() {
55 | socketState = message;
56 | sslMessage = '';
57 | })
58 | });
59 | socketProxy.onSecureChat((message) => {
60 | setState(() {
61 | socketState = 'Secure Chat';
62 | sslMessage = message;
63 | })
64 | });
65 | socketProxy.onConnection(() => {
66 | setState(() {
67 | socketState = 'Connected';
68 | sslMessage = '';
69 | })
70 | });
71 | }
72 |
73 | void _connect() {
74 | setState(() {
75 | _counter++;
76 | SocketProxy.getInstance().connectToServer("example", "123456");
77 | // freechat java client default credentials
78 | });
79 | }
80 |
81 | @override
82 | Widget build(BuildContext context) {
83 | setup();
84 | return Scaffold(
85 | appBar: AppBar(
86 | title: Text(widget.title),
87 | ),
88 | body: Center(
89 | child: Column(
90 | mainAxisAlignment: MainAxisAlignment.center,
91 | children: [
92 | const Text(
93 | 'You have pushed the button this many times:',
94 | ),
95 | Text(
96 | '$_counter',
97 | style: Theme.of(context).textTheme.headlineMedium,
98 | ),
99 | const Text(
100 | 'Socket message: ',
101 | ),
102 | Text(
103 | '$socketState',
104 | style: Theme.of(context).textTheme.headlineMedium,
105 | ),
106 | const Text(
107 | 'SSL message: ',
108 | ),
109 | Text(
110 | '$sslMessage',
111 | style: Theme.of(context).textTheme.headlineMedium,
112 | )
113 | ],
114 | ),
115 | ),
116 | floatingActionButton: FloatingActionButton(
117 | onPressed: _connect,
118 | tooltip: 'Connect',
119 | child: const Icon(Icons.add),
120 | ), // This trailing comma makes auto-formatting nicer for build methods.
121 | );
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/example/lib/socket_proxy.dart:
--------------------------------------------------------------------------------
1 | import 'package:ezyfox_server_flutter_client/ezy_client.dart';
2 | import 'package:ezyfox_server_flutter_client/ezy_clients.dart';
3 | import 'package:ezyfox_server_flutter_client/ezy_config.dart';
4 | import 'package:ezyfox_server_flutter_client/ezy_constants.dart';
5 | import 'package:ezyfox_server_flutter_client/ezy_entities.dart';
6 | import 'package:ezyfox_server_flutter_client/ezy_handlers.dart';
7 |
8 | const ZONE_NAME = "freechat";
9 | const APP_NAME = "freechat";
10 |
11 | class SocketProxy {
12 | bool settedUp = false;
13 | late String username;
14 | late String password;
15 | late EzyClient _client;
16 | late Function(String)? _greetCallback;
17 | late Function(String)? _secureChatCallback;
18 | late Function? _disconnectedCallback;
19 | late Function? _connectionCallback;
20 | late Function? _connectionFailedCallback;
21 | static final SocketProxy _INSTANCE = SocketProxy._();
22 |
23 | SocketProxy._() {}
24 |
25 | static SocketProxy getInstance() {
26 | return _INSTANCE;
27 | }
28 |
29 | void _setup() {
30 | EzyConfig config = EzyConfig();
31 | config.clientName = ZONE_NAME;
32 | config.enableSSL =
33 | false; // SSL is not active by default using freechat server
34 | config.ping.maxLostPingCount = 3;
35 | config.ping.pingPeriod = 1000;
36 | config.reconnect.maxReconnectCount = 10;
37 | config.reconnect.reconnectPeriod = 1000;
38 | // config.enableDebug = true;
39 | EzyClients clients = EzyClients.getInstance();
40 | _client = clients.newDefaultClient(config);
41 | _client.setup.addEventHandler(EzyEventType.DISCONNECTION,
42 | _DisconnectionHandler(_disconnectedCallback!));
43 | _client.setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS,
44 | _connectionHandler(_connectionCallback!));
45 | _client.setup.addEventHandler(EzyEventType.CONNECTION_FAILURE,
46 | _ConnectionFailureHandler(_connectionFailedCallback!));
47 | _client.setup.addDataHandler(EzyCommand.HANDSHAKE, _HandshakeHandler());
48 | _client.setup.addDataHandler(EzyCommand.LOGIN, _LoginSuccessHandler());
49 | _client.setup.addDataHandler(EzyCommand.APP_ACCESS, _AppAccessHandler());
50 | var appSetup = _client.setup.setupApp(APP_NAME);
51 | appSetup.addDataHandler("greet", _GreetResponseHandler((message) {
52 | _greetCallback!(message);
53 | }));
54 | appSetup.addDataHandler("secureChat", _SecureChatResponseHandler((message) {
55 | _secureChatCallback!(message);
56 | }));
57 | }
58 |
59 | void connectToServer(String username, String password) {
60 | if (!settedUp) {
61 | settedUp = true;
62 | _setup();
63 | }
64 | this.username = username;
65 | this.password = password;
66 | // this._client.connect("127.0.0.1", 3005);
67 | this._client.connect("10.0.2.2", 3005);
68 | // this._client.connect("tvd12.com", 3005);
69 | }
70 |
71 | void onGreet(Function(String) callback) {
72 | _greetCallback = callback;
73 | }
74 |
75 | void onSecureChat(Function(String) callback) {
76 | _secureChatCallback = callback;
77 | }
78 |
79 | void onDisconnected(Function callback) {
80 | _disconnectedCallback = callback;
81 | }
82 |
83 | void onConnection(Function callback) {
84 | _connectionCallback = callback;
85 | }
86 |
87 | void onConnectionFailed(Function callback) {
88 | _connectionFailedCallback = callback;
89 | }
90 | }
91 |
92 | class _HandshakeHandler extends EzyHandshakeHandler {
93 | @override
94 | List getLoginRequest() {
95 | var request = [];
96 | request.add(ZONE_NAME);
97 | request.add(SocketProxy.getInstance().username);
98 | request.add(SocketProxy.getInstance().password);
99 | request.add([]);
100 | return request;
101 | }
102 | }
103 |
104 | class _LoginSuccessHandler extends EzyLoginSuccessHandler {
105 | @override
106 | void handleLoginSuccess(responseData) {
107 | client.send(EzyCommand.APP_ACCESS, [APP_NAME]);
108 | }
109 | }
110 |
111 | class _AppAccessHandler extends EzyAppAccessHandler {
112 | @override
113 | void postHandle(EzyApp app, List data) {
114 | app.send("greet", {"who": "Flutter's developer"});
115 | }
116 | }
117 |
118 | class _GreetResponseHandler extends EzyAppDataHandler