incyclist-devices 2.3.0-beta.15 → 2.3.0-beta.17

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.
@@ -35,6 +35,7 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
35
35
  protected connectAttemptCnt: number;
36
36
  static getInstance(props?: InterfaceProps): BleInterface;
37
37
  protected constructor(props: InterfaceProps);
38
+ setProps(props: InterfaceProps): void;
38
39
  getLogger(): EventLogger;
39
40
  setLogger(logger: EventLogger): void;
40
41
  getName(): string;
@@ -28,6 +28,7 @@ class BleInterface extends events_1.default {
28
28
  if (BleInterface._instance === undefined)
29
29
  BleInterface._instance = new BleInterface(props);
30
30
  else {
31
+ BleInterface._instance.setProps(props);
31
32
  if (props.binding) {
32
33
  BleInterface._instance.setBinding(props.binding);
33
34
  }
@@ -60,9 +61,13 @@ class BleInterface extends events_1.default {
60
61
  }
61
62
  this.internalEvents = new events_1.default();
62
63
  this.onDiscovered = this.onPeripheralFound.bind(this);
63
- if (this.binding)
64
+ const { enabled = true } = props;
65
+ if (this.binding && enabled)
64
66
  this.autoConnect();
65
67
  }
68
+ setProps(props) {
69
+ this.props = props;
70
+ }
66
71
  getLogger() {
67
72
  return this.logger;
68
73
  }
@@ -73,8 +78,9 @@ class BleInterface extends events_1.default {
73
78
  return BleInterface.INTERFACE_NAME;
74
79
  }
75
80
  setBinding(binding) {
81
+ const prev = this.binding;
76
82
  this.binding = binding;
77
- if (!this.isConnected()) {
83
+ if (!prev && !this.isConnected() && this.props.enabled) {
78
84
  this.autoConnect();
79
85
  }
80
86
  }
@@ -504,7 +510,7 @@ class BleInterface extends events_1.default {
504
510
  const expected = this.expectedServices.map(utils_1.parseUUID);
505
511
  const supported = (_b = found.filter(uuid => expected.includes(uuid))) !== null && _b !== void 0 ? _b : [];
506
512
  if (!supported.length) {
507
- this.logEvent({ message: 'service not supported', name: service.name, uuids: service.serviceUUIDs });
513
+ this.logEvent({ message: 'peripheral not supported', name: service.name, uuids: service.serviceUUIDs });
508
514
  this.addUnsupported(service);
509
515
  }
510
516
  return supported.length > 0;
@@ -29,6 +29,7 @@ export default class DirectConnectInterface extends EventEmitter implements IBle
29
29
  protected connected: boolean;
30
30
  static getInstance(props?: InterfaceProps): DirectConnectInterface;
31
31
  constructor(props: InterfaceProps);
32
+ setProps(props: InterfaceProps): void;
32
33
  createPeripheral(announcement: MulticastDnsAnnouncement): IBlePeripheral;
33
34
  createDeviceSetting(service: MulticastDnsAnnouncement): BleDeviceSettings;
34
35
  createPeripheralFromSettings(settings: DeviceSettings): IBlePeripheral;
@@ -27,6 +27,7 @@ class DirectConnectInterface extends events_1.default {
27
27
  if (DirectConnectInterface._instance === undefined)
28
28
  DirectConnectInterface._instance = new DirectConnectInterface(props);
29
29
  else {
30
+ DirectConnectInterface._instance.setProps(props);
30
31
  if (props.binding) {
31
32
  DirectConnectInterface._instance.setBinding(props.binding);
32
33
  }
@@ -54,9 +55,13 @@ class DirectConnectInterface extends events_1.default {
54
55
  }
55
56
  this.internalEvents = new events_1.default();
56
57
  this.instance = ++instanceId;
57
- if (this.binding)
58
+ const { enabled } = props;
59
+ if (this.binding && (enabled !== null && enabled !== void 0 ? enabled : false))
58
60
  this.autoConnect();
59
61
  }
62
+ setProps(props) {
63
+ this.props = props;
64
+ }
60
65
  createPeripheral(announcement) {
61
66
  return peripheral_1.DirectConnectPeripheral.create(announcement);
62
67
  }
@@ -83,7 +88,7 @@ class DirectConnectInterface extends events_1.default {
83
88
  setBinding(binding) {
84
89
  const prev = this.binding;
85
90
  this.binding = binding;
86
- if (!prev)
91
+ if (!prev && this.props.enabled)
87
92
  this.autoConnect();
88
93
  }
89
94
  getBinding() {
@@ -238,10 +243,10 @@ class DirectConnectInterface extends events_1.default {
238
243
  this.services[idx] = { ts: Date.now(), service };
239
244
  }
240
245
  else {
241
- this.logEvent({ message: 'device announced', device: service.name, announcement: service, source });
242
246
  this.services.push({ ts: Date.now(), service });
243
247
  if (!((_a = service.serviceUUIDs) === null || _a === void 0 ? void 0 : _a.length))
244
248
  return;
249
+ this.logEvent({ message: 'device announced', device: service.name, announcement: service, source });
245
250
  this.emitDevice(service);
246
251
  (_b = this.matching) === null || _b === void 0 ? void 0 : _b.push(service.name);
247
252
  }
@@ -5,6 +5,7 @@ export type InterfaceProps = {
5
5
  binding?: any;
6
6
  logger?: EventLogger;
7
7
  log?: boolean;
8
+ enabled?: boolean;
8
9
  };
9
10
  export interface IncyclistInterface extends EventEmitter {
10
11
  getName(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.3.0-beta.15",
3
+ "version": "2.3.0-beta.17",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",