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/managers/namespaces.dart";
|
||||||
import "package:moxxyv2/xmpp/xeps/xep_0030.dart";
|
import "package:moxxyv2/xmpp/xeps/xep_0030.dart";
|
||||||
import "package:moxxyv2/xmpp/xeps/xep_0198.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:moxxyv2/xmpp/xeps/xep_0368.dart";
|
||||||
|
|
||||||
import "package:uuid/uuid.dart";
|
import "package:uuid/uuid.dart";
|
||||||
@ -152,6 +153,11 @@ class XmppConnection {
|
|||||||
StreamManagementManager? getStreamManagementManager() {
|
StreamManagementManager? getStreamManagementManager() {
|
||||||
return getManagerById(smManager);
|
return getManagerById(smManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the registered [CSIManager], if one is registered.
|
||||||
|
CSIManager? getCSIManager() {
|
||||||
|
return getManagerById(csiManager);
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the connection settings of this connection.
|
/// Set the connection settings of this connection.
|
||||||
void setConnectionSettings(ConnectionSettings settings) {
|
void setConnectionSettings(ConnectionSettings settings) {
|
||||||
@ -479,6 +485,12 @@ class XmppConnection {
|
|||||||
_routingState = RoutingState.handleStanzas;
|
_routingState = RoutingState.handleStanzas;
|
||||||
_setConnectionState(XmppConnectionState.connected);
|
_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"]!);
|
final h = int.parse(node.attributes["h"]!);
|
||||||
_sendEvent(StreamResumedEvent(h: h));
|
_sendEvent(StreamResumedEvent(h: h));
|
||||||
} else if (node.tag == "failed") {
|
} 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 {
|
class CSIManager extends XmppManagerBase {
|
||||||
|
bool _isActive;
|
||||||
|
|
||||||
|
CSIManager() : _isActive = true, super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getId() => csiManager;
|
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
|
/// Tells the server to top optimizing traffic
|
||||||
void setActive() {
|
void setActive() {
|
||||||
|
_isActive = true;
|
||||||
|
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
if (attrs.isStreamFeatureSupported(csiXmlns)) {
|
if (attrs.isStreamFeatureSupported(csiXmlns)) {
|
||||||
attrs.sendNonza(CSIActiveNonza());
|
attrs.sendNonza(CSIActiveNonza());
|
||||||
@ -36,6 +51,8 @@ class CSIManager extends XmppManagerBase {
|
|||||||
|
|
||||||
/// Tells the server to optimize traffic following XEP-0352
|
/// Tells the server to optimize traffic following XEP-0352
|
||||||
void setInactive() {
|
void setInactive() {
|
||||||
|
_isActive = false;
|
||||||
|
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
if (attrs.isStreamFeatureSupported(csiXmlns)) {
|
if (attrs.isStreamFeatureSupported(csiXmlns)) {
|
||||||
attrs.sendNonza(CSIInactiveNonza());
|
attrs.sendNonza(CSIInactiveNonza());
|
||||||
|
Loading…
Reference in New Issue
Block a user