CRecordWebIncomingJson

The CRecordWebIncomingJson message is made for extensions to the Web API. Messages that the websocket server does not recognize are sent to interested targets with this message.

All JSON messages sent from the browser containing an unknown command in the cmd field are forwarded to the targets that have registered interest in the element's ID (field: id, see CRecordWebRegisterWidgetOwner).

Messages from the browser always have this format (mandatory field):

{
    "cmd": "onClick2",
    "id": "myElementId",
    "how": "left"
}

The message is part of the RemoteSkin Web API.
The API is located in the plugin NY_RemoteSkinWebProtocolAPI.

{
  "id": "770e679c-26c9-4548-ba41-a5e18759b9b7",
  "name": "WEB_INCOMING_JSON",
  "description": "A json text from the browser.",
  "slots": [
    {
      "key": "1",
      "name": "JSON",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The json text from the browser. The json must contain a field named 'id'."
    },
    {
      "key": "2",
      "name": "ID",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The element id."
    }
  ]
}

Arguments

  • JSON : The JSON text sent by the Javascript from the browser.
  • ID : The ID of the html element to which the message belongs.

Usage

Register your target address for this ID. You need to have the RemoteSkin address.

final CWebApi webApi = new CWebApi(this, // your target
                                   mRemoteSkinAddress);
webApi.registerWidgets(new String[]{"myElementId"});

Register a message handler for this message.

// constructor:
addMessageHandler(CRecordWebIncomingJson.ID,
                  this::asyncIncomingJson);

Implement the message handler.

private boolean asyncIncomingJson(@NotNull final CEnvelope aEnvelope,
                                  @NotNull final CRecord aRecord) throws CException
{
    if (aEnvelope.isAnswer())
    {
        return false;
    }
    else
    {
        final String id = CRecordWebIncomingJson.getId(aRecord,
                                                       "");
        final String json = CRecordWebIncomingJson.getJson(aRecord,
                                                           "");
        // ...
        aEnvelope.setResultSuccess();
        return true;
    }
}

See also: