feat(xep): Small fixes - MUC Example.

Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
This commit is contained in:
Ikjot Singh Dhody 2023-07-01 17:29:51 +05:30
parent 8b00e85167
commit d3742ea156

View File

@ -15,7 +15,7 @@ void main(List<String> args) async {
});
final parser = ArgumentParser()
..parser.addOption('to', help: 'The JID to send messages to')
..parser.addOption('muc', help: 'The MUC to send messages to')
..parser.addOption('nick', help: 'The nickname with which to join the MUC');
final options = parser.handleArguments(args);
if (options == null) {
@ -23,10 +23,8 @@ void main(List<String> args) async {
}
// Connect
final jid = parser.jid;
final to = JID.fromString(options['to']! as String).toBare();
final muc = JID.fromString(options['muc']! as String).toBare();
final nick = options['nick']! as String;
print(parser.connectionSettings);
final connection = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
@ -34,11 +32,6 @@ void main(List<String> args) async {
ExampleTCPSocketWrapper(parser.srvRecord),
)..connectionSettings = parser.connectionSettings;
print(parser.connectionSettings.host);
print(parser.connectionSettings.jid);
print(parser.connectionSettings.password);
print(parser.connectionSettings.port);
// Register the managers and negotiators
await connection.registerManagers([
PresenceManager(),
@ -65,14 +58,14 @@ void main(List<String> args) async {
Logger.root.info('Connected.');
// Join room
await connection.getManagerById<MUCManager>(mucManager)!.joinRoom(to, nick);
await connection.getManagerById<MUCManager>(mucManager)!.joinRoom(muc, nick);
final repl = Repl(prompt: '> ');
await for (final line in repl.runAsync()) {
await connection
.getManagerById<MessageManager>(messageManager)!
.sendMessage(
to,
muc,
TypedMap<StanzaHandlerExtension>.fromList([
MessageBodyData(line),
]),
@ -80,7 +73,7 @@ void main(List<String> args) async {
}
// Leave room
await connection.getManagerById<MUCManager>(mucManager)!.leaveRoom(to);
await connection.getManagerById<MUCManager>(mucManager)!.leaveRoom(muc);
// Disconnect
await connection.disconnect();