onmessage method

void onmessage(
  1. ProxyMessage msg
)

Implementation

void onmessage(ProxyMessage msg) {
  switch (msg.type) {
    case ProxyMessageKind.GetPrincipal:
      _agent.getPrincipal().then((response) {
        _frontend(ProxyMessageGetPrincipalResponse.fromJson({
          "id": msg.id,
          "type": ProxyMessageKind.GetPrincipalResponse,
          "response": response.toText(),
        }));
      });
      break;
    case ProxyMessageKind.Query:
      _agent.query(msg.args?[0], msg.args?[1], msg.args?[2]).then((response) {
        _frontend(ProxyMessageQueryResponse.fromJson({
          "id": msg.id,
          "type": ProxyMessageKind.QueryResponse,
          "response": response,
        }));
      });
      break;
    case ProxyMessageKind.Call:
      _agent.call(msg.args?[0], msg.args?[1], msg.args?[2]).then((response) {
        _frontend(ProxyMessageCallResponse.fromJson({
          "id": msg.id,
          "type": ProxyMessageKind.CallResponse,
          "response": response,
        }));
      });
      break;
    case ProxyMessageKind.ReadState:
      _agent
          .readState(msg.args?[0], msg.args?[1], msg.args?[2])
          .then((response) {
        _frontend(ProxyMessageReadStateResponse.fromJson({
          "id": msg.id,
          "type": ProxyMessageKind.ReadStateResponse,
          "response": response,
        }));
      });
      break;
    case ProxyMessageKind.Status:
      _agent.status().then((response) {
        _frontend(ProxyMessageStatusResponse.fromJson({
          "id": msg.id,
          "type": ProxyMessageKind.StatusResponse,
          "response": response,
        }));
      });
      break;

    default:
      throw "Invalid message received: ${jsonEncode(msg)}";
  }
}