CRecordWebSendJson
The
Nearly all messages of the RemoteSkin API result in a JSON text being sent to the browser. This JSON text is then used to invoke JavaScript methods. The JavaScript files used by RemoteSkin are available in the source code and can be modified by you. The counterpart, i.e., sending the JSON text to the browser, is handled by this message. This allows you to implement any commands not yet provided by the API.
The reverse process, i.e., handling JSON text sent from the browser, is made possible by the CRecordWebIncomingJson notification.
The message is part of the RemoteSkin Web API.
The API is located in the plugin NY_RemoteSkinWebProtocolAPI.
{ "id": "749577d6-2404-49e5-bbbf-04d2a44b539a", "name": "WEB_SEND_JSON ", "description": "Send a json text to the browser.", "slots": [ { "key": "1", "name": "JSON ", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The json text for the browser." } ] }
Arguments
-
JSON : The JSON text to be sent directly to the Javascript in the browser.
Example
The CRecordWebSetInnerHtml message inserts HTML code into an HTML element. The WebSocket server converts the message into a JSON text, which is then sent to the browser.
{ "cmd": "setInnerHtml", "id": "myDiv", "html": "<p>Hello World!</p>" }
The JavaScript in the browser processes this text by locating the element with the specified ID and then calling the element's setInnerHtml() method.
const element = document.getElementById(id); if (element != null) { element.innerHTML = html; }
Usage with the helper class CWebApisince Version 2.4
The easiest way is to call the corresponding method in the CWebApi class. The use of the class is described there.
mWebApi.sendJson(@NotNull final StringaJson );
Usage as message
The RemoteSkin
public void sendJson(@NotNull final CTargetAddressaRemoteSkinAddress , @NotNull final StringaJson ) throws CException {// Envelope final CEnvelope env = CEnvelope.forSingleTarget(mRemoteSkinAddress );// Record final CRecord record =CRecordWebSendJson .create();CRecordWebSendJson .setJson(record,aJson );// send message sendNotification(env, record); }