xmpp: Have the [CSIManager] remember its last state
This commit is contained in:
parent
e33b290d24
commit
5be7e4a563
@ -19,6 +19,7 @@ import "package:moxxyv2/xmpp/managers/attributes.dart";
|
||||
import "package:moxxyv2/xmpp/managers/namespaces.dart";
|
||||
import "package:moxxyv2/xmpp/xeps/xep_0030.dart";
|
||||
import "package:moxxyv2/xmpp/xeps/xep_0198.dart";
|
||||
import "package:moxxyv2/xmpp/xeps/xep_0352.dart";
|
||||
import "package:moxxyv2/xmpp/xeps/xep_0368.dart";
|
||||
|
||||
import "package:uuid/uuid.dart";
|
||||
@ -153,6 +154,11 @@ class XmppConnection {
|
||||
return getManagerById(smManager);
|
||||
}
|
||||
|
||||
/// Returns the registered [CSIManager], if one is registered.
|
||||
CSIManager? getCSIManager() {
|
||||
return getManagerById(csiManager);
|
||||
}
|
||||
|
||||
/// Set the connection settings of this connection.
|
||||
void setConnectionSettings(ConnectionSettings settings) {
|
||||
_connectionSettings = settings;
|
||||
@ -479,6 +485,12 @@ class XmppConnection {
|
||||
_routingState = RoutingState.handleStanzas;
|
||||
_setConnectionState(XmppConnectionState.connected);
|
||||
|
||||
// Restore the CSI state if we have a manager
|
||||
final csiManager = getCSIManager();
|
||||
if (csiManager != null) {
|
||||
csiManager.restoreCSIState();
|
||||
}
|
||||
|
||||
final h = int.parse(node.attributes["h"]!);
|
||||
_sendEvent(StreamResumedEvent(h: h));
|
||||
} else if (node.tag == "failed") {
|
||||
|
@ -21,13 +21,28 @@ class CSIInactiveNonza extends XMLNode {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Remember the CSI state in case we resume a stream
|
||||
class CSIManager extends XmppManagerBase {
|
||||
bool _isActive;
|
||||
|
||||
CSIManager() : _isActive = true, super();
|
||||
|
||||
@override
|
||||
String getId() => csiManager;
|
||||
|
||||
/// To be called after a stream has been resumed as CSI does not
|
||||
/// survive a stream resumption.
|
||||
void restoreCSIState() {
|
||||
if (_isActive) {
|
||||
setActive();
|
||||
} else {
|
||||
setInactive();
|
||||
}
|
||||
}
|
||||
|
||||
/// Tells the server to top optimizing traffic
|
||||
void setActive() {
|
||||
_isActive = true;
|
||||
|
||||
final attrs = getAttributes();
|
||||
if (attrs.isStreamFeatureSupported(csiXmlns)) {
|
||||
attrs.sendNonza(CSIActiveNonza());
|
||||
@ -36,6 +51,8 @@ class CSIManager extends XmppManagerBase {
|
||||
|
||||
/// Tells the server to optimize traffic following XEP-0352
|
||||
void setInactive() {
|
||||
_isActive = false;
|
||||
|
||||
final attrs = getAttributes();
|
||||
if (attrs.isStreamFeatureSupported(csiXmlns)) {
|
||||
attrs.sendNonza(CSIInactiveNonza());
|
||||
|
Loading…
Reference in New Issue
Block a user