Skip to content

Commit 414a5ab

Browse files
committed
feat: add network logs broadcaster for call history
1 parent 6241e18 commit 414a5ab

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

lib/services/connection/call_manager/call_history.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
import 'dart:async';
2+
13
import 'package:flutter_deriv_api/services/connection/call_manager/call_history_entry.dart';
4+
import 'package:flutter_deriv_api/services/interfaces/call_history_provider.dart';
25

36
/// Provides storage for messages sent/received via the web socket connection
4-
class CallHistory {
7+
class CallHistory implements CallHistoryProvider {
8+
/// It initializes [CallHistory] instance.
9+
CallHistory() {
10+
_callHistoryBroadcaster = StreamController<NetworkPayload>.broadcast();
11+
}
12+
13+
late final StreamController<NetworkPayload> _callHistoryBroadcaster;
14+
515
/// Messages that were sent to the remote endpoint
616
final List<CallHistoryEntry> outgoing = <CallHistoryEntry>[];
717

@@ -29,7 +39,15 @@ class CallHistory {
2939
incoming.add(
3040
CallHistoryEntry(timeStamp: timestamp, method: method, message: message),
3141
);
32-
42+
if (!method.contains('ping')) {
43+
_callHistoryBroadcaster.add(
44+
NetworkPayload(
45+
method: method,
46+
body: message,
47+
direction: 'RECEIVED',
48+
timeStamp: timestamp),
49+
);
50+
}
3351
_trimHistory(incoming);
3452
}
3553

@@ -42,6 +60,15 @@ class CallHistory {
4260
outgoing.add(
4361
CallHistoryEntry(timeStamp: timestamp, method: method, message: message),
4462
);
63+
if (!method.contains('ping')) {
64+
_callHistoryBroadcaster.add(
65+
NetworkPayload(
66+
method: method,
67+
body: message,
68+
direction: 'SENT',
69+
timeStamp: timestamp),
70+
);
71+
}
4572

4673
_trimHistory(outgoing);
4774
}
@@ -52,4 +79,7 @@ class CallHistory {
5279
callHistory.removeRange(0, callHistory.length - limit);
5380
}
5481
}
82+
83+
@override
84+
Stream<NetworkPayload> get stream => _callHistoryBroadcaster.stream;
5585
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// This interface provides stream of network payload that is going out(SENT)
2+
/// and coming in(RECEIVED) to the application.
3+
abstract class CallHistoryProvider {
4+
/// Stream of network payload that is going out(SENT) and coming in(RECEIVED)
5+
Stream<NetworkPayload> get stream;
6+
}
7+
8+
/// Network payload that is going out and coming in from the web socket.
9+
class NetworkPayload {
10+
/// Initializes [NetworkPayload] instance.
11+
NetworkPayload({
12+
required this.method,
13+
required this.body,
14+
required this.direction,
15+
required this.timeStamp,
16+
});
17+
18+
/// name of the api.
19+
final String method;
20+
21+
/// content of the api.
22+
final Object body;
23+
24+
/// direction of the api i.e SENT or RECEIVED.
25+
final String direction;
26+
27+
/// time of the api.
28+
final int timeStamp;
29+
}

0 commit comments

Comments
 (0)