onmessage method

void onmessage(
  1. ProxyMessage msg
)

Implementation

void onmessage(ProxyMessage msg) {
  final id = msg.id;

  final maybePromise = _pendingCalls[id];
  if (maybePromise == null) {
    throw 'A proxy get 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 "Invalid message being sent to ProxyAgent: ${jsonEncode(msg)}";
  }
}