Touch script remote API for Node.js (Unofficial)
npm install touch-sprite-remote
import { fetchAuth, run, status } from 'touch-sprite-remote';
(async function () {
const { auth } = await fetchAuth({
key: '<my_key>',
devices: ['<my_device_id>'],
});
const runResult = await run('192.168.1.23', { auth });
console.log('run:', runResult); /* "ok" or "fail" */
const statusResult = await status('192.168.1.23', { auth });
console.log('status:', statusResult); /* "f00", "f01" or "f02" */
}());
Fetch auth / access token.
key
(String): Developer access keydevices
: ([String]): Devices IDsexpiresIn
(Number): Expires in seconds. Defaults to 3600
{
status: 200,
message: 'error message if status is not 200',
time: 1422930265, // current unix timestamp
auth: 'auth / access token',
expiresIn: 3600, // expires in second
remainderToken: 4, // remainder token
}
Get device name.
target
(String): Device host target. eg: '192.168.1.23'
(String): Device name.
Get status.
target
(String): Device host target. eg: '192.168.1.23'options
(Object): Definesoptions.auth
for access token (required)
(String): Returns one of these string:
f00
: Freef01
: In running scriptsf02
: In recording screen
Run script.
target
(String): Device host target. eg: '192.168.1.23'options
(Object): Definesoptions.auth
for access token (required)
(String): ok
or fail
Stop script.
target
(String): Device host target. eg: '192.168.1.23'options
(Object): Definesoptions.auth
for access token (required)
(String): ok
or fail
Upload file.
target
(String): Device host target. eg: '192.168.1.23'options
(Object):auth
(String): Access token (required)file
(String): Local file pathremoteFile
(String): Remote file pathtype
(String): Defining root type. One oflua
,res
,log
orplugin
is supported. By default, iffile
ext is.lua
,.luac
or.txt
, it would belua
, otherwise, it would beres
(String): ok
or fail
TSRemote class. A TSRemote instance by calling new TSRemote(options)
provides all methods above, but could only get and set auth once.
The options
is almost the same with fetchAuth(options)
, but also provides these two auth cache getter and setter functions:
async getAuth()
: Will call when calling any api needsauth
. It's useful to getauth
from your cache systemasync setAuth(authObject)
: Will call whengetAuth()
doesn't returnauth
. TheauthObject
is the same with the result offetchAuth()
. It's useful to save theauth
to your cache system
import TSRemote from 'touch-sprite-remote';
let cache;
(async function () {
const tsr = new TSRemote({
key: '<my_key>',
devices: ['<my_device_id>'],
/* add `getAuth()` and `setAuth()` functions */
getAuth: async () => cache,
setAuth: async ({ auth, expiresIn }) => (cache = auth),
});
/* no need `auth` option */
const runResult = await tsr.run('192.168.1.23');
const statusResult = await tsr.status('192.168.1.23');
}());
refreshToken()
: Force refresh tokenaddDevices(device[, ...devices])
: Add devices. Will refresh tokenremoveDevices(device[, ...devices])
: Remove devices. Will refresh token
MIT