incyclist-devices 2.2.9 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/antv2/base/interface.js +2 -2
- package/lib/antv2/factories/index.d.ts +1 -0
- package/lib/antv2/factories/index.js +17 -0
- package/lib/antv2/fe/adapter.js +5 -4
- package/lib/antv2/index.d.ts +1 -0
- package/lib/antv2/index.js +12 -8
- package/lib/base/adpater.js +1 -1
- package/lib/ble/adapter-factory.d.ts +20 -24
- package/lib/ble/adapter-factory.js +13 -36
- package/lib/ble/base/adapter.d.ts +16 -5
- package/lib/ble/base/adapter.js +169 -52
- package/lib/ble/base/comms.d.ts +2 -74
- package/lib/ble/base/comms.js +3 -596
- package/lib/ble/base/interface.d.ts +96 -0
- package/lib/ble/base/interface.js +544 -0
- package/lib/ble/base/peripheral.d.ts +34 -0
- package/lib/ble/base/peripheral.js +286 -0
- package/lib/ble/base/sensor.d.ts +31 -0
- package/lib/ble/base/sensor.js +130 -0
- package/lib/ble/base/types.d.ts +7 -0
- package/lib/ble/base/types.js +7 -0
- package/lib/ble/bindings/mock.js +6 -0
- package/lib/ble/bindings/types.d.ts +3 -4
- package/lib/ble/ble-interface.d.ts +7 -4
- package/lib/ble/ble-interface.js +16 -2
- package/lib/ble/ble-peripheral.d.ts +1 -0
- package/lib/ble/ble-peripheral.js +7 -11
- package/lib/ble/consts.d.ts +0 -6
- package/lib/ble/consts.js +1 -7
- package/lib/ble/cp/adapter.d.ts +3 -3
- package/lib/ble/cp/adapter.js +12 -13
- package/lib/ble/cp/comm.d.ts +1 -1
- package/lib/ble/cp/comm.js +2 -2
- package/lib/ble/cp/index.d.ts +1 -1
- package/lib/ble/cp/index.js +2 -2
- package/lib/ble/cp/sensor.d.ts +27 -0
- package/lib/ble/cp/sensor.js +107 -0
- package/lib/ble/elite/comms.d.ts +1 -1
- package/lib/ble/elite/comms.js +2 -2
- package/lib/ble/factories/adapter-factory.d.ts +32 -0
- package/lib/ble/factories/adapter-factory.js +104 -0
- package/lib/ble/factories/index.d.ts +2 -0
- package/lib/ble/factories/index.js +18 -0
- package/lib/ble/factories/interface-factory.d.ts +7 -0
- package/lib/ble/factories/interface-factory.js +18 -0
- package/lib/ble/fm/adapter.d.ts +9 -4
- package/lib/ble/fm/adapter.js +104 -108
- package/lib/ble/fm/comms.d.ts +1 -1
- package/lib/ble/fm/comms.js +3 -3
- package/lib/ble/fm/consts.d.ts +93 -0
- package/lib/ble/fm/consts.js +55 -1
- package/lib/ble/fm/index.d.ts +1 -1
- package/lib/ble/fm/index.js +2 -2
- package/lib/ble/fm/sensor.d.ts +44 -0
- package/lib/ble/fm/sensor.js +384 -0
- package/lib/ble/hr/adapter.d.ts +3 -3
- package/lib/ble/hr/adapter.js +5 -8
- package/lib/ble/hr/comm.d.ts +1 -1
- package/lib/ble/hr/comm.js +2 -2
- package/lib/ble/hr/index.d.ts +1 -1
- package/lib/ble/hr/index.js +2 -2
- package/lib/ble/hr/sensor.d.ts +17 -0
- package/lib/ble/hr/sensor.js +52 -0
- package/lib/ble/index.d.ts +4 -3
- package/lib/ble/index.js +29 -13
- package/lib/ble/tacx/adapter.d.ts +4 -2
- package/lib/ble/tacx/adapter.js +26 -66
- package/lib/ble/tacx/comms.d.ts +1 -1
- package/lib/ble/tacx/comms.js +2 -2
- package/lib/ble/tacx/consts.d.ts +23 -0
- package/lib/ble/tacx/consts.js +27 -0
- package/lib/ble/tacx/index.d.ts +1 -1
- package/lib/ble/tacx/index.js +2 -2
- package/lib/ble/tacx/sensor.d.ts +63 -0
- package/lib/ble/tacx/sensor.js +596 -0
- package/lib/ble/types.d.ts +81 -52
- package/lib/ble/utils.d.ts +7 -2
- package/lib/ble/utils.js +84 -9
- package/lib/ble/wahoo/adapter.d.ts +2 -2
- package/lib/ble/wahoo/adapter.js +4 -72
- package/lib/ble/wahoo/comms.d.ts +1 -1
- package/lib/ble/wahoo/comms.js +2 -2
- package/lib/ble/wahoo/consts.d.ts +16 -0
- package/lib/ble/wahoo/consts.js +7 -0
- package/lib/ble/wahoo/index.d.ts +1 -1
- package/lib/ble/wahoo/index.js +2 -2
- package/lib/ble/wahoo/sensor.d.ts +48 -0
- package/lib/ble/wahoo/sensor.js +356 -0
- package/lib/direct-connect/base/comms.d.ts +3 -0
- package/lib/direct-connect/base/comms.js +7 -0
- package/lib/direct-connect/base/interface.d.ts +75 -0
- package/lib/direct-connect/base/interface.js +306 -0
- package/lib/direct-connect/base/peripheral.d.ts +50 -0
- package/lib/direct-connect/base/peripheral.js +413 -0
- package/lib/direct-connect/base/sensor.d.ts +3 -0
- package/lib/direct-connect/base/sensor.js +7 -0
- package/lib/direct-connect/bindings/index.d.ts +1 -0
- package/lib/direct-connect/bindings/index.js +17 -0
- package/lib/direct-connect/bindings/types.d.ts +36 -0
- package/lib/direct-connect/bindings/types.js +2 -0
- package/lib/direct-connect/consts.d.ts +17 -0
- package/lib/direct-connect/consts.js +20 -0
- package/lib/direct-connect/index.d.ts +3 -0
- package/lib/direct-connect/index.js +22 -0
- package/lib/direct-connect/messages/CharacteristicNotification.d.ts +12 -0
- package/lib/direct-connect/messages/CharacteristicNotification.js +23 -0
- package/lib/direct-connect/messages/DiscoverCharacteristics.d.ts +22 -0
- package/lib/direct-connect/messages/DiscoverCharacteristics.js +43 -0
- package/lib/direct-connect/messages/DiscoverServices.d.ts +15 -0
- package/lib/direct-connect/messages/DiscoverServices.js +33 -0
- package/lib/direct-connect/messages/EnableCharacteristicNotifications.d.ts +18 -0
- package/lib/direct-connect/messages/EnableCharacteristicNotifications.js +35 -0
- package/lib/direct-connect/messages/ReadCharacteristic.d.ts +18 -0
- package/lib/direct-connect/messages/ReadCharacteristic.js +34 -0
- package/lib/direct-connect/messages/WriteCharacteristic.d.ts +18 -0
- package/lib/direct-connect/messages/WriteCharacteristic.js +36 -0
- package/lib/direct-connect/messages/error.d.ts +5 -0
- package/lib/direct-connect/messages/error.js +18 -0
- package/lib/direct-connect/messages/factory.d.ts +6 -0
- package/lib/direct-connect/messages/factory.js +44 -0
- package/lib/direct-connect/messages/index.d.ts +9 -0
- package/lib/direct-connect/messages/index.js +25 -0
- package/lib/direct-connect/messages/message.d.ts +20 -0
- package/lib/direct-connect/messages/message.js +90 -0
- package/lib/direct-connect/types.d.ts +24 -0
- package/lib/direct-connect/types.js +9 -0
- package/lib/direct-connect/utils.d.ts +5 -0
- package/lib/direct-connect/utils.js +73 -0
- package/lib/factories/adapters.js +16 -4
- package/lib/factories/interfaces.d.ts +2 -1
- package/lib/factories/interfaces.js +10 -7
- package/lib/index.d.ts +5 -4
- package/lib/index.js +6 -2
- package/lib/serial/bindings/tcp.d.ts +5 -4
- package/lib/serial/bindings/tcp.js +16 -23
- package/lib/types/device.d.ts +2 -1
- package/lib/types/device.js +1 -0
- package/lib/utils/operation.d.ts +17 -0
- package/lib/utils/operation.js +20 -0
- package/lib/utils/task.d.ts +44 -0
- package/lib/utils/task.js +127 -0
- package/package.json +3 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { INTERFACE } from './types/device';
|
|
1
|
+
import { INTERFACE, DeviceSettings, DeviceProperties } from './types/device';
|
|
2
2
|
import { IncyclistInterface, InterfaceProps } from './types/interface';
|
|
3
3
|
import { IncyclistCapability } from './types/capabilities';
|
|
4
4
|
import { IncyclistAdapterData } from './types/data';
|
|
5
|
-
import { DeviceSettings, DeviceProperties } from './types/device';
|
|
6
5
|
import ICyclingMode from './modes/types';
|
|
7
6
|
import calc from './utils/calculations';
|
|
8
7
|
import IncyclistDevice, { IncyclistDeviceAdapter } from './base/adpater';
|
|
9
8
|
import { IAdapter } from './types/adapter';
|
|
10
|
-
|
|
9
|
+
import AdapterFactory from './factories/adapters';
|
|
10
|
+
import InterfaceFactory from './factories/interfaces';
|
|
11
11
|
export * from './modes/types';
|
|
12
12
|
export * from './serial';
|
|
13
13
|
export * from './ble';
|
|
14
14
|
export * from './antv2';
|
|
15
|
-
export
|
|
15
|
+
export * from './direct-connect';
|
|
16
|
+
export { IAdapter, IncyclistDevice, IncyclistDeviceAdapter, DeviceSettings, DeviceProperties, AdapterFactory, InterfaceFactory, IncyclistInterface, INTERFACE, InterfaceProps, ICyclingMode, IncyclistAdapterData as DeviceData, IncyclistCapability, calc, };
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.calc = exports.IncyclistCapability = exports.INTERFACE = exports.IncyclistDevice = void 0;
|
|
20
|
+
exports.calc = exports.IncyclistCapability = exports.INTERFACE = exports.InterfaceFactory = exports.AdapterFactory = exports.IncyclistDevice = void 0;
|
|
21
21
|
const device_1 = require("./types/device");
|
|
22
22
|
Object.defineProperty(exports, "INTERFACE", { enumerable: true, get: function () { return device_1.INTERFACE; } });
|
|
23
23
|
const capabilities_1 = require("./types/capabilities");
|
|
@@ -26,8 +26,12 @@ const calculations_1 = __importDefault(require("./utils/calculations"));
|
|
|
26
26
|
exports.calc = calculations_1.default;
|
|
27
27
|
const adpater_1 = __importDefault(require("./base/adpater"));
|
|
28
28
|
exports.IncyclistDevice = adpater_1.default;
|
|
29
|
-
|
|
29
|
+
const adapters_1 = __importDefault(require("./factories/adapters"));
|
|
30
|
+
exports.AdapterFactory = adapters_1.default;
|
|
31
|
+
const interfaces_1 = __importDefault(require("./factories/interfaces"));
|
|
32
|
+
exports.InterfaceFactory = interfaces_1.default;
|
|
30
33
|
__exportStar(require("./modes/types"), exports);
|
|
31
34
|
__exportStar(require("./serial"), exports);
|
|
32
35
|
__exportStar(require("./ble"), exports);
|
|
33
36
|
__exportStar(require("./antv2"), exports);
|
|
37
|
+
__exportStar(require("./direct-connect"), exports);
|
|
@@ -6,6 +6,7 @@ export interface TCPOpenOptions extends OpenOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export declare interface TCPBindingInterface<T extends BindingPortInterface = BindingPortInterface, R extends OpenOptions = OpenOptions, P extends PortInfo = PortInfo> extends BindingInterface<TCPPortBinding, TCPOpenOptions> {
|
|
8
8
|
list(port?: number, excludeList?: string[]): Promise<P[]>;
|
|
9
|
+
open(options: TCPOpenOptions): Promise<TCPPortBinding>;
|
|
9
10
|
}
|
|
10
11
|
export declare class CanceledError extends Error {
|
|
11
12
|
canceled: true;
|
|
@@ -22,10 +23,10 @@ export declare class TCPPortBinding implements BindingPortInterface {
|
|
|
22
23
|
writeOperation: null | Promise<any>;
|
|
23
24
|
data: Buffer;
|
|
24
25
|
private pendingRead;
|
|
25
|
-
private onDataHandler;
|
|
26
|
-
private onErrorHandler;
|
|
27
|
-
private onTimeoutHandler;
|
|
28
|
-
private onCloseHandler;
|
|
26
|
+
private readonly onDataHandler;
|
|
27
|
+
private readonly onErrorHandler;
|
|
28
|
+
private readonly onTimeoutHandler;
|
|
29
|
+
private readonly onCloseHandler;
|
|
29
30
|
constructor(socket: net.Socket, options: Required<OpenOptions>);
|
|
30
31
|
get isOpen(): boolean;
|
|
31
32
|
onData(data: Buffer): void;
|
|
@@ -55,23 +55,13 @@ function scanPort(host, port) {
|
|
|
55
55
|
function scanSubNet(sn, port, excludeHosts) {
|
|
56
56
|
const range = [];
|
|
57
57
|
for (let i = 1; i < 255; i++)
|
|
58
|
-
if (!excludeHosts ||
|
|
58
|
+
if (!(excludeHosts === null || excludeHosts === void 0 ? void 0 : excludeHosts.includes(`${sn}.${i}`)))
|
|
59
59
|
range.push(i);
|
|
60
60
|
return Promise.all(range.map(j => scanPort(`${sn}.${j}`, port).then(success => success ? `${sn}.${j}` : null).catch()))
|
|
61
61
|
.then(hosts => hosts.filter(h => h !== null))
|
|
62
62
|
.catch();
|
|
63
63
|
}
|
|
64
64
|
function getSubnets() {
|
|
65
|
-
const nets = (0, os_1.networkInterfaces)();
|
|
66
|
-
const results = [];
|
|
67
|
-
const names = Object.keys(nets);
|
|
68
|
-
names.forEach(name => {
|
|
69
|
-
for (const net of nets[name]) {
|
|
70
|
-
if (net.family === 'IPv4' && !net.internal) {
|
|
71
|
-
results.push(net.address);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
65
|
const address = Object.keys((0, os_1.networkInterfaces)())
|
|
76
66
|
.reduce((a, key) => [
|
|
77
67
|
...a,
|
|
@@ -93,7 +83,7 @@ exports.TCPBinding = {
|
|
|
93
83
|
return [];
|
|
94
84
|
const subnets = getSubnets();
|
|
95
85
|
let hosts = [];
|
|
96
|
-
const excludeHosts = excludeList.map(e => e
|
|
86
|
+
const excludeHosts = excludeList.map(e => (e === null || e === void 0 ? void 0 : e.includes(':')) ? e.split(':')[0] : e);
|
|
97
87
|
yield Promise.all(subnets.map(sn => scanSubNet(sn, port, excludeHosts).then(found => { hosts.push(...found); })));
|
|
98
88
|
return hosts.map(host => ({
|
|
99
89
|
path: `${host}:${port}`,
|
|
@@ -253,17 +243,20 @@ class TCPPortBinding {
|
|
|
253
243
|
if (!this.isOpen) {
|
|
254
244
|
throw new Error('Port is not open');
|
|
255
245
|
}
|
|
256
|
-
this.writeOperation = new Promise((resolve
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
246
|
+
this.writeOperation = new Promise((resolve) => {
|
|
247
|
+
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
yield resolveNextTick();
|
|
249
|
+
try {
|
|
250
|
+
this.socket.write(buffer, () => {
|
|
251
|
+
resolve();
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
this.onError(err);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
run();
|
|
259
|
+
});
|
|
267
260
|
return this.writeOperation;
|
|
268
261
|
}
|
|
269
262
|
update(options) {
|
package/lib/types/device.d.ts
CHANGED
package/lib/types/device.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface TaskState {
|
|
2
|
+
isRunning: boolean;
|
|
3
|
+
timeout?: NodeJS.Timeout;
|
|
4
|
+
onTimeout: () => void;
|
|
5
|
+
promise: Promise<any>;
|
|
6
|
+
}
|
|
7
|
+
export interface TaskProps {
|
|
8
|
+
timeout?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class Task<T extends TaskState> {
|
|
11
|
+
protected _state: T;
|
|
12
|
+
constructor(_state: T, props: TaskProps);
|
|
13
|
+
get state(): T;
|
|
14
|
+
get promise(): Promise<any>;
|
|
15
|
+
start(promise: Promise<any>): void;
|
|
16
|
+
isRunning(): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Task = void 0;
|
|
4
|
+
class Task {
|
|
5
|
+
constructor(_state, props) {
|
|
6
|
+
this._state = _state;
|
|
7
|
+
}
|
|
8
|
+
get state() {
|
|
9
|
+
return this._state;
|
|
10
|
+
}
|
|
11
|
+
get promise() {
|
|
12
|
+
return this._state.promise;
|
|
13
|
+
}
|
|
14
|
+
start(promise) {
|
|
15
|
+
}
|
|
16
|
+
isRunning() {
|
|
17
|
+
return this._state.isRunning;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Task = Task;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
export interface TaskState {
|
|
3
|
+
result?: 'completed' | 'timeout' | 'stopped' | 'error' | 'paused';
|
|
4
|
+
error?: Error;
|
|
5
|
+
tsStart?: number;
|
|
6
|
+
tsTimeout?: number;
|
|
7
|
+
promise?: Promise<any>;
|
|
8
|
+
}
|
|
9
|
+
export interface TaskProps<T, P> {
|
|
10
|
+
timeout?: number;
|
|
11
|
+
state?: any;
|
|
12
|
+
name?: string;
|
|
13
|
+
errorOnTimeout?: boolean;
|
|
14
|
+
log?: (event: any) => void;
|
|
15
|
+
onDone?: (state: T) => P;
|
|
16
|
+
}
|
|
17
|
+
interface InternalTaskState<P> {
|
|
18
|
+
tsStart?: number;
|
|
19
|
+
tsTimeout?: number;
|
|
20
|
+
isRunning: boolean;
|
|
21
|
+
timeout?: NodeJS.Timeout;
|
|
22
|
+
promise?: Promise<P>;
|
|
23
|
+
onDone?: (result: P) => void;
|
|
24
|
+
onError?: (error: Error) => void;
|
|
25
|
+
onTimeout?: () => void;
|
|
26
|
+
}
|
|
27
|
+
export declare class InteruptableTask<T extends TaskState, P> {
|
|
28
|
+
protected state: T;
|
|
29
|
+
protected internalState: InternalTaskState<P>;
|
|
30
|
+
protected props?: TaskProps<T, P>;
|
|
31
|
+
protected internalEvents: EventEmitter<[never]>;
|
|
32
|
+
protected promise?: Promise<P>;
|
|
33
|
+
constructor(promise: Promise<any>, props?: TaskProps<T, P>);
|
|
34
|
+
getPromise(): Promise<P>;
|
|
35
|
+
getState(): T;
|
|
36
|
+
run(): Promise<P>;
|
|
37
|
+
start(): void;
|
|
38
|
+
stop(): Promise<boolean>;
|
|
39
|
+
isRunning(): boolean;
|
|
40
|
+
protected clearTimeout(): void;
|
|
41
|
+
protected onTimeout(): void;
|
|
42
|
+
protected logEvent(event: any): void;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.InteruptableTask = void 0;
|
|
16
|
+
const events_1 = __importDefault(require("events"));
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
class InteruptableTask {
|
|
19
|
+
constructor(promise, props) {
|
|
20
|
+
var _a;
|
|
21
|
+
this.internalState = { isRunning: false };
|
|
22
|
+
this.internalEvents = new events_1.default();
|
|
23
|
+
this.state = ((_a = props === null || props === void 0 ? void 0 : props.state) !== null && _a !== void 0 ? _a : {});
|
|
24
|
+
this.props = props;
|
|
25
|
+
delete this.props.state;
|
|
26
|
+
this.promise = promise;
|
|
27
|
+
this.start();
|
|
28
|
+
}
|
|
29
|
+
getPromise() {
|
|
30
|
+
return this.internalState.promise;
|
|
31
|
+
}
|
|
32
|
+
getState() {
|
|
33
|
+
return this.state;
|
|
34
|
+
}
|
|
35
|
+
run() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (!this.internalState.isRunning)
|
|
38
|
+
yield (0, utils_1.resolveNextTick)();
|
|
39
|
+
return this.internalState.promise;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
start() {
|
|
43
|
+
this.internalState.promise = new Promise((resolve, reject) => {
|
|
44
|
+
var _a;
|
|
45
|
+
this.internalState.isRunning = true;
|
|
46
|
+
this.internalState.onDone = resolve;
|
|
47
|
+
this.internalState.onError = reject;
|
|
48
|
+
this.internalState.tsStart = Date.now();
|
|
49
|
+
const { timeout } = this.props;
|
|
50
|
+
if (timeout) {
|
|
51
|
+
this.internalState.tsTimeout = this.internalState.tsStart + timeout;
|
|
52
|
+
this.internalState.onTimeout = this.onTimeout.bind(this);
|
|
53
|
+
this.internalState.timeout = setTimeout(() => { this.internalEvents.emit('timeout'); }, timeout);
|
|
54
|
+
this.internalEvents.on('timeout', this.internalState.onTimeout);
|
|
55
|
+
}
|
|
56
|
+
this.internalEvents.once('stopped', () => {
|
|
57
|
+
this.clearTimeout();
|
|
58
|
+
this.internalState = {
|
|
59
|
+
isRunning: false,
|
|
60
|
+
};
|
|
61
|
+
this.internalEvents.removeAllListeners();
|
|
62
|
+
if (this.getState().result === 'completed' || this.getState().result === 'error')
|
|
63
|
+
return;
|
|
64
|
+
if (this.props.onDone)
|
|
65
|
+
resolve(this.props.onDone(this.getState()));
|
|
66
|
+
else
|
|
67
|
+
resolve(null);
|
|
68
|
+
});
|
|
69
|
+
(_a = this.promise) === null || _a === void 0 ? void 0 : _a.then((res) => {
|
|
70
|
+
this.clearTimeout();
|
|
71
|
+
this.internalState = {
|
|
72
|
+
isRunning: false,
|
|
73
|
+
};
|
|
74
|
+
this.getState().result = 'completed';
|
|
75
|
+
this.internalEvents.emit('stopped');
|
|
76
|
+
resolve(res);
|
|
77
|
+
}).catch((err) => {
|
|
78
|
+
this.getState().result = 'error';
|
|
79
|
+
this.getState().error = err;
|
|
80
|
+
this.internalEvents.emit('stopped');
|
|
81
|
+
reject(err);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
stop() {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
this.internalEvents.emit('stopped');
|
|
88
|
+
(0, utils_1.resolveNextTick)().then(() => {
|
|
89
|
+
resolve(true);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
isRunning() {
|
|
94
|
+
return this.internalState.isRunning === true;
|
|
95
|
+
}
|
|
96
|
+
clearTimeout() {
|
|
97
|
+
if (this.internalState.timeout) {
|
|
98
|
+
clearTimeout(this.internalState.timeout);
|
|
99
|
+
this.internalEvents.off('timeout', this.internalState.onTimeout);
|
|
100
|
+
}
|
|
101
|
+
delete this.internalState.timeout;
|
|
102
|
+
}
|
|
103
|
+
onTimeout() {
|
|
104
|
+
var _a;
|
|
105
|
+
if (!this.internalState.timeout)
|
|
106
|
+
return;
|
|
107
|
+
const message = this.props.name ? `${this.props.name} timeout` : 'timeout';
|
|
108
|
+
this.logEvent({ message, active: this.isRunning() });
|
|
109
|
+
this.clearTimeout();
|
|
110
|
+
this.getState().result = 'timeout';
|
|
111
|
+
const resolve = this.internalState.onDone;
|
|
112
|
+
const reject = this.internalState.onError;
|
|
113
|
+
this.internalState = { isRunning: false };
|
|
114
|
+
if ((_a = this.props.errorOnTimeout) !== null && _a !== void 0 ? _a : true) {
|
|
115
|
+
reject(new Error('timeout'));
|
|
116
|
+
}
|
|
117
|
+
if (this.props.onDone)
|
|
118
|
+
resolve(this.props.onDone(this.getState()));
|
|
119
|
+
else
|
|
120
|
+
resolve(null);
|
|
121
|
+
}
|
|
122
|
+
logEvent(event) {
|
|
123
|
+
if (this.props.log)
|
|
124
|
+
this.props.log(event);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.InteruptableTask = InteruptableTask;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-devices",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@serialport/bindings-interface": "^1.2.2",
|
|
6
6
|
"@serialport/parser-byte-length": "^9.0.1",
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@serialport/binding-mock": "^10.2.2",
|
|
18
18
|
"@serialport/bindings-cpp": "^10.8.0",
|
|
19
|
+
"@stoprocent/noble": "^1.15.2",
|
|
19
20
|
"@types/jest": "^29.5.12",
|
|
20
21
|
"@types/node": "^22.5.0",
|
|
22
|
+
"bonjour-service": "^1.3.0",
|
|
21
23
|
"eslint": "^8.47.0",
|
|
22
24
|
"eslint-config-react-app": "^7.0.1",
|
|
23
25
|
"jest": "^29.7.0",
|