mirror of
https://kevinblog.sytes.net/Code/Jibo-Revival-Group/RoboCommander.git
synced 2026-06-19 00:16:14 +00:00
Initial commit
This commit is contained in:
70
node_modules/@jibo/apptoolkit-library/lib/Account.js
generated
vendored
Normal file
70
node_modules/@jibo/apptoolkit-library/lib/Account.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const axios_1 = require("axios");
|
||||
const constants_1 = require("./constants");
|
||||
const Robot_1 = require("./Robot");
|
||||
/**
|
||||
* @description A reference to a Jibo account. Log in here to get an API handle
|
||||
* to a Jibo robot or robots.
|
||||
* @class Account
|
||||
*/
|
||||
class Account {
|
||||
constructor(creds) {
|
||||
this.clientId = creds.clientId;
|
||||
this._clientSecret = creds.clientSecret;
|
||||
this.email = creds.email;
|
||||
this._password = creds.password;
|
||||
}
|
||||
/**
|
||||
* Log into the account with the credentials provided in the
|
||||
* {@link AccountCreds}
|
||||
* @method Account#login
|
||||
*/
|
||||
async login() {
|
||||
if (this._accessToken) {
|
||||
this.logout();
|
||||
}
|
||||
const getTokenUri = `https://${constants_1.ENDPOINT}/token`;
|
||||
const body = {
|
||||
grant_type: "password",
|
||||
client_id: this.clientId,
|
||||
client_secret: this._clientSecret,
|
||||
username: this.email,
|
||||
password: this._password,
|
||||
};
|
||||
return axios_1.default.post(getTokenUri, body).then(res => {
|
||||
this._accessToken = res.data.access_token;
|
||||
this._tokenType = res.data.token_type;
|
||||
}).catch(err => { throw new Error(err.message); });
|
||||
}
|
||||
/**
|
||||
* Get an API handle for each robot associated with the account
|
||||
* @method Account#getRobots
|
||||
* @returns {Promise<Robot[]>}
|
||||
*/
|
||||
async getRobots() {
|
||||
if (!this._accessToken) {
|
||||
throw new Error('Not logged in');
|
||||
}
|
||||
const getRobotListUri = `https://${constants_1.ENDPOINT}/rom/v1/robots`;
|
||||
return axios_1.default.get(getRobotListUri, {
|
||||
headers: { "Authorization": `${this._tokenType} ${this._accessToken}` },
|
||||
})
|
||||
.then(res => res.data.data.map(data => new Robot_1.Robot(data.robotName, this._tokenType, this._accessToken)))
|
||||
.catch(err => { throw new Error(err.message); });
|
||||
}
|
||||
/**
|
||||
* Log out from the account
|
||||
* @method Account#logout
|
||||
*/
|
||||
logout() {
|
||||
// Don't throw an error if this is called in a late cleanup and this
|
||||
// falls out of scope
|
||||
if (this) {
|
||||
this._accessToken = null;
|
||||
this._tokenType = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Account = Account;
|
||||
//# sourceMappingURL=Account.js.map
|
||||
1
node_modules/@jibo/apptoolkit-library/lib/Account.js.map
generated
vendored
Normal file
1
node_modules/@jibo/apptoolkit-library/lib/Account.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Account.js","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":";;AACA,iCAA0B;AAC1B,2CAAqC;AACrC,mCAA8B;AAE9B;;;;GAIG;AACH;IAaI,YAAY,KAAmB;QAC3B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK;QACP,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,IAAI,CAAC,MAAM,EAAE,CAAC;SACjB;QACD,MAAM,WAAW,GAAG,WAAW,oBAAQ,QAAQ,CAAC;QAChD,MAAM,IAAI,GAAG;YACT,UAAU,EAAE,UAAU;YACtB,SAAS,EAAE,IAAI,CAAC,QAAQ;YACxB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,KAAK;YACpB,QAAQ,EAAE,IAAI,CAAC,SAAS;SAC3B,CAAC;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AC1B;IACL,CAAC;CACJ;AA5ED,0BA4EC"}
|
||||
3
node_modules/@jibo/apptoolkit-library/lib/AccountCreds.js
generated
vendored
Normal file
3
node_modules/@jibo/apptoolkit-library/lib/AccountCreds.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=AccountCreds.js.map
|
||||
1
node_modules/@jibo/apptoolkit-library/lib/AccountCreds.js.map
generated
vendored
Normal file
1
node_modules/@jibo/apptoolkit-library/lib/AccountCreds.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"AccountCreds.js","sourceRoot":"","sources":["../src/AccountCreds.ts"],"names":[],"mappings":""}
|
||||
128
node_modules/@jibo/apptoolkit-library/lib/Robot.js
generated
vendored
Normal file
128
node_modules/@jibo/apptoolkit-library/lib/Robot.js
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const axios_1 = require("axios");
|
||||
const events_1 = require("events");
|
||||
const command_requester_1 = require("@jibo/command-requester");
|
||||
const constants_1 = require("./constants");
|
||||
/**
|
||||
* An API handle to a Jibo robot, used to request commands
|
||||
* @class Robot
|
||||
* @hideconstructor
|
||||
*/
|
||||
class Robot extends events_1.EventEmitter {
|
||||
/** @private */
|
||||
constructor(
|
||||
/**
|
||||
* The "friendly serial name" from the bottom of the robot,
|
||||
* e.g. My-Friendly-Robot-Name
|
||||
*/
|
||||
serialName, tokenType, accessToken) {
|
||||
super();
|
||||
this.serialName = serialName;
|
||||
this.tokenType = tokenType;
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
/**
|
||||
* `true` if the app is currently connected to this robot
|
||||
* @method Robot#connected
|
||||
* @returns {boolean}
|
||||
*/
|
||||
get connected() {
|
||||
return this._connected;
|
||||
}
|
||||
/**
|
||||
* A handle to the command requester for this robot
|
||||
* @method Robot#requester
|
||||
* @returns {CommandRequester}
|
||||
*/
|
||||
get requester() {
|
||||
return this._requester;
|
||||
}
|
||||
/**
|
||||
* Establish a connection to this robot
|
||||
* @method Robot.connect
|
||||
*/
|
||||
async connect() {
|
||||
if (this.connected) {
|
||||
await this.disconnect();
|
||||
}
|
||||
if (!this._ip) {
|
||||
await this._requestCertificate();
|
||||
await this._retrieveCertificate();
|
||||
}
|
||||
const options = {
|
||||
port: constants_1.PORT,
|
||||
key: this._key,
|
||||
cert: this._certificate,
|
||||
rejectUnauthorized: false,
|
||||
perMessageDeflate: false,
|
||||
fingerprint: this._fingerprint,
|
||||
};
|
||||
this._requester = new command_requester_1.CommandRequester();
|
||||
this._requester.disconnected.on(data => {
|
||||
this._connected = false;
|
||||
this.emit('disconnected', data);
|
||||
this.emit('status', 'disconnected');
|
||||
});
|
||||
return this._requester.connect(this._ip, options)
|
||||
.then(() => {
|
||||
this._connected = true;
|
||||
this.emit('status', 'connected');
|
||||
})
|
||||
.catch(err => { throw new Error(err.message); });
|
||||
}
|
||||
/**
|
||||
* Disconnect from this robot
|
||||
* @method Robot#disconnect
|
||||
*/
|
||||
disconnect() {
|
||||
// Don't throw an error if this is called in a late cleanup and this
|
||||
// falls out of scope
|
||||
if (this) {
|
||||
this._requester.disconnect();
|
||||
this._certificate = null;
|
||||
this._connected = false;
|
||||
this._fingerprint = null;
|
||||
this._ip = null;
|
||||
this._key = null;
|
||||
this._requester = null;
|
||||
this.emit('status', 'disconnected');
|
||||
}
|
||||
}
|
||||
async _requestCertificate() {
|
||||
const certificateCreationUri = `https://${constants_1.ENDPOINT}/rom/v1/certificates`;
|
||||
const body = { friendlyId: this.serialName };
|
||||
const headers = { 'Authorization': `${this.tokenType} ${this.accessToken}` };
|
||||
await axios_1.default.post(certificateCreationUri, body, { headers })
|
||||
.then(() => this.emit('status', 'certificateRequested'))
|
||||
.catch(err => { throw new Error(err.message); });
|
||||
}
|
||||
async _retrieveCertificate() {
|
||||
const certificateRetrievalUri = `https://${constants_1.ENDPOINT}/rom/v1/certificates/client?friendlyId=${this.serialName}`;
|
||||
const headers = { 'Authorization': `${this.tokenType} ${this.accessToken}` };
|
||||
this._ip = null;
|
||||
let numTries = 0;
|
||||
while (!this._ip && numTries < constants_1.MAX_CERT_TRIES) {
|
||||
try {
|
||||
await axios_1.default.get(certificateRetrievalUri, {
|
||||
headers,
|
||||
timeout: 5000,
|
||||
}).then(res => {
|
||||
this._certificate = res.data.data.cert;
|
||||
this._fingerprint = res.data.data.fingerprint;
|
||||
this._ip = res.data.data.payload.ipAddress;
|
||||
this._key = res.data.data.private;
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
numTries++;
|
||||
}
|
||||
}
|
||||
if (!this._ip) {
|
||||
throw new Error('Failed to retrieve certificate');
|
||||
}
|
||||
this.emit('status', 'certificateReceived');
|
||||
}
|
||||
}
|
||||
exports.Robot = Robot;
|
||||
//# sourceMappingURL=Robot.js.map
|
||||
1
node_modules/@jibo/apptoolkit-library/lib/Robot.js.map
generated
vendored
Normal file
1
node_modules/@jibo/apptoolkit-library/lib/Robot.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Robot.js","sourceRoot":"","sources":["../src/Robot.ts"],"names":[],"mappings":";;AAAA,iCAA0B;AAC1B,mCAAoC;AACpC,+DAAyD;AACzD,2CAA2D;AAE3D;;;;GAIG;AACH,WAAmB,SAAQ,qBAAY;IASnC,eAAe;IACf;IACI;;;OAGG;IACM,UAAkB,EACnB,SAAiB,EACjB,WAAmB;QAE3B,KAAK,EAAE,CAAC;QAJC,eAAU,GAAV,UAAU,CAAQ;QACnB,cAAS,GAAT,SAAS,CAAQ;QACjB,gBAAW,GAAX,WAAW,CAAQ;IAG/B,CAAC;IAED;;;;OAIG;IACH,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;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,GAAG,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,QAAQ,GAAG,0BAAc,EAAE;YAC3C,IAAI;gBACA,MAAM,eAAK,CAAC,GAAG,CAAC,uBAAuB,EAAE;oBACrC,OAAO;oBACP,OAAO,EAAE,IAAI;iBAChB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;oBACV,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;oBACvC,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;oBAC9C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;oBAC3C,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;gBACtC,CAAC,CAAC,CAAC;aACN;YAAC,OAAO,GAAG,EAAE;gBACV,QAAQ,EAAE,CAAC;aACd;SACJ;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;SACrD;QACD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IAC/C,CAAC;CACJ;AAhID,sBAgIC"}
|
||||
6
node_modules/@jibo/apptoolkit-library/lib/constants.js
generated
vendored
Normal file
6
node_modules/@jibo/apptoolkit-library/lib/constants.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ENDPOINT = 'portal.jibo.com';
|
||||
exports.MAX_CERT_TRIES = 40;
|
||||
exports.PORT = 7160;
|
||||
//# sourceMappingURL=constants.js.map
|
||||
1
node_modules/@jibo/apptoolkit-library/lib/constants.js.map
generated
vendored
Normal file
1
node_modules/@jibo/apptoolkit-library/lib/constants.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;AAAa,QAAA,QAAQ,GAAG,iBAAiB,CAAC;AAC7B,QAAA,cAAc,GAAG,EAAE,CAAC;AACpB,QAAA,IAAI,GAAG,IAAI,CAAC"}
|
||||
7
node_modules/@jibo/apptoolkit-library/lib/index.js
generated
vendored
Normal file
7
node_modules/@jibo/apptoolkit-library/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const Account_1 = require("./Account");
|
||||
exports.Account = Account_1.Account;
|
||||
const Robot_1 = require("./Robot");
|
||||
exports.Robot = Robot_1.Robot;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@jibo/apptoolkit-library/lib/index.js.map
generated
vendored
Normal file
1
node_modules/@jibo/apptoolkit-library/lib/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,uCAAkC;AAK9B,kBALI,iBAAO,CAKJ;AAHX,mCAA8B;AAK1B,gBALI,aAAK,CAKJ"}
|
||||
Reference in New Issue
Block a user