Git Product home page Git Product logo

node-touch-sprite-remote's Introduction

touch-sprite-remote

Build Status License

Touch script remote API for Node.js (Unofficial)

Table of Contents

Installation

npm install touch-sprite-remote

Getting Started

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" */
}());

API Reference

fetchAuth(options)

Fetch auth / access token.

Options
  • key (String): Developer access key
  • devices: ([String]): Devices IDs
  • expiresIn (Number): Expires in seconds. Defaults to 3600
Returns
{
  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
}

getDeviceName(target)

Get device name.

Arguments
  • target (String): Device host target. eg: '192.168.1.23'
Returns

(String): Device name.


status(target[, options])

Get status.

Arguments
  • target (String): Device host target. eg: '192.168.1.23'
  • options (Object): Defines options.auth for access token (required)
Returns

(String): Returns one of these string:

  • f00: Free
  • f01: In running scripts
  • f02: In recording screen

run(target[, options])

Run script.

Arguments
  • target (String): Device host target. eg: '192.168.1.23'
  • options (Object): Defines options.auth for access token (required)
Returns

(String): ok or fail


stop(target[, options])

Stop script.

Arguments
  • target (String): Device host target. eg: '192.168.1.23'
  • options (Object): Defines options.auth for access token (required)
Returns

(String): ok or fail


upload(target[, options])

Upload file.

Arguments
  • target (String): Device host target. eg: '192.168.1.23'
  • options (Object):
    • auth (String): Access token (required)
    • file (String): Local file path
    • remoteFile (String): Remote file path
    • type (String): Defining root type. One of lua, res, log or plugin is supported. By default, if file ext is .lua, .luac or .txt, it would be lua, otherwise, it would be res
Returns

(String): ok or fail


TSRemote

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 needs auth. It's useful to get auth from your cache system
  • async setAuth(authObject): Will call when getAuth() doesn't return auth. The authObject is the same with the result of fetchAuth(). It's useful to save the auth to your cache system
Example
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');
}());
Additional instance methods
  • refreshToken(): Force refresh token
  • addDevices(device[, ...devices]): Add devices. Will refresh token
  • removeDevices(device[, ...devices]): Remove devices. Will refresh token

License

MIT

node-touch-sprite-remote's People

Contributors

cap32 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.