Compare commits
No commits in common. "b53c62b40ccf99dd8df845da0b1c3b1cd46d40b1" and "93d08188ea72892eb8d09660ed445a17ef0dc3c6" have entirely different histories.
b53c62b40c
...
93d08188ea
@ -11,22 +11,19 @@ class ExampleTcpSocketWrapper extends TCPSocketWrapper {
|
|||||||
Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async {
|
Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async {
|
||||||
final records = await MoxdnsPlugin.srvQuery(domain, false);
|
final records = await MoxdnsPlugin.srvQuery(domain, false);
|
||||||
return records
|
return records
|
||||||
.map(
|
.map((record) => MoxSrvRecord(
|
||||||
(record) => MoxSrvRecord(
|
record.priority,
|
||||||
record.priority,
|
record.weight,
|
||||||
record.weight,
|
record.target,
|
||||||
record.target,
|
record.port,
|
||||||
record.port,
|
),)
|
||||||
),
|
.toList();
|
||||||
)
|
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
Logger.root.level = Level.ALL;
|
Logger.root.level = Level.ALL;
|
||||||
Logger.root.onRecord.listen((record) {
|
Logger.root.onRecord.listen((record) {
|
||||||
// ignore: avoid_print
|
|
||||||
print('${record.level.name}: ${record.time}: ${record.message}');
|
print('${record.level.name}: ${record.time}: ${record.message}');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -57,29 +54,22 @@ class MyHomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
final logger = Logger('MyHomePage');
|
|
||||||
final XmppConnection connection = XmppConnection(
|
final XmppConnection connection = XmppConnection(
|
||||||
RandomBackoffReconnectionPolicy(1, 60),
|
ExponentialBackoffReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
ExampleTcpSocketWrapper(),
|
||||||
// The below causes the app to crash.
|
|
||||||
//ExampleTcpSocketWrapper(),
|
|
||||||
// In a production app, the below should be false.
|
|
||||||
TCPSocketWrapper(true),
|
|
||||||
);
|
);
|
||||||
TextEditingController jidController = TextEditingController();
|
TextEditingController jidController = TextEditingController();
|
||||||
TextEditingController passwordController = TextEditingController();
|
TextEditingController passwordController = TextEditingController();
|
||||||
bool connected = false;
|
|
||||||
bool loading = false;
|
|
||||||
|
|
||||||
_MyHomePageState() : super() {
|
_MyHomePageState() : super() {
|
||||||
connection
|
connection
|
||||||
..registerManagers([
|
..registerManagers([
|
||||||
StreamManagementManager(),
|
StreamManagementManager(),
|
||||||
DiscoManager([]),
|
DiscoManager(),
|
||||||
RosterManager(TestingRosterStateManager("", [])),
|
RosterManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
MessageManager(),
|
MessageManager(),
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
])
|
])
|
||||||
..registerFeatureNegotiators([
|
..registerFeatureNegotiators([
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
@ -95,45 +85,15 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _buttonPressed() async {
|
Future<void> _buttonPressed() async {
|
||||||
if (connected) {
|
|
||||||
await connection.disconnect();
|
|
||||||
setState(() {
|
|
||||||
connected = false;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
loading = true;
|
|
||||||
});
|
|
||||||
connection.setConnectionSettings(
|
connection.setConnectionSettings(
|
||||||
ConnectionSettings(
|
ConnectionSettings(
|
||||||
jid: JID.fromString(jidController.text),
|
jid: JID.fromString(jidController.text),
|
||||||
password: passwordController.text,
|
password: passwordController.text,
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
// If `allowPlainAuth` is `false`, connecting to some
|
allowPlainAuth: false,
|
||||||
// servers will cause apps to hang, and never connect.
|
|
||||||
// The hang is a bug that will be fixed, so when it is,
|
|
||||||
// allowPlainAuth should be set to false.
|
|
||||||
allowPlainAuth: true,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final result = await connection.connectAwaitable();
|
await connection.connect();
|
||||||
setState(() {
|
|
||||||
connected = result.success;
|
|
||||||
loading = false;
|
|
||||||
});
|
|
||||||
if (result.error != null) {
|
|
||||||
logger.severe(result.error);
|
|
||||||
if (context.mounted) {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (_) => AlertDialog(
|
|
||||||
title: const Text('Error'),
|
|
||||||
content: Text(result.error.toString()),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -141,24 +101,20 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
backgroundColor: connected ? Colors.green : Colors.deepPurple[800],
|
|
||||||
foregroundColor: connected ? Colors.black : Colors.white,
|
|
||||||
),
|
),
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
TextField(
|
TextField(
|
||||||
enabled: !loading,
|
|
||||||
controller: jidController,
|
controller: jidController,
|
||||||
decoration: const InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'JID',
|
labelText: 'JID',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
enabled: !loading,
|
|
||||||
controller: passwordController,
|
controller: passwordController,
|
||||||
decoration: const InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Password',
|
labelText: 'Password',
|
||||||
),
|
),
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
@ -166,13 +122,10 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: _buttonPressed,
|
onPressed: _buttonPressed,
|
||||||
label: Text(connected ? 'Disconnect' : 'Connect'),
|
|
||||||
backgroundColor: Colors.blue,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
tooltip: 'Connect',
|
tooltip: 'Connect',
|
||||||
icon: const Icon(Icons.power),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user