onMessage method
Implementation
void onMessage(ProxyMessage msg) {
final id = msg.id;
final maybePromise = _pendingCalls[id];
if (maybePromise == null) {
throw StateError('Proxy $id got the same message twice.');
}
_pendingCalls.remove(id);
final resolve = maybePromise.resolve;
final reject = maybePromise.reject;
switch (msg.type) {
case ProxyMessageKind.error:
return reject(msg.error);
case ProxyMessageKind.getPrincipalResponse:
case ProxyMessageKind.callResponse:
case ProxyMessageKind.queryResponse:
case ProxyMessageKind.readStateResponse:
case ProxyMessageKind.statusResponse:
return resolve(msg.response);
default:
throw UnsupportedError(
'Invalid message being sent to ProxyAgent: ${jsonEncode(msg)}.',
);
}
}