Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added registration (Android only) #107

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class FlutterXmppConnectionService extends Service {
private Handler mTHandler;
private String jid_user = "";
private String password = "";
private boolean requireSSLConnection = false, autoDeliveryReceipt = false, useStreamManagement = true, automaticReconnection = true;
private boolean requireSSLConnection = false, autoDeliveryReceipt = false, useStreamManagement = true,
automaticReconnection = true, registerUser = false;
private FlutterXmppConnection mConnection;

public FlutterXmppConnectionService() {
Expand Down Expand Up @@ -66,23 +67,27 @@ private void initConnection() {
Utils.printLog(" initConnection(): ");

if (mConnection == null) {
mConnection = new FlutterXmppConnection(this, this.jid_user, this.password, this.host, this.port, requireSSLConnection, autoDeliveryReceipt, useStreamManagement, automaticReconnection);
mConnection = new FlutterXmppConnection(this, this.jid_user, this.password, this.host, this.port,
requireSSLConnection, autoDeliveryReceipt, useStreamManagement, automaticReconnection,
registerUser, this);
}

mConnection.connect();

} catch (IOException | SmackException | XMPPException e) {
FlutterXmppConnectionService.sConnectionState = ConnectionState.FAILED;
Utils.broadcastConnectionMessageToFlutter(this, ConnectionState.FAILED, "Something went wrong while connecting ,make sure the credentials are right and try again.");
Utils.printLog(" Something went wrong while connecting ,make sure the credentials are right and try again: ");
Utils.broadcastConnectionMessageToFlutter(this, ConnectionState.FAILED,
"Something went wrong while connecting ,make sure the credentials are right and try again.");
Utils.printLog(
" Something went wrong while connecting ,make sure the credentials are right and try again: ");
e.printStackTrace();
stopSelf();
}
}

public void start() {

Utils.printLog(" Service Start() function called: ");
Utils.printLog(" Service Start() function called: " + mActive);

if (!mActive) {
mActive = true;
Expand All @@ -104,15 +109,20 @@ public void stop() {
Utils.printLog(" stop() :");

mActive = false;
if (mThread.isAlive() && mThread != null) {
mThread.interrupt();
mThread = null;
}
if (mTHandler != null) {
mTHandler.post(() -> {
if (mConnection != null) {
mConnection.disconnect();
mConnection = null;
}
});
}
}

}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Expand All @@ -134,6 +144,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
this.autoDeliveryReceipt = extras.getBoolean(Constants.AUTO_DELIVERY_RECEIPT, false);
this.useStreamManagement = extras.getBoolean(Constants.USER_STREAM_MANAGEMENT, true);
this.automaticReconnection = extras.getBoolean(Constants.AUTOMATIC_RECONNECTION, true);
this.registerUser = extras.getBoolean(Constants.REGISTER_USER, false);

}
start();
Expand All @@ -148,4 +159,3 @@ public void onDestroy() {
stop();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class FlutterXmppPlugin implements MethodCallHandler, FlutterPlugin, Acti
private BroadcastReceiver successBroadcastReceiver = null;
private BroadcastReceiver errorBroadcastReceiver = null;
private BroadcastReceiver connectionBroadcastReceiver = null;
private boolean requireSSLConnection = false, autoDeliveryReceipt = false, automaticReconnection = true, useStreamManagement = true;
private boolean requireSSLConnection = false, autoDeliveryReceipt = false, automaticReconnection = true, useStreamManagement = true, registerUser = false;

// public static void registerWith(Registrar registrar) {
//
Expand Down Expand Up @@ -463,6 +463,7 @@ public void onMethodCall(MethodCall call, Result result) {

jid_user = call.argument(Constants.USER_JID).toString();
password = call.argument(Constants.PASSWORD).toString();
Utils.printLog("jid_user: " + jid_user + " password: " + password);
host = call.argument(Constants.HOST).toString();
if (call.hasArgument(Constants.PORT)) {
Constants.PORT_NUMBER = Integer.parseInt(call.argument(Constants.PORT).toString());
Expand All @@ -488,6 +489,10 @@ public void onMethodCall(MethodCall call, Result result) {
useStreamManagement = call.argument(Constants.USER_STREAM_MANAGEMENT);
}

if (call.hasArgument(Constants.REGISTER_USER)) {
registerUser = call.argument(Constants.REGISTER_USER);
}

// Start authentication.
doLogin();

Expand Down Expand Up @@ -786,7 +791,9 @@ public void onMethodCall(MethodCall call, Result result) {
// login
private void doLogin() {
// Check if the user is already connected or not ? if not then start login process.
if (FlutterXmppConnectionService.getState().equals(ConnectionState.DISCONNECTED)) {
Log.d("TAG", "doLogin: " + FlutterXmppConnectionService.getState());
if (FlutterXmppConnectionService.getState().equals(ConnectionState.DISCONNECTED) ||
FlutterXmppConnectionService.getState().equals(ConnectionState.FAILED)) {
Intent i = new Intent(activity, FlutterXmppConnectionService.class);
i.putExtra(Constants.JID_USER, jid_user);
i.putExtra(Constants.PASSWORD, password);
Expand All @@ -796,6 +803,7 @@ private void doLogin() {
i.putExtra(Constants.REQUIRE_SSL_CONNECTION, requireSSLConnection);
i.putExtra(Constants.USER_STREAM_MANAGEMENT, useStreamManagement);
i.putExtra(Constants.AUTOMATIC_RECONNECTION, automaticReconnection);
i.putExtra(Constants.REGISTER_USER, registerUser);
activity.startService(i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class Constants {
public static final String PASSWORD = "password";
public static final String SEND_MESSAGE = "send_message";
public static final String SEND_GROUP_MESSAGE = "send_group_message";
public static final String REGISTER_USER = "register_user";
public static final String LOGIN = "login";
public static final String TO_JID = "to_jid";
public static final String TO_JID_1 = "toJid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static long getLongDate() {
}

public static String getJidWithDomainName(String jid, String host) {
Log.d(Constants.TAG, "jid: " + jid + ", host: " + host);
return jid.contains(host) ? jid : jid + Constants.SYMBOL_COMPARE_JID + host;
}

Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class _MyAppState extends State<MyApp>
"autoDeliveryReceipt": false,
"useStreamManagement": false,
"automaticReconnection": true,
"register": true
};

flutterXmpp = XmppConnection(auth);
Expand Down
94 changes: 59 additions & 35 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
cross_file:
dependency: transitive
description:
Expand Down Expand Up @@ -101,10 +101,10 @@ packages:
dependency: transitive
description:
name: file
sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
url: "https://pub.dev"
source: hosted
version: "6.1.4"
version: "7.0.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -151,30 +151,54 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.6.7"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
matcher:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.11.0"
mime:
dependency: transitive
description:
Expand All @@ -187,10 +211,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
path_provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -283,10 +307,10 @@ packages:
dependency: transitive
description:
name: platform
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
version: "3.1.4"
plugin_platform_interface:
dependency: transitive
description:
Expand All @@ -299,10 +323,10 @@ packages:
dependency: transitive
description:
name: process
sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09"
sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32"
url: "https://pub.dev"
source: hosted
version: "4.2.4"
version: "5.0.2"
share_plus:
dependency: "direct main"
description:
Expand Down Expand Up @@ -347,10 +371,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "71d6806d1449b0a9d4e85e0c7a917771e672a3d5dc61149cc9fac871115018e1"
sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
version: "2.3.2"
shared_preferences_platform_interface:
dependency: transitive
description:
Expand All @@ -371,10 +395,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_windows
sha256: f95e6a43162bce43c9c3405f3eb6f39e5b5d11f65fab19196cf8225e2777624d
sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
version: "2.3.2"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -384,26 +408,26 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -432,10 +456,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -496,18 +520,18 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f6deed8ed625c52864792459709183da231ebf66ff0cf09e69b573227c377efe
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "11.3.0"
version: "13.0.0"
webdriver:
dependency: transitive
description:
name: webdriver
sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49"
sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "3.0.3"
win32:
dependency: transitive
description:
Expand Down Expand Up @@ -538,7 +562,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.2.10"
version: "2.2.12"
sdks:
dart: ">=3.0.0 <4.0.0"
flutter: ">=3.3.0"
dart: ">=3.2.0-0 <4.0.0"
flutter: ">=3.7.0"
10 changes: 5 additions & 5 deletions lib/ennums/typing_status.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
enum TypingStatus {
COMPOSING,
PAUSED,
ACTIVE,
GONE,
INACTIVE;
composing,
paused,
active,
gone,
inactive,
}
Loading
Loading