We are trying to implement a screen capture functionality on a Samsung TV with Tizen OS and send the captured image to Hyperion using WebSocket. Despite multiple attempts, we are encountering issues with the JSON data validation on the Hyperion server. Here are the steps and problems we've faced:
- Capture Screen on Tizen TV:
- We are capturing a specific area of the screen using a
<canvas>
element. - We convert the canvas content to a Base64 encoded PNG image.
- We are capturing a specific area of the screen using a
- Send Image to Hyperion:
- We establish a WebSocket connection to the Hyperion server.
- We send the image data along with the required parameters (
width
,height
,imagedata
, etc.) as a JSON object.
- Errors Encountered:
- The Hyperion server returns errors indicating issues with the JSON data validation.
- Specifically, the errors mention that
height
andwidth
have "no schema definition" andimagedata
is expected to be a string. - When we correct these, we get an error saying:
"Size of image data does not match with the width and height"
.
Current JSON Payload
Here is an example of the JSON data we are sending to Hyperion:
Code
{
"command": "image",
"imagedata": "iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAAAXNSR0IArs4c6QAACCxJREFUeF7tmleIVE0QhWvNYo6I...",
"width": 120,
"height": 120,
"format": "auto",
"origin": "TizenApp",
"priority": 50,
"duration": 0
}
Display More
Hyperion Server Logs
The logs on the Hyperion server show the following errors:
Code
2024-05-23T02:09:04.887Z [WEBSOCKET] (ERROR) While validating schema against json data of 'JsonRpc@::ffff:192.168.88.101':[root].height: no schema definition
2024-05-23T02:09:04.887Z [WEBSOCKET] (ERROR) While validating schema against json data of 'JsonRpc@::ffff:192.168.88.101':[root].width: no schema definition
2024-05-23T02:09:04.887Z [WEBSOCKET] (ERROR) While validating schema against json data of 'JsonRpc@::ffff:192.168.88.101':[root].format: Unknown enum value (allowed values are: ["auto"])
2024-05-23T02:09:04.887Z [WEBSOCKET] (ERROR) While validating schema against json data of 'JsonRpc@::ffff:192.168.88.101':[root].imagedata: string expected
When we fix the above errors, we encounter another error:
Here is the current JavaScript code we are using to capture the screen and send the image to Hyperion:
Code
function captureScreen() {
const captureArea = document.getElementById('captureArea');
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const fixedWidth = 120;
const fixedHeight = 120;
canvas.width = fixedWidth;
canvas.height = fixedHeight;
const colors = ['black', 'red', 'green', 'blue', 'yellow', 'purple', 'orange'];
const randomColor = colors[Math.floor(Math.random() * colors.length)];
context.fillStyle = randomColor;
context.fillRect(0, 0, canvas.width, canvas.height);
const text = captureArea.innerText || captureArea.textContent;
context.font = '30px Arial';
context.fillStyle = 'white';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillText(text, canvas.width / 2, canvas.height / 2);
const imageData = canvas.toDataURL('image/png').split(',')[1];
sendToHyperion(imageData, canvas.width, canvas.height);
}
function sendToHyperion(imageData, width, height) {
const ipHyperion = '192.168.88.101';
const puertoHyperion = 8090;
const jsonData = {
command: "image",
imagedata: imageData,
width: width,
height: height,
format: "auto",
origin: "TizenApp",
priority: 50,
duration: 0
};
const ws = new WebSocket(`ws://${ipHyperion}:${puertoHyperion}/jsonrpc`);
ws.onopen = function () {
ws.send(JSON.stringify(jsonData));
};
ws.onmessage = function (event) {
console.log('Message from server: ' + event.data);
};
ws.onerror = function (error) {
console.log('WebSocket error: ' + error.message);
};
ws.onclose = function () {
console.log('WebSocket connection closed');
};
}
Display More
Need assistance with the following:
- Correcting the JSON schema to match what Hyperion expects.
- Ensuring that the image data size matches the specified width and height.
Any guidance or examples would be greatly appreciated!
Thanks in advance!