(1.0.10) attempt add bluetooth
This commit is contained in:
56
dist/index.cjs.js
vendored
56
dist/index.cjs.js
vendored
@@ -2,13 +2,24 @@
|
|||||||
|
|
||||||
var parseXml = require('@rgrove/parse-xml');
|
var parseXml = require('@rgrove/parse-xml');
|
||||||
|
|
||||||
|
/// <reference types="cordova-plugin-ble-central" />
|
||||||
class Updater {
|
class Updater {
|
||||||
archiveURL;
|
archiveURL;
|
||||||
feedType;
|
feedType;
|
||||||
constructor(archiveURL = "/", feedType = "atom") {
|
bleObject;
|
||||||
|
bleDeviceId;
|
||||||
|
_updaterServiceUUID = "71a4438e-fd52-4b15-b3d2-ec0e3e56193b";
|
||||||
|
_updaterVersionCharactersiticUUID = "1978a3df-c009-4837-b295-57ef429dde8c";
|
||||||
|
constructor(archiveURL = "/", feedType = "atom", bleObject) {
|
||||||
this.archiveURL = archiveURL;
|
this.archiveURL = archiveURL;
|
||||||
this.feedType = feedType;
|
this.feedType = feedType;
|
||||||
|
if (bleObject) {
|
||||||
|
this.bleObject = bleObject;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
FEEDS
|
||||||
|
*/
|
||||||
async getRawArchive() {
|
async getRawArchive() {
|
||||||
const res = await fetch(`http://cors.emaker.limited/?url=${this.archiveURL}.${this.feedType}`, {
|
const res = await fetch(`http://cors.emaker.limited/?url=${this.archiveURL}.${this.feedType}`, {
|
||||||
// "mode": "cors"
|
// "mode": "cors"
|
||||||
@@ -79,7 +90,7 @@ class Updater {
|
|||||||
if (elm.type == "element") {
|
if (elm.type == "element") {
|
||||||
const element = elm;
|
const element = elm;
|
||||||
if (element.name == "item") {
|
if (element.name == "item") {
|
||||||
output.push(this.atomGetVersionDetails(element));
|
output.push(this.rssGetVersionDetails(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -93,6 +104,47 @@ class Updater {
|
|||||||
return this.rssGetArchive();
|
return this.rssGetArchive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
BLUETOOTH
|
||||||
|
*/
|
||||||
|
setDeviceId(id) {
|
||||||
|
this.bleDeviceId = id;
|
||||||
|
}
|
||||||
|
bytesToString(buffer) {
|
||||||
|
return String.fromCharCode.apply(null, new Uint8Array(buffer));
|
||||||
|
}
|
||||||
|
async readVersionNumber() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.bleObject.read(this.bleDeviceId, this._updaterServiceUUID, this._updaterVersionCharactersiticUUID, (rawData) => {
|
||||||
|
resolve(this.bytesToString(rawData));
|
||||||
|
}, (error) => {
|
||||||
|
reject(`Error: ${error}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async getLatestVersion() {
|
||||||
|
let feed = await this.getArchive();
|
||||||
|
let newestDate = feed[0].date;
|
||||||
|
let i = 0;
|
||||||
|
feed.forEach((item, index) => {
|
||||||
|
if (item.date > newestDate) {
|
||||||
|
newestDate = item.date;
|
||||||
|
i = index;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return feed[i].title;
|
||||||
|
}
|
||||||
|
async checkForUpdate() {
|
||||||
|
// read device value
|
||||||
|
const deviceVersion = await this.readVersionNumber();
|
||||||
|
// compare with latest version
|
||||||
|
const latestVersion = await this.getLatestVersion();
|
||||||
|
if (deviceVersion != latestVersion) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// update
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Updater;
|
module.exports = Updater;
|
||||||
|
|||||||
11
dist/index.d.ts
vendored
11
dist/index.d.ts
vendored
@@ -7,11 +7,20 @@ export type versionNotes = {
|
|||||||
export default class Updater {
|
export default class Updater {
|
||||||
archiveURL: string;
|
archiveURL: string;
|
||||||
feedType: string;
|
feedType: string;
|
||||||
constructor(archiveURL?: string, feedType?: string);
|
bleObject: BLECentralPlugin.BLECentralPluginStatic;
|
||||||
|
protected bleDeviceId: string;
|
||||||
|
private readonly _updaterServiceUUID;
|
||||||
|
private readonly _updaterVersionCharactersiticUUID;
|
||||||
|
constructor(archiveURL?: string, feedType?: string, bleObject?: BLECentralPlugin.BLECentralPluginStatic);
|
||||||
private getRawArchive;
|
private getRawArchive;
|
||||||
private atomGetVersionDetails;
|
private atomGetVersionDetails;
|
||||||
private atomGetArchive;
|
private atomGetArchive;
|
||||||
private rssGetVersionDetails;
|
private rssGetVersionDetails;
|
||||||
private rssGetArchive;
|
private rssGetArchive;
|
||||||
getArchive(): Promise<versionNotes[]>;
|
getArchive(): Promise<versionNotes[]>;
|
||||||
|
setDeviceId(id: string): void;
|
||||||
|
private bytesToString;
|
||||||
|
private readVersionNumber;
|
||||||
|
private getLatestVersion;
|
||||||
|
checkForUpdate(): Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|||||||
56
dist/index.es.js
vendored
56
dist/index.es.js
vendored
@@ -1,12 +1,23 @@
|
|||||||
import { parseXml } from '@rgrove/parse-xml';
|
import { parseXml } from '@rgrove/parse-xml';
|
||||||
|
|
||||||
|
/// <reference types="cordova-plugin-ble-central" />
|
||||||
class Updater {
|
class Updater {
|
||||||
archiveURL;
|
archiveURL;
|
||||||
feedType;
|
feedType;
|
||||||
constructor(archiveURL = "/", feedType = "atom") {
|
bleObject;
|
||||||
|
bleDeviceId;
|
||||||
|
_updaterServiceUUID = "71a4438e-fd52-4b15-b3d2-ec0e3e56193b";
|
||||||
|
_updaterVersionCharactersiticUUID = "1978a3df-c009-4837-b295-57ef429dde8c";
|
||||||
|
constructor(archiveURL = "/", feedType = "atom", bleObject) {
|
||||||
this.archiveURL = archiveURL;
|
this.archiveURL = archiveURL;
|
||||||
this.feedType = feedType;
|
this.feedType = feedType;
|
||||||
|
if (bleObject) {
|
||||||
|
this.bleObject = bleObject;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
FEEDS
|
||||||
|
*/
|
||||||
async getRawArchive() {
|
async getRawArchive() {
|
||||||
const res = await fetch(`http://cors.emaker.limited/?url=${this.archiveURL}.${this.feedType}`, {
|
const res = await fetch(`http://cors.emaker.limited/?url=${this.archiveURL}.${this.feedType}`, {
|
||||||
// "mode": "cors"
|
// "mode": "cors"
|
||||||
@@ -77,7 +88,7 @@ class Updater {
|
|||||||
if (elm.type == "element") {
|
if (elm.type == "element") {
|
||||||
const element = elm;
|
const element = elm;
|
||||||
if (element.name == "item") {
|
if (element.name == "item") {
|
||||||
output.push(this.atomGetVersionDetails(element));
|
output.push(this.rssGetVersionDetails(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -91,6 +102,47 @@ class Updater {
|
|||||||
return this.rssGetArchive();
|
return this.rssGetArchive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
BLUETOOTH
|
||||||
|
*/
|
||||||
|
setDeviceId(id) {
|
||||||
|
this.bleDeviceId = id;
|
||||||
|
}
|
||||||
|
bytesToString(buffer) {
|
||||||
|
return String.fromCharCode.apply(null, new Uint8Array(buffer));
|
||||||
|
}
|
||||||
|
async readVersionNumber() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.bleObject.read(this.bleDeviceId, this._updaterServiceUUID, this._updaterVersionCharactersiticUUID, (rawData) => {
|
||||||
|
resolve(this.bytesToString(rawData));
|
||||||
|
}, (error) => {
|
||||||
|
reject(`Error: ${error}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async getLatestVersion() {
|
||||||
|
let feed = await this.getArchive();
|
||||||
|
let newestDate = feed[0].date;
|
||||||
|
let i = 0;
|
||||||
|
feed.forEach((item, index) => {
|
||||||
|
if (item.date > newestDate) {
|
||||||
|
newestDate = item.date;
|
||||||
|
i = index;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return feed[i].title;
|
||||||
|
}
|
||||||
|
async checkForUpdate() {
|
||||||
|
// read device value
|
||||||
|
const deviceVersion = await this.readVersionNumber();
|
||||||
|
// compare with latest version
|
||||||
|
const latestVersion = await this.getLatestVersion();
|
||||||
|
if (deviceVersion != latestVersion) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// update
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Updater as default };
|
export { Updater as default };
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "updaterweblibrary",
|
"name": "updaterweblibrary",
|
||||||
"version": "1.0.9",
|
"version": "1.0.10",
|
||||||
"description": "OTA Updater App frontend library",
|
"description": "OTA Updater App frontend library",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user