sendStatsLive method
- JsonMap frame
Sends frame (a StatsLiveFrame, for example a fixture of bothy_viz) as the ephemeral
event stats.live to every live connection with a subscription, with the scope of each
subscription (no sli for a space, 25 5.2); returns the number of connections reached.
The fake builds no frames itself: the test decides when one arrives, so "no frame for
viz.stale_after" is a test that sends none.
Implementation
int sendStatsLive(JsonMap frame) {
var sent = 0;
for (final c in _open) {
final sub = c.session?.stats;
if (!c.live || sub == null) continue;
final payload = jsonDecode(jsonEncode(frame)) as JsonMap;
payload['scope'] = statsScopeOf(sub.spaceId);
if (sub.spaceId != null) payload.remove('sli');
_send(c, 'dispatch', {
'id': world.nextId(),
'type': 'stats.live',
'schema_version': 1,
'occurred_at': world.stamp(),
'scope': {'space_id': ?sub.spaceId},
'resource': sub.spaceId == null
? {'kind': 'instance'}
: {'kind': 'space', 'id': sub.spaceId},
'payload': payload,
});
sent++;
}
return sent;
}