Öffentliche Websocket-API
(Beispiel: Javascript)
Verbindung öffnen
var rotoclear_ip = "192.168.214.221";
var rotoclear_api_port = "7000";
var my_api_token = "0123456789"
// Open websocket connection
var connection = new WebSocket("ws://" + rotoclear_ip + ":" + rotoclear_api_port);
// When the connection is open, send some data to the server
connection.onopen = function() { /* now you can send messages to api */ };
// Log errors
connection.onerror = function(error) { console.log('WebSocket Error ' + error); };
// Setup message callback
// If you will use jpeg stream, then you need a FileReader to handle not ut8 packets.
var jpeg_reader = new FileReader();
jpeg_reader.addEventListener("load", function () { some_image_tag.src = jpeg_reader.result; }, false);
connection.onmessage = function(evt) {
if (typeof evt.data === "string") {
var api_message = JSON.parse(evt.data);
console.debug(api_message);
// Use data from api
// ....
} else if (typeof evt.data === "object") {
// handle raw jpeg stream
jpeg_reader.readAsDataURL(msg.data)
}
};
// You can add the token to message in your custom send funtion
function customSendToAPI(message) {
message["token"] = my_api_token;
// Send message to api server. Only stringified json object is accepted
connection.send(JSON.stringify(message));
}
Informationsanfragen
Beispiel 1a - Nur eine einzelne Information
customSendToAPI({
info: "cam1-light",
});
// response = {
//
"cam1-light": true,
// }
Beispiel 1b - Liste von Informationen
customSendToAPI({ info: ["cam1-light", "brightness", "cam2-exists", "main-camera"] });
// response = {
Public Websocket API
(Example: Javascript)
Open Connection
Information Requests
Example 1a – Only a single piece of information
Example 1b – List of information
34
Anhang | Appendix