diff --git a/example/lib/main.dart b/example/lib/main.dart index fbbdea2..d0a6147 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -108,12 +108,10 @@ class _MyHomePageState extends State { setState(() { loading = true; }); - connection.setConnectionSettings( - ConnectionSettings( - jid: JID.fromString(jidController.text), - password: passwordController.text, - useDirectTLS: true, - ), + connection.connectionSettings = ConnectionSettings( + jid: JID.fromString(jidController.text), + password: passwordController.text, + useDirectTLS: true, ); final result = await connection.connect(waitUntilLogin: true); setState(() { diff --git a/packages/moxxmpp/CHANGELOG.md b/packages/moxxmpp/CHANGELOG.md index 071da45..f448255 100644 --- a/packages/moxxmpp/CHANGELOG.md +++ b/packages/moxxmpp/CHANGELOG.md @@ -6,6 +6,7 @@ - Renamed `ResourceBindingSuccessEvent` to `ResourceBoundEvent` - **BREAKING**: Removed `isFeatureSupported` from the manager attributes. The managers now all have a method `isFeatureSupported` that works the same - The `PresenceManager` is now optional +- **BREAKING**: Removed `setConnectionSettings` and `getConnectionSettings`. Just directly acces the `connectionSettings` field. ## 0.1.6+1 diff --git a/packages/moxxmpp/lib/src/connection.dart b/packages/moxxmpp/lib/src/connection.dart index e1204b7..bd5ed09 100644 --- a/packages/moxxmpp/lib/src/connection.dart +++ b/packages/moxxmpp/lib/src/connection.dart @@ -119,7 +119,7 @@ class XmppConnection { late final Stream _socketStream; /// Connection settings - late ConnectionSettings _connectionSettings; + late ConnectionSettings connectionSettings; /// A policy on how to reconnect final ReconnectionPolicy _reconnectionPolicy; @@ -197,9 +197,9 @@ class XmppConnection { sendStanza: sendStanza, sendNonza: sendRawXML, sendEvent: _sendEvent, - getConnectionSettings: () => _connectionSettings, + getConnectionSettings: () => connectionSettings, getManagerById: getManagerById, - getFullJID: () => _connectionSettings.jid.withResource(_resource), + getFullJID: () => connectionSettings.jid.withResource(_resource), getSocket: () => _socket, getConnection: () => this, getNegotiatorById: _negotiationsHandler.getNegotiatorById, @@ -246,11 +246,11 @@ class XmppConnection { NegotiatorAttributes( sendRawXML, () => this, - () => _connectionSettings, + () => connectionSettings, _sendEvent, _negotiationsHandler.getNegotiatorById, getManagerById, - () => _connectionSettings.jid.withResource(_resource), + () => connectionSettings.jid.withResource(_resource), () => _socket, () => _isAuthenticated, _setAuthenticated, @@ -312,16 +312,6 @@ class XmppConnection { return getManagerById(csiManager); } - /// Set the connection settings of this connection. - void setConnectionSettings(ConnectionSettings settings) { - _connectionSettings = settings; - } - - /// Returns the connection settings of this connection. - ConnectionSettings getConnectionSettings() { - return _connectionSettings; - } - /// Attempts to reconnect to the server by following an exponential backoff. Future _attemptReconnection() async { _log.finest('_attemptReconnection: Setting state to notConnected'); @@ -471,14 +461,14 @@ class XmppConnection { case StanzaFromType.full: { stanza_ = stanza_.copyWith( - from: _connectionSettings.jid.withResource(_resource).toString(), + from: connectionSettings.jid.withResource(_resource).toString(), ); } break; case StanzaFromType.bare: { stanza_ = stanza_.copyWith( - from: _connectionSettings.jid.toBare().toString(), + from: connectionSettings.jid.toBare().toString(), ); } break; @@ -533,7 +523,7 @@ class XmppConnection { // A stanza with no to attribute is for direct processing by the server. As such, // we can correlate it by just *assuming* we have that attribute // (RFC 6120 Section 8.1.1.1) - data.stanza.to ?? _connectionSettings.jid.toBare().toString(), + data.stanza.to ?? connectionSettings.jid.toBare().toString(), data.stanza.id!, data.stanza.tag, ); @@ -752,7 +742,7 @@ class XmppConnection { final awaited = await _stanzaAwaiter.onData( incomingPreHandlers.stanza, - _connectionSettings.jid.toBare(), + connectionSettings.jid.toBare(), ); if (awaited) { return; @@ -841,7 +831,7 @@ class XmppConnection { closeTag: false, isDeclaration: true, children: [ - StreamHeaderNonza(_connectionSettings.jid), + StreamHeaderNonza(connectionSettings.jid), ], ).toXml(), ); @@ -929,20 +919,17 @@ class XmppConnection { } final smManager = getStreamManagementManager(); - var host = _connectionSettings.host; - var port = _connectionSettings.port; + var host = connectionSettings.host; + var port = connectionSettings.port; if (smManager?.state.streamResumptionLocation != null) { // TODO(Unknown): Maybe wrap this in a try catch? final parsed = Uri.parse(smManager!.state.streamResumptionLocation!); host = parsed.host; port = parsed.port; - } else { - host = _connectionSettings.host; - port = _connectionSettings.port; } final result = await _socket.connect( - _connectionSettings.jid.domain, + connectionSettings.jid.domain, host: host, port: port, ); diff --git a/packages/moxxmpp/test/xeps/xep_0030_test.dart b/packages/moxxmpp/test/xeps/xep_0030_test.dart index 8785f67..21c80e5 100644 --- a/packages/moxxmpp/test/xeps/xep_0030_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0030_test.dart @@ -72,12 +72,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), diff --git a/packages/moxxmpp/test/xeps/xep_0060_test.dart b/packages/moxxmpp/test/xeps/xep_0060_test.dart index 505e61e..7649ce4 100644 --- a/packages/moxxmpp/test/xeps/xep_0060_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0060_test.dart @@ -161,7 +161,7 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), socket, - ); + )..connectionSettings = TestingManagerHolder.settings; await connection.registerManagers([ PubSubManager(), @@ -174,7 +174,6 @@ void main() { SaslPlainNegotiator(), ResourceBindingNegotiator(), ]); - connection.setConnectionSettings(TestingManagerHolder.settings); await connection.connect( waitUntilLogin: true, ); diff --git a/packages/moxxmpp/test/xeps/xep_0198_test.dart b/packages/moxxmpp/test/xeps/xep_0198_test.dart index da0ea7a..cbd4f9b 100644 --- a/packages/moxxmpp/test/xeps/xep_0198_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0198_test.dart @@ -283,12 +283,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); final sm = StreamManagementManager(); await conn.registerManagers([ @@ -409,12 +407,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); final sm = StreamManagementManager(); await conn.registerManagers([ @@ -570,12 +566,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -665,12 +659,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -757,12 +749,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -846,12 +836,10 @@ void main() { ClientToServerNegotiator(), fakeSocket, ) - ..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + ..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ) ..setResource('test-resource', triggerEvent: false); await conn.registerManagers([ @@ -946,12 +934,10 @@ void main() { ClientToServerNegotiator(), fakeSocket, ) - ..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + ..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ) ..setResource('test-resource', triggerEvent: false); await conn.registerManagers([ @@ -1050,12 +1036,10 @@ void main() { ClientToServerNegotiator(), fakeSocket, ) - ..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + ..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ) ..setResource('test-resource', triggerEvent: false); await conn.registerManagers([ diff --git a/packages/moxxmpp/test/xeps/xep_0280_test.dart b/packages/moxxmpp/test/xeps/xep_0280_test.dart index 7dd045d..11d8bf9 100644 --- a/packages/moxxmpp/test/xeps/xep_0280_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0280_test.dart @@ -107,12 +107,10 @@ void main() { ClientToServerNegotiator(), fakeSocket, ) - ..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + ..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ) ..setResource('test-resource', triggerEvent: false); await conn.registerManagers([ diff --git a/packages/moxxmpp/test/xeps/xep_0352_test.dart b/packages/moxxmpp/test/xeps/xep_0352_test.dart index 526c64d..fd70995 100644 --- a/packages/moxxmpp/test/xeps/xep_0352_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0352_test.dart @@ -171,12 +171,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); final csi = CSIManager(); await csi.setInactive(sendNonza: false); diff --git a/packages/moxxmpp/test/xeps/xep_0386_test.dart b/packages/moxxmpp/test/xeps/xep_0386_test.dart index 5402606..39915c9 100644 --- a/packages/moxxmpp/test/xeps/xep_0386_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0386_test.dart @@ -46,12 +46,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -120,12 +118,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ RosterManager(TestingRosterStateManager('', [])), diff --git a/packages/moxxmpp/test/xeps/xep_0388_test.dart b/packages/moxxmpp/test/xeps/xep_0388_test.dart index f0fad63..8918d10 100644 --- a/packages/moxxmpp/test/xeps/xep_0388_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0388_test.dart @@ -103,12 +103,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -184,12 +182,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('user@server'), - password: 'pencil', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('user@server'), + password: 'pencil', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -264,12 +260,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('user@server'), - password: 'pencil', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('user@server'), + password: 'pencil', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -352,12 +346,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -438,12 +430,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), diff --git a/packages/moxxmpp/test/xeps/xep_xxxx_fast_test.dart b/packages/moxxmpp/test/xeps/xep_xxxx_fast_test.dart index f58e058..b6b1722 100644 --- a/packages/moxxmpp/test/xeps/xep_xxxx_fast_test.dart +++ b/packages/moxxmpp/test/xeps/xep_xxxx_fast_test.dart @@ -109,12 +109,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ RosterManager(TestingRosterStateManager('', [])), @@ -225,12 +223,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ RosterManager(TestingRosterStateManager('', [])), diff --git a/packages/moxxmpp/test/xmpp_test.dart b/packages/moxxmpp/test/xmpp_test.dart index 9828211..2242f0b 100644 --- a/packages/moxxmpp/test/xmpp_test.dart +++ b/packages/moxxmpp/test/xmpp_test.dart @@ -127,12 +127,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -185,12 +183,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -245,12 +241,10 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - )..setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('polynomdivision@test.server'), - password: 'aaaa', - useDirectTLS: true, - ), + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, ); await conn.registerManagers([ PresenceManager(), @@ -406,7 +400,11 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - ); + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('testuser@example.org'), + password: 'abc123', + useDirectTLS: false, + ); await conn.registerManagers([ PresenceManager(), RosterManager(TestingRosterStateManager('', [])), @@ -416,13 +414,6 @@ void main() { // SaslPlainNegotiator(), ResourceBindingNegotiator(), ]); - conn.setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('testuser@example.org'), - password: 'abc123', - useDirectTLS: false, - ), - ); final result = await conn.connect( waitUntilLogin: true, @@ -503,7 +494,11 @@ void main() { AlwaysConnectedConnectivityManager(), ClientToServerNegotiator(), fakeSocket, - ); + )..connectionSettings = ConnectionSettings( + jid: JID.fromString('testuser@example.org'), + password: 'abc123', + useDirectTLS: false, + ); await conn.registerManagers([ RosterManager(TestingRosterStateManager('', [])), DiscoManager([]), @@ -512,13 +507,6 @@ void main() { SaslPlainNegotiator(), ResourceBindingNegotiator(), ]); - conn.setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('testuser@example.org'), - password: 'abc123', - useDirectTLS: false, - ), - ); final result1 = conn.connect( waitUntilLogin: true,