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 UnsupportedError('Message received: ${jsonEncode(msg)}.');
  }
}