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