Compare commits

...

28 Commits

Author SHA1 Message Date
Martín M
b3655b095d getRegion: use v2 API 2020-10-26 21:17:01 -03:00
Martín M
82f152d624 openWebSocket: use v2 API 2020-10-26 21:10:51 -03:00
Martín M
08e84b5fea updated dependencies 2020-10-26 20:48:41 -03:00
Martín M
979664dc34 getDeviceIP: refactor 2020-10-22 02:59:00 -03:00
Martín M
f81fd771a6 saveDevicesCache: use v2 API 2020-10-22 02:53:40 -03:00
Martín M
f2a39c34b4 checkDeviceUpdate: refactor 2020-10-22 02:50:54 -03:00
Martín M
646dfed03c checkDevicesUpdates: use v2 API 2020-10-22 02:44:07 -03:00
Martín M
4038c8c7bd checkDeviceUpdate: use v2 API 2020-10-22 02:18:53 -03:00
Martín M
9e7bef86ff getFirmwareVersion: use v2 API 2020-10-21 21:26:34 -03:00
Martín M
894aa6f5ca getDeviceChannelCount: use v2 API 2020-10-21 21:24:17 -03:00
Martín M
ad2d72f4ce setDevicePowerState: improved error handling 2020-10-21 21:19:01 -03:00
Martín M
e5242589f8 getDeviceCurrentTH: improved error handling 2020-10-21 21:18:21 -03:00
Martín M
bf6ab11590 toggleDevicePowerState: renamed to toggleDevicePowerState 2020-10-21 21:11:39 -03:00
Martín M
ac80e06b0f setDevicePowerState: use v2 API 2020-10-21 21:00:23 -03:00
Martín M
2a64768822 getDevicePowerState: use v2 API 2020-10-21 20:23:01 -03:00
Martín M
930cf2878c getDevices: improved error message 2020-10-21 20:12:50 -03:00
Martín M
996c678204 getDevices: use v2 API 2020-10-21 20:12:13 -03:00
Martín M
45b1c4363a DEV: update eslint + prettier + jest 2020-10-21 20:03:11 -03:00
Martín M
47fd13f105 getDevice: improved error message 2020-10-21 19:59:08 -03:00
Martín M
94b3bc084a makeRequest: improved error message 2020-10-21 19:58:51 -03:00
Martín M
9c00d8280a getDevice: use v2 API 2020-10-21 19:53:18 -03:00
Martín M
16772a5c54 makeRequest: improved error message 2020-10-21 19:53:18 -03:00
Martín M
03307994ea makeRequest: use v2 API 2020-10-21 19:53:18 -03:00
Martín M
d274a8d560 getCredentials: improved error message 2020-10-21 19:53:18 -03:00
Martín M
2f4716f379 getCredentials: fix getting api key and access token 2020-10-21 19:53:17 -03:00
Martín M
012d0ee092 getCredentials: use v2 API 2020-10-21 19:53:17 -03:00
Martín M
1109e70019 use v2 API URL 2020-10-21 19:53:17 -03:00
Martin M
5a07f6b615 Release v3.1.1 (#112)
* fix JSON parse error when device is offline (#111)

* add 503 error and fix makeRequest mixin when device is Offline or Service is unavailable

* add 503 error and fix makeRequest mixin when device is Offline or Service is unavailable

* version bump

Co-authored-by: Luigui Delyer <git@s1x.com.br>
2020-10-18 19:17:16 -03:00
23 changed files with 707 additions and 733 deletions

View File

@@ -75,7 +75,8 @@ class eWeLink {
* @returns {string}
*/
getApiUrl() {
return `https://${this.region}-api.coolkit.cc:8080/api`;
const domain = this.region === 'cn' ? 'cn' : 'cc';
return `https://${this.region}-apia.coolkit.${domain}`;
}
/**
@@ -95,6 +96,11 @@ class eWeLink {
return `wss://${this.region}-pconnect3.coolkit.cc:8080/api/ws`;
}
getDispatchServiceUrl() {
const domain = this.region === 'cn' ? 'cn' : 'cc';
return `https://${this.region}-dispa.coolkit.${domain}`;
}
/**
* Generate Zeroconf URL
* @param device

1032
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "ewelink-api",
"version": "3.1.0",
"version": "3.1.1",
"description": "eWeLink API for Node.js",
"author": "Martín M.",
"license": "MIT",
@@ -41,27 +41,28 @@
},
"dependencies": {
"arpping": "github:skydiver/arpping",
"compare-versions": "^3.6.0",
"crypto-js": "^4.0.0",
"delay": "^4.4.0",
"node-fetch": "^2.6.1",
"random": "^2.2.0",
"websocket": "^1.0.32",
"websocket-as-promised": "^1.0.1"
"websocket-as-promised": "^1.1.0"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.11.0",
"eslint": "^7.12.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.12.0",
"eslint-config-wesbos": "0.0.19",
"eslint-config-prettier": "^6.14.0",
"eslint-config-wesbos": "1.0.1",
"eslint-plugin-html": "^6.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.21.4",
"eslint-plugin-react-hooks": "^4.1.2",
"jest": "^26.5.3",
"nock": "^12.0.3",
"prettier": "^1.19.1"
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"jest": "^26.6.1",
"nock": "^13.0.4",
"prettier": "^2.1.2"
}
}

View File

@@ -5,15 +5,19 @@ const errors = {
403: 'Forbidden',
404: 'Device does not exist',
406: 'Authentication failed',
503: 'Service Temporarily Unavailable or Device is offline',
};
const customErrors = {
ch404: 'Device channel does not exist',
unknown: 'An unknown error occurred',
noARP: 'No ARP information found. You need to generate the ARP file.',
noDevice: 'No device found',
noDevices: 'No devices found',
noPower: 'No power usage data found',
noSensor: "Can't read sensor data from device",
noFirmware: "Can't get model or firmware version",
noFirmwares: "Can't find firmware update information",
invalidAuth: 'Library needs to be initialized using email and password',
invalidCredentials: 'Invalid credentials provided',
invalidPowerState: 'Invalid power state. Expecting: "on", "off" or "toggle"',

View File

@@ -1,5 +1,4 @@
const { _get } = require('../helpers/utilities');
const parseFirmwareUpdates = require('../parsers/parseFirmwareUpdates');
const errors = require('../data/errors');
module.exports = {
/**
@@ -10,39 +9,14 @@ module.exports = {
* @returns {Promise<{msg: string, version: *}|{msg: string, error: number}|{msg: string, error: *}|Device|{msg: string}>}
*/
async checkDeviceUpdate(deviceId) {
const device = await this.getDevice(deviceId);
const updates = await this.checkDevicesUpdates();
const error = _get(device, 'error', false);
const update = updates.find((device) => device.deviceId === deviceId);
if (error) {
return device;
if (!update) {
throw new Error(`${errors.noFirmware}`);
}
const deviceInfoList = parseFirmwareUpdates([device]);
const deviceInfoListError = _get(deviceInfoList, 'error', false);
if (deviceInfoListError) {
return deviceInfoList;
}
const update = await this.makeRequest({
method: 'post',
url: this.getOtaUrl(),
uri: '/app',
body: { deviceInfoList },
});
const isUpdate = _get(update, 'upgradeInfoList.0.version', false);
if (!isUpdate) {
return { status: 'ok', msg: 'No update available' };
}
return {
status: 'ok',
msg: 'Update available',
version: isUpdate,
};
return update;
},
};

View File

@@ -1,53 +1,42 @@
const { _get } = require('../helpers/utilities');
const compareVersions = require('compare-versions');
const parseFirmwareUpdates = require('../parsers/parseFirmwareUpdates');
const errors = require('../data/errors');
module.exports = {
async checkDevicesUpdates() {
const devices = await this.getDevices();
const error = _get(devices, 'error', false);
if (error) {
return devices;
}
const deviceInfoList = parseFirmwareUpdates(devices);
const deviceInfoListError = _get(deviceInfoList, 'error', false);
if (deviceInfoListError) {
return deviceInfoList;
}
const updates = await this.makeRequest({
method: 'post',
url: this.getOtaUrl(),
uri: '/app',
uri: '/v2/device/ota/query',
body: { deviceInfoList },
});
const upgradeInfoList = _get(updates, 'upgradeInfoList', false);
const { otaInfoList } = updates;
if (!upgradeInfoList) {
return { error: "Can't find firmware update information" };
if (!otaInfoList) {
throw new Error(`${errors.noFirmwares}`);
}
return upgradeInfoList.map(device => {
const upd = _get(device, 'version', false);
/** Get current versions */
const currentVersions = {};
deviceInfoList.forEach((device) => {
currentVersions[device.deviceid] = device.version;
});
if (!upd) {
return {
status: 'ok',
deviceId: device.deviceid,
msg: 'No update available',
};
}
return otaInfoList.map((device) => {
const current = currentVersions[device.deviceid];
const { version } = device;
const outdated = compareVersions(version, current);
return {
status: 'ok',
update: !!outdated,
deviceId: device.deviceid,
msg: 'Update available',
version: upd,
msg: outdated ? 'Update available' : 'No update available',
current,
version,
};
});
},

View File

@@ -1,54 +1,46 @@
const fetch = require('node-fetch');
const { _get } = require('../helpers/utilities');
const credentialsPayload = require('../payloads/credentialsPayload');
const { makeAuthorizationSign } = require('../helpers/ewelink');
const errors = require('../data/errors');
module.exports = {
/**
* Returns user credentials information
*
* @returns {Promise<{msg: string, error: *}>}
*/
async getCredentials() {
const { APP_ID, APP_SECRET } = this;
const body = credentialsPayload({
appid: APP_ID,
const body = {
countryCode: '+1',
email: this.email,
phoneNumber: this.phoneNumber,
password: this.password,
});
};
const request = await fetch(`${this.getApiUrl()}/user/login`, {
if (this.phoneNumber) {
body.phoneNumber = this.phoneNumber;
}
const request = await fetch(`${this.getApiUrl()}/v2/user/login`, {
method: 'post',
headers: {
Authorization: `Sign ${makeAuthorizationSign(APP_SECRET, body)}`,
'Content-Type': 'application/json',
'X-CK-Appid': APP_ID,
},
body: JSON.stringify(body),
});
let response = await request.json();
const response = await request.json();
const error = _get(response, 'error', false);
const region = _get(response, 'region', false);
if (error && [400, 401, 404].indexOf(parseInt(error)) !== -1) {
return { error: 406, msg: errors['406'] };
if (error) {
throw new Error(`[${error}] ${response.msg}`);
}
if (error && parseInt(error) === 301 && region) {
if (this.region !== region) {
this.region = region;
response = await this.getCredentials();
return response;
}
return { error, msg: 'Region does not exist' };
}
this.apiKey = _get(response, 'data.user.apikey', '');
this.at = _get(response, 'data.at', '');
this.apiKey = _get(response, 'user.apikey', '');
this.at = _get(response, 'at', '');
return response;
return response.data;
},
};

View File

@@ -1,4 +1,4 @@
const { nonce, timestamp, _get } = require('../helpers/utilities');
const { _get } = require('../helpers/utilities');
const errors = require('../data/errors');
module.exports = {
@@ -10,28 +10,27 @@ module.exports = {
*/
async getDevice(deviceId) {
if (this.devicesCache) {
return this.devicesCache.find(dev => dev.deviceid === deviceId) || null;
return this.devicesCache.find((dev) => dev.deviceid === deviceId) || null;
}
const { APP_ID } = this;
const device = await this.makeRequest({
uri: `/user/device/${deviceId}`,
qs: {
deviceid: deviceId,
appid: APP_ID,
nonce,
ts: timestamp,
version: 8,
method: 'post',
uri: `/v2/device/thing/`,
body: {
thingList: [{ id: deviceId, itemType: 1 }],
},
});
const error = _get(device, 'error', false);
if (error) {
return { error, msg: errors[error] };
throw new Error(`[${error}] ${errors[error]}`);
}
return device;
if (device.thingList.length === 0) {
throw new Error(`${errors.noDevice}`);
}
return device.thingList.shift().itemData;
},
};

View File

@@ -1,7 +1,4 @@
const { _get } = require('../helpers/utilities');
const errors = require('../data/errors');
const { getDeviceChannelCount } = require('../helpers/ewelink');
module.exports = {
/**
@@ -13,12 +10,18 @@ module.exports = {
*/
async getDeviceChannelCount(deviceId) {
const device = await this.getDevice(deviceId);
const error = _get(device, 'error', false);
const uiid = _get(device, 'extra.extra.uiid', false);
const switchesAmount = getDeviceChannelCount(uiid);
if (error) {
return { error, msg: errors[error] };
const paramSwitch = _get(device, 'params.switch', false);
const paramSwitches = _get(device, 'params.switches', false);
let switchesAmount;
if (paramSwitches) {
switchesAmount = paramSwitches.length;
}
if (!paramSwitches && paramSwitch) {
switchesAmount = 1;
}
return { status: 'ok', switchesAmount };

View File

@@ -10,16 +10,12 @@ module.exports = {
*/
async getDeviceCurrentTH(deviceId, type = '') {
const device = await this.getDevice(deviceId);
const error = _get(device, 'error', false);
const temperature = _get(device, 'params.currentTemperature', false);
const humidity = _get(device, 'params.currentHumidity', false);
if (error) {
return device;
}
if (!temperature || !humidity) {
return { error: 404, msg: errors.noSensor };
throw new Error(`${errors.noSensor}`);
}
const data = { status: 'ok', temperature, humidity };

View File

@@ -1,3 +1,5 @@
const errors = require('../data/errors');
module.exports = {
/**
* Get local IP address from a given MAC
@@ -6,10 +8,16 @@ module.exports = {
* @returns {Promise<string>}
*/
getDeviceIP(device) {
const mac = device.extra.extra.staMac;
if (!this.arpTable) {
throw new Error(errors.noARP);
}
const mac = device.extra.staMac;
const arpItem = this.arpTable.find(
item => item.mac.toLowerCase() === mac.toLowerCase()
(item) => item.mac.toLowerCase() === mac.toLowerCase()
);
return arpItem.ip;
},
};

View File

@@ -1,8 +1,6 @@
const { _get } = require('../helpers/utilities');
const errors = require('../data/errors');
const deviceStatusPayload = require('../payloads/deviceStatus');
module.exports = {
/**
* Get current power state for a specific device
@@ -14,19 +12,18 @@ module.exports = {
*/
async getDevicePowerState(deviceId, channel = 1) {
const status = await this.makeRequest({
uri: '/user/device/status',
qs: deviceStatusPayload({
appid: this.APP_ID,
deviceId,
uri: '/v2/device/thing/status',
qs: {
type: 1,
id: deviceId,
params: 'switch|switches',
}),
},
});
const error = _get(status, 'error', false);
if (error) {
const err = error === 400 ? 404 : error;
return { error: err, msg: errors[err] };
throw new Error(`[${error}] ${errors[error]}`);
}
let state = _get(status, 'params.switch', false);
@@ -35,7 +32,7 @@ module.exports = {
const switchesAmount = switches ? switches.length : 1;
if (switchesAmount > 0 && switchesAmount < channel) {
return { error: 404, msg: errors.ch404 };
throw new Error(`${errors.ch404}`);
}
if (switches) {

View File

@@ -1,4 +1,4 @@
const { _get, timestamp } = require('../helpers/utilities');
const { _get } = require('../helpers/utilities');
const errors = require('../data/errors');
module.exports = {
@@ -8,30 +8,21 @@ module.exports = {
* @returns {Promise<{msg: string, error: number}|*>}
*/
async getDevices() {
const { APP_ID } = this;
const response = await this.makeRequest({
uri: '/user/device',
qs: {
lang: 'en',
appid: APP_ID,
ts: timestamp,
version: 8,
getTags: 1,
},
uri: `/v2/device/thing/`,
});
const error = _get(response, 'error', false);
const devicelist = _get(response, 'devicelist', false);
const thingList = _get(response, 'thingList', false);
if (error) {
return { error, msg: errors[error] };
throw new Error(`[${error}] ${errors[error]}`);
}
if (!devicelist) {
return { error: 404, msg: errors.noDevices };
if (!thingList) {
throw new Error(`${errors.noDevices}`);
}
return devicelist;
return thingList.map((thing) => thing.itemData);
},
};

View File

@@ -11,11 +11,11 @@ module.exports = {
*/
async getFirmwareVersion(deviceId) {
const device = await this.getDevice(deviceId);
const error = _get(device, 'error', false);
const fwVersion = _get(device, 'params.fwVersion', false);
if (error || !fwVersion) {
return { error, msg: errors[error] };
if (!fwVersion) {
throw new Error(`${errors.noFirmware}`);
}
return { status: 'ok', fwVersion };

View File

@@ -3,16 +3,12 @@ const errors = require('../data/errors');
module.exports = {
async getRegion() {
if (!this.email || !this.password) {
return { error: 406, msg: errors.invalidAuth };
}
const credentials = await this.getCredentials();
const error = _get(credentials, 'error', false);
if (error) {
return credentials;
throw new Error(`[${error}] ${errors[error]}`);
}
return {

View File

@@ -13,10 +13,10 @@ const { getDevices } = require('./getDevices');
const { getFirmwareVersion } = require('./getFirmwareVersion');
const { getRegion } = require('./getRegion');
const { makeRequest } = require('./makeRequest');
const { openWebSocket } = require('./openWebSocket');
const openWebSocket = require('./openWebSocket');
const { saveDevicesCache } = require('./saveDevicesCache');
const { setDevicePowerState } = require('./setDevicePowerState');
const { toggleDevice } = require('./toggleDevice');
const { toggleDevicePowerState } = require('./toggleDevicePowerState');
const mixins = {
checkDevicesUpdates,
@@ -34,10 +34,10 @@ const mixins = {
getFirmwareVersion,
getRegion,
makeRequest,
openWebSocket,
...openWebSocket,
saveDevicesCache,
setDevicePowerState,
toggleDevice,
toggleDevicePowerState,
};
module.exports = mixins;

View File

@@ -14,7 +14,7 @@ module.exports = {
* @returns {Promise<{msg: *, error: *}|*>}
*/
async makeRequest({ method = 'get', url, uri, body = {}, qs = {} }) {
const { at } = this;
const { at, APP_ID } = this;
if (!at) {
await this.getCredentials();
@@ -31,6 +31,7 @@ module.exports = {
headers: {
Authorization: `Bearer ${this.at}`,
'Content-Type': 'application/json',
'X-CK-Appid': APP_ID,
},
};
@@ -42,14 +43,24 @@ module.exports = {
const requestUrl = `${apiUrl}${uri}${queryString}`;
const request = await fetch(requestUrl, payload);
const response = await request.json();
const error = _get(response, 'error', false);
if (error) {
return { error, msg: errors[error] };
/** Catch request status code other than 200 */
if (!request.ok) {
throw new Error(`[${request.status}] ${errors[request.status]}`);
}
return response;
/** Parse API response */
const response = await request.json();
/** Catch errors with status code 200 */
const error = _get(response, 'error', false);
/** Throw error if needed */
if (error) {
throw new Error(`[${error}] ${response.msg}`);
}
/** Return response data */
return response.data;
},
};

View File

@@ -1,7 +1,9 @@
const fetch = require('node-fetch');
const W3CWebSocket = require('websocket').w3cwebsocket;
const WebSocketAsPromised = require('websocket-as-promised');
const wssLoginPayload = require('../payloads/wssLoginPayload');
const errors = require('../data/errors');
module.exports = {
/**
@@ -13,17 +15,20 @@ module.exports = {
* @returns {Promise<WebSocketAsPromised>}
*/
async openWebSocket(callback, ...{ heartbeat = 120000 }) {
const dispatch = await this.getWebSocketServer();
const WSS_URL = `wss://${dispatch.domain}:${dispatch.port}/api/ws`;
const payloadLogin = wssLoginPayload({
at: this.at,
apiKey: this.apiKey,
appid: this.APP_ID,
});
const wsp = new WebSocketAsPromised(this.getApiWebSocket(), {
createWebSocket: wss => new W3CWebSocket(wss),
const wsp = new WebSocketAsPromised(WSS_URL, {
createWebSocket: (wss) => new W3CWebSocket(wss),
});
wsp.onMessage.addListener(message => {
wsp.onMessage.addListener((message) => {
try {
const data = JSON.parse(message);
callback(data);
@@ -41,4 +46,15 @@ module.exports = {
return wsp;
},
async getWebSocketServer() {
const requestUrl = this.getDispatchServiceUrl();
const request = await fetch(`${requestUrl}/dispatch/app`);
if (!request.ok) {
throw new Error(`[${request.status}] ${errors[request.status]}`);
}
return request.json();
},
};

View File

@@ -1,7 +1,5 @@
const fs = require('fs');
const { _get } = require('../helpers/utilities');
module.exports = {
/**
* Save devices cache file (useful for using zeroconf)
@@ -10,20 +8,13 @@ module.exports = {
async saveDevicesCache(fileName = './devices-cache.json') {
const devices = await this.getDevices();
const error = _get(devices, 'error', false);
if (error || !devices) {
return devices;
}
const jsonContent = JSON.stringify(devices, null, 2);
try {
fs.writeFileSync(fileName, jsonContent, 'utf8');
return { status: 'ok', file: fileName };
} catch (e) {
console.log('An error occured while writing JSON Object to File.');
return { error: e.toString() };
throw new Error('An error occured while writing JSON Object to File.');
}
},
};

View File

@@ -1,10 +1,6 @@
const { _get, timestamp, nonce } = require('../helpers/utilities');
const { _get } = require('../helpers/utilities');
const errors = require('../data/errors');
const { getDeviceChannelCount } = require('../helpers/ewelink');
const ChangeStateZeroconf = require('../classes/ChangeStateZeroconf');
module.exports = {
/**
* Change power state for a specific device
@@ -17,20 +13,14 @@ module.exports = {
*/
async setDevicePowerState(deviceId, state, channel = 1) {
const device = await this.getDevice(deviceId);
const error = _get(device, 'error', false);
const uiid = _get(device, 'extra.extra.uiid', false);
let status = _get(device, 'params.switch', false);
const switches = _get(device, 'params.switches', false);
const switchesAmount = getDeviceChannelCount(uiid);
const switchesAmount = switches.length;
if (switchesAmount > 0 && switchesAmount < channel) {
return { error: 404, msg: errors.ch404 };
}
if (error || (!status && !switches)) {
return { error, msg: errors[error] };
throw new Error(`${errors.ch404}`);
}
let stateToSwitch = state;
@@ -51,35 +41,31 @@ module.exports = {
params.switch = stateToSwitch;
}
if (this.devicesCache) {
return ChangeStateZeroconf.set({
url: this.getZeroconfUrl(device),
device,
params,
switches,
state: stateToSwitch,
});
}
const { APP_ID } = this;
// DISABLED DURING v4.0.0 DEVELOPMENT
// if (this.devicesCache) {
// return ChangeStateZeroconf.set({
// url: this.getZeroconfUrl(device),
// device,
// params,
// switches,
// state: stateToSwitch,
// });
// }
const response = await this.makeRequest({
method: 'post',
uri: '/user/device/status',
uri: '/v2/device/thing/status',
body: {
deviceid: deviceId,
type: 1,
id: deviceId,
params,
appid: APP_ID,
nonce,
ts: timestamp,
version: 8,
},
});
const responseError = _get(response, 'error', false);
if (responseError) {
return { error: responseError, msg: errors[responseError] };
throw new Error(`[${error}] ${errors[error]}`);
}
return { status: 'ok', state, channel };

View File

@@ -7,7 +7,7 @@ module.exports = {
*
* @returns {Promise<{state: *, status: string}|{msg: string, error: *}>}
*/
async toggleDevice(deviceId, channel = 1) {
async toggleDevicePowerState(deviceId, channel = 1) {
return this.setDevicePowerState(deviceId, 'toggle', channel);
},
};

View File

@@ -1,13 +1,13 @@
const { _get } = require('../helpers/utilities');
const errors = require('../data/errors');
const parseFirmwareUpdates = devicesList =>
devicesList.map(device => {
const model = _get(device, 'extra.extra.model', false);
const parseFirmwareUpdates = (devicesList) =>
devicesList.map((device) => {
const model = _get(device, 'extra.model', false);
const fwVersion = _get(device, 'params.fwVersion', false);
if (!model || !fwVersion) {
return { error: 500, msg: errors.noFirmware };
throw new Error(`${errors.noFirmware}`);
}
return { model, version: fwVersion, deviceid: device.deviceid };

View File

@@ -3,14 +3,14 @@ const { timestamp, nonce } = require('../helpers/utilities');
const wssLoginPayload = ({ at, apiKey, appid }) => {
const payload = {
action: 'userOnline',
version: 8,
ts: timestamp,
at,
userAgent: 'app',
apikey: apiKey,
appid,
nonce,
ts: timestamp,
userAgent: 'app',
sequence: Math.floor(timestamp * 1000),
version: 8,
};
return JSON.stringify(payload);