diff --git a/packages/moxxmpp/lib/src/connection.dart b/packages/moxxmpp/lib/src/connection.dart index 0cef5c0..01aea42 100644 --- a/packages/moxxmpp/lib/src/connection.dart +++ b/packages/moxxmpp/lib/src/connection.dart @@ -270,6 +270,7 @@ class XmppConnection { negotiator.register( NegotiatorAttributes( sendRawXML, + () => this, () => _connectionSettings, _sendEvent, getNegotiatorById, diff --git a/packages/moxxmpp/lib/src/negotiators/negotiator.dart b/packages/moxxmpp/lib/src/negotiators/negotiator.dart index 9658e95..534dd28 100644 --- a/packages/moxxmpp/lib/src/negotiators/negotiator.dart +++ b/packages/moxxmpp/lib/src/negotiators/negotiator.dart @@ -1,5 +1,6 @@ import 'package:meta/meta.dart'; import 'package:moxlib/moxlib.dart'; +import 'package:moxxmpp/src/connection.dart'; import 'package:moxxmpp/src/errors.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/jid.dart'; @@ -28,6 +29,7 @@ abstract class NegotiatorError extends XmppError {} class NegotiatorAttributes { const NegotiatorAttributes( this.sendNonza, + this.getConnection, this.getConnectionSettings, this.sendEvent, this.getNegotiatorById, @@ -46,7 +48,10 @@ class NegotiatorAttributes { /// Returns the connection settings. final ConnectionSettings Function() getConnectionSettings; - /// Send an event event to the connection's event bus + /// Returns the connection object. + final XmppConnection Function() getConnection; + + /// Send an event event to the connection's event bus. final Future Function(XmppEvent event) sendEvent; /// Returns the negotiator with id id of the connection or null. diff --git a/packages/moxxmpp/lib/src/negotiators/resource_binding.dart b/packages/moxxmpp/lib/src/negotiators/resource_binding.dart index 6c6ffd2..2ebb737 100644 --- a/packages/moxxmpp/lib/src/negotiators/resource_binding.dart +++ b/packages/moxxmpp/lib/src/negotiators/resource_binding.dart @@ -30,10 +30,13 @@ class ResourceBindingNegotiator extends XmppFeatureNegotiatorBase { if (sm != null) { return super.matchesFeature(features) && !sm.streamResumed && - attributes.isAuthenticated(); + attributes.isAuthenticated() && + attributes.getConnection().resource.isEmpty; } - return super.matchesFeature(features) && attributes.isAuthenticated(); + return super.matchesFeature(features) && + attributes.isAuthenticated() && + attributes.getConnection().resource.isEmpty; } @override diff --git a/packages/moxxmpp/test/sasl/scram_test.dart b/packages/moxxmpp/test/sasl/scram_test.dart index 44596de..b8e3798 100644 --- a/packages/moxxmpp/test/sasl/scram_test.dart +++ b/packages/moxxmpp/test/sasl/scram_test.dart @@ -46,6 +46,11 @@ void main() { )..register( NegotiatorAttributes( (XMLNode _, {String? redact}) {}, + () => XmppConnection( + TestingReconnectionPolicy(), + AlwaysConnectedConnectivityManager(), + fakeSocket, + ), () => ConnectionSettings( jid: JID.fromString('user@server'), password: 'pencil', @@ -142,6 +147,11 @@ void main() { )..register( NegotiatorAttributes( (XMLNode n, {String? redact}) => lastMessage = n.innerText(), + () => XmppConnection( + TestingReconnectionPolicy(), + AlwaysConnectedConnectivityManager(), + StubTCPSocket([]), + ), () => ConnectionSettings( jid: JID.fromString('user@server'), password: 'pencil', @@ -193,6 +203,11 @@ void main() { )..register( NegotiatorAttributes( (XMLNode _, {String? redact}) {}, + () => XmppConnection( + TestingReconnectionPolicy(), + AlwaysConnectedConnectivityManager(), + StubTCPSocket([]), + ), () => ConnectionSettings( jid: JID.fromString('user@server'), password: 'pencil', @@ -234,6 +249,11 @@ void main() { )..register( NegotiatorAttributes( (XMLNode _, {String? redact}) {}, + () => XmppConnection( + TestingReconnectionPolicy(), + AlwaysConnectedConnectivityManager(), + StubTCPSocket([]), + ), () => ConnectionSettings( jid: JID.fromString('user@server'), password: 'pencil', @@ -278,6 +298,11 @@ void main() { )..register( NegotiatorAttributes( (XMLNode _, {String? redact}) {}, + () => XmppConnection( + TestingReconnectionPolicy(), + AlwaysConnectedConnectivityManager(), + StubTCPSocket([]), + ), () => ConnectionSettings( jid: JID.fromString('user@server'), password: 'pencil',