handleFrame method
Dispatches one decoded frame from peer. Anything that is not a
well-formed request is ignored, which is what makes a liveness knock —
connect, say nothing, close — cost a read loop and nothing else.
Implementation
void handleFrame(InspectorPeer peer, Map<String, Object?> frame) {
if (frame[frameType] != typeRequest) return;
var channel = frame[frameChannel];
var method = frame[frameMethod];
var id = frame[frameRequestId];
if (channel is! String || method is! String || id is! int) return;
if (channel == metaChannel && method == metaAttach) {
attach(peer, id);
return;
}
if (channel == metaChannel && method == metaDetail) {
var params = frame[framePayload];
var eventId = params is Map ? params['event'] : null;
var encoded = eventId is int ? _details[eventId] : null;
send(peer, {
frameChannel: metaChannel,
frameType: typeResponse,
frameRequestId: id,
framePayload: encoded == null
// Honest about the difference between "never captured" and
// "captured and evicted": the attacher words them differently.
? {'evicted': true}
: {'details': jsonDecode(encoded)},
});
return;
}
var handler = _handlers[channel]?[method];
if (handler == null) {
send(peer, {
frameChannel: channel,
frameType: typeError,
frameRequestId: id,
framePayload: {'message': 'no handler for $channel.$method'},
});
return;
}
var params = frame[framePayload];
unawaited(
_respond(
peer,
channel,
id,
handler,
params is Map ? params.cast<String, Object?>() : const {},
),
);
}