Platform API
Installation
npm install @cutos/core
Import CoreAPI
import {CoreAPI} from '@cutos/core';
CoreAPI.init
Initialization
CoreAPI.init(host, callback);
- host: CUTOS address. When host is equal to null, it takes the value 'localhost'. During development, it can be changed to the target address (the device address where CUTOS is installed), such as: '192.168.1.11'
- callback: callback function. The callback function will receive two parameters: result (String) and error (Object). Among them, error.name is the error name, and error.message is the specific error message.
Example:
CoreAPI.init('192.168.1.11', (result, error) => {
if (!error) {
console.log(result)
} else {
console.error('init failed' + error.message)
}
})
- Return result example:
{
"result": "CUTOS CORE connected."
}
CoreAPI.getVersion
Get platform version information
CoreAPI.getVersion();
- Return result example:
"3.2.2"
CoreAPI.getPlatform
Get platform information
CoreAPI.getPlatform(callback);
- callback: callback function
Example:
CoreAPI.getPlatform(result => {
console.log(result)
});
- Return result example:
{
"arch": "x64",
"platform": "win32",
"type": "Windows_NT",
"release": "10.0.19045"
}
CoreAPI.getConfig
Get configuration information
CoreAPI.getConfig(callback);
- callback: callback function
Example:
CoreAPI.getConfig(result => {
console.log(result)
});
- Return result example:
{
"srvAddress": "www.cut-os.com",
"srvRestProtocol": "https",
"enableTimeSync": true,
"playReport": false,
"language": "Chinese",
"debug": false
}
CoreAPI.getBoxInfo
Get host information
CoreAPI.getBoxInfo(callback);
- callback: callback function
Example:
CoreAPI.getBoxInfo(result => {
console.log(result)
})
- Return result example:
{
"id": 1016,
"macAddress": "00-F1-F5-2A-8E-8C",
"ipAddress": "192.168.1.127",
"masterIpAddress": "",
"osVersion": "3.2.0"
}
`
id
: Host IDmacAddress
: Host MAC addressipAddress
: host IP addressmasterIpAddress
: Master IP address, used when multiple hosts form a host grouposVersion
: CUTOS Player Version
CoreAPI.getDeviceInfo
Get device information
CoreAPI.getDeviceInfo(callback);
- callback: callback function
Example:
CoreAPI.getDeviceInfo(result => {
console.log(result)
})
- Return result example:
{
"id": 1234,
"name": "sipTimes office",
"shortName": "",
"groupId": 0,
"groupName": null,
"department": null,
"description": null,
"gwi": "9E1E3B67-...101B",
"gwUrl": "ws://127.0.0.1:61614",
"ext": null,
"token": "D+yIxq1d3...BTgjK....."
}
id
: device IDname
: device nameshortName
: device short namegroupId
: device group IDgroupName
: device group namedepartment
: departmentdescription
: descriptiongwi
: gateway IDgwUrl
: gateway addressext
: extended informationtoken
: token
CoreAPI.getVolume
Get the volume
CoreAPI.getVolume(callback);
- callback: callback function
Example:
CoreAPI.getVolume(result => {
console.log(result)
})
- Return result example:
"10"
CoreAPI.setVolume
Set the volume
CoreAPI.setVolume(value, callback)
- value: volume (0-100)
- callback: callback function
Example:
CoreAPI.setVolume(70, (result, error) => {
if (!error) {
console.log(result)
}
})
- Return result example:
{
"result": 70
}
CoreAPI.setHttpProxy
Set proxy to solve LWA cross-domain problem
CoreAPI.setHttpProxy(api, target, callback)
- api: interface name
- target: target address
- callback: callback function. The callback function returns result if successful and error if failed.
Example:
CoreAPI.setHttpProxy('api', 'https://www.cut-os.com', (result, error) => {
if (!error) {
console.log(result)
}
})
- Return result example:
{
"path": "proxy/api",
"target": "https://www.cut-os.com"
}
- path: Request address prefix
- target: target address
Actual interface call example
fetch(`http://localhost:3000/proxy/api/rest/sv/system/runtime/ping`)
The actual request address
fetch(`https://www.cut-os.com/rest/sv/system/runtime/ping`)
CoreAPI.shell
Shell command execution
CoreAPI.shell(command, callback)
- command: command
- callback: callback function
Example:
CoreAPI.shell('pwd', (result, error) => {
if (!error) {
console.log(result)
}
})
- Return result example:
"/home/linaro"