# JavaScript
You can write your own custom JavaScript codes to manipulate the received data and pass it to the next block. An arrow function with one positional argument shall be provided like this.
json => {
return json;
}
JavaScript blocks can be cascaded.
# EdgeAI key
EdgeAI key is the key to access the API calls.
TIP
As API calls are chargable items in the Business and Enterprise version, please do not share your EdgeAI key with unauthorized parties.
# Installed libraries
A few sophisticated libraries are installed for use.
Package name |
---|
bluebird |
node-fetch |
# Used key names
Some key names are used in other blocks. Those names are not reserved and you can still used the names but with care.
# metadata
The key metadata
should not be removed if you are calling the JavaScript block from an external program. Metadata contains routing information. If those information is removed, the JavaScript block will not be able to reply to the external request; the external request will be timed out.
# image
and resolution
The image and resolution always appear in a pair in the JSON object. The image value contains a data URI which contains a base64-encoded string of a JPEG or PNG image. All augmentation blocks accept these 2 keys.
{
"image": "data:image/png,base64:...",
"resolution": {
"width": 1024,
"height": 768
}
}
# output
and bboxes
Bounding boxes are always stored in output
. bboxes
is an alias of output
which contains the same value as output
.
Key | Description |
---|---|
x, y | The center of the box |
left, top | The left and top of the box |
width, height | The size of the box |
The values are real numbers which contain decimals and the values are with respect to the size of the image not a value from 0 to 1.
# value
value
is usually used for output block such as Bar, Chart and Number. Value contains a nullable real number.
{
"value": 1.2345
}
# Calling from an external program
An external program can make a request to the pipeline running in the current browser. You can find the codes by clicking the "Show integration methods" button. We support Node.js, Python, HTML and Shell (cURL). HTML means you can call the pipeline from a web site.
In each integration approach, it requires 3 mandatory inputs.
- EdgeAI Key
- Pipeline ID
- Block ID
# Asynchronous processing
Studio supports asynchronous JavaScript processing. You just need to specify async
before the argument as follows.
async json => {
await Promise.delay(1000);
return json;
}
# JavaScript-to-JavaScript or JavaScript-to-Python
You can call another JavaScript block using sendMessage
like this. You can also find the same information by clicking the "Show integration methods" button and selecting "JavaScript (Block)".
async json => {
const output = await (new Promise(rs => sendMessage('[blockid of the other block]', 'request-json', {}, data => rs(data))));
return { ...json, output };
}
# Debugging
To debug, you can basically return the value in the JSON or simply turn on the web inspector.
← Introduction Python →