feat(core): Add a callback for raw data events
This commit is contained in:
parent
87866bf3f5
commit
e7922668b1
@ -71,7 +71,11 @@ class XmppConnection {
|
|||||||
this._socket, {
|
this._socket, {
|
||||||
this.connectingTimeout = const Duration(minutes: 2),
|
this.connectingTimeout = const Duration(minutes: 2),
|
||||||
}) : _reconnectionPolicy = reconnectionPolicy,
|
}) : _reconnectionPolicy = reconnectionPolicy,
|
||||||
_connectivityManager = connectivityManager {
|
_connectivityManager = connectivityManager,
|
||||||
|
assert(
|
||||||
|
_socket.getDataStream().isBroadcast,
|
||||||
|
"The socket's data stream must be a broadcast stream",
|
||||||
|
) {
|
||||||
// Allow the reconnection policy to perform reconnections by itself
|
// Allow the reconnection policy to perform reconnections by itself
|
||||||
_reconnectionPolicy.register(
|
_reconnectionPolicy.register(
|
||||||
_attemptReconnection,
|
_attemptReconnection,
|
||||||
@ -95,10 +99,10 @@ class XmppConnection {
|
|||||||
);
|
);
|
||||||
_incomingStanzaQueue = IncomingStanzaQueue(handleXmlStream, _stanzaAwaiter);
|
_incomingStanzaQueue = IncomingStanzaQueue(handleXmlStream, _stanzaAwaiter);
|
||||||
_socketStream = _socket.getDataStream();
|
_socketStream = _socket.getDataStream();
|
||||||
// TODO(Unknown): Handle on done
|
|
||||||
_socketStream
|
_socketStream
|
||||||
.transform(_streamParser)
|
.transform(_streamParser)
|
||||||
.forEach(_incomingStanzaQueue.addStanza);
|
.forEach(_incomingStanzaQueue.addStanza);
|
||||||
|
_socketStream.listen(_handleOnDataCallbacks);
|
||||||
_socket.getEventStream().listen(handleSocketEvent);
|
_socket.getEventStream().listen(handleSocketEvent);
|
||||||
|
|
||||||
_stanzaQueue = AsyncStanzaQueue(
|
_stanzaQueue = AsyncStanzaQueue(
|
||||||
@ -314,6 +318,13 @@ class XmppConnection {
|
|||||||
return getManagerById(csiManager);
|
return getManagerById(csiManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called whenever we receive data on the socket.
|
||||||
|
Future<void> _handleOnDataCallbacks(String _) async {
|
||||||
|
for (final manager in _xmppManagers.values) {
|
||||||
|
unawaited(manager.onData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Attempts to reconnect to the server by following an exponential backoff.
|
/// Attempts to reconnect to the server by following an exponential backoff.
|
||||||
Future<void> _attemptReconnection() async {
|
Future<void> _attemptReconnection() async {
|
||||||
_log.finest('_attemptReconnection: Setting state to notConnected');
|
_log.finest('_attemptReconnection: Setting state to notConnected');
|
||||||
|
@ -80,6 +80,9 @@ abstract class XmppManagerBase {
|
|||||||
/// handler's priority, the earlier it is run.
|
/// handler's priority, the earlier it is run.
|
||||||
List<NonzaHandler> getNonzaHandlers() => [];
|
List<NonzaHandler> getNonzaHandlers() => [];
|
||||||
|
|
||||||
|
/// Whenever the socket receives data, this method is called, if it is non-null.
|
||||||
|
Future<void> onData() async {}
|
||||||
|
|
||||||
/// Return a list of features that should be included in a disco response.
|
/// Return a list of features that should be included in a disco response.
|
||||||
List<String> getDiscoFeatures() => [];
|
List<String> getDiscoFeatures() => [];
|
||||||
|
|
||||||
|
@ -75,6 +75,11 @@ class StreamManagementManager extends XmppManagerBase {
|
|||||||
return acks;
|
return acks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onData() async {
|
||||||
|
logger.finest('Got data!');
|
||||||
|
}
|
||||||
|
|
||||||
/// Called when a stanza has been acked to decide whether we should trigger a
|
/// Called when a stanza has been acked to decide whether we should trigger a
|
||||||
/// StanzaAckedEvent.
|
/// StanzaAckedEvent.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user