@moddable/typings 5.3.0 → 5.4.1

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/ble.d.ts DELETED
@@ -1,732 +0,0 @@
1
- /*
2
- * Copyright (c) 2022 Richard Lea
3
- *
4
- * This file is part of the Moddable SDK Tools.
5
- *
6
- * The Moddable SDK Tools is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Tools is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with the Moddable SDK Tools. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
- type ManufacturerSpec = {
22
- /**
23
- * The `identifier` property is a number corresponding to the
24
- * _Company Identifier Code_.
25
- */
26
- identifier: string | number,
27
-
28
- /**
29
- * The `data` property is an array of numbers corresponding
30
- * to additional manufacturer specific data.
31
- */
32
- data: number[],
33
- };
34
-
35
- declare module "bleclient" {
36
-
37
- import { GAP } from "gap";
38
- import { Client, Characteristic } from "gatt";
39
- import { IOCapability } from "sm";
40
-
41
- type gapScanFilterPolicies =
42
- typeof GAP.ScanFilterPolicy.NONE |
43
- typeof GAP.ScanFilterPolicy.NOT_RESOLVED_DIRECTED |
44
- typeof GAP.ScanFilterPolicy.WHITELIST |
45
- typeof GAP.ScanFilterPolicy.WHITELIST_NOT_RESOLVED_DIRECTED;
46
-
47
- /**
48
- * The `BLEClient` class provides access to the BLE client features.
49
- */
50
- export class BLEClient {
51
-
52
- securityParameters: {
53
- encryption?: boolean,
54
- bonding?: boolean,
55
- mitm?: boolean,
56
- ioCapability?: IOCapability,
57
- };
58
-
59
- /**
60
- * Applications must wait for the `onReady` callback before calling
61
- * other `BLEClient` functions
62
- */
63
- onReady(): void
64
-
65
- /**
66
- * The `startScanning` function enables scanning for nearby peripherals.
67
- *
68
- * @param params If params is not provided, the default scan properties are used.
69
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#startscanningparams
70
- */
71
- startScanning(params?: {
72
- active: boolean,
73
- duplicates: boolean,
74
- filterPolicy: gapScanFilterPolicies,
75
- interval: number,
76
- window: number,
77
- }): void;
78
-
79
- /**
80
- * Called when one or more times for each peripheral device discovered.
81
- * @param device
82
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#ondiscovereddevice
83
- */
84
- onDiscovered(device: Client): void;
85
-
86
- /**
87
- * Disables scanning for nearby peripherals.
88
- */
89
- stopScanning(): void;
90
-
91
- /**
92
- * Initiates a connection request between the `BLEClient` and a target peripheral `device`.
93
- * @param device
94
- */
95
- connect(device: Client): void;
96
-
97
- onConnected(device: Client): void;
98
-
99
- onDisconnected(): void;
100
-
101
- onCharacteristicNotification(characteristic: Characteristic, buffer: number[]): void;
102
- }
103
-
104
- export { BLEClient as default };
105
- }
106
-
107
- declare module "bleserver" {
108
-
109
- import { GAP } from "gap";
110
- import { Bytes } from "btutils";
111
- import { Characteristic, Client } from "gatt";
112
- import { IOCapability } from "sm";
113
-
114
- type gapScanFilterPolicies =
115
- typeof GAP.ScanFilterPolicy.NONE |
116
- typeof GAP.ScanFilterPolicy.NOT_RESOLVED_DIRECTED |
117
- typeof GAP.ScanFilterPolicy.WHITELIST |
118
- typeof GAP.ScanFilterPolicy.WHITELIST_NOT_RESOLVED_DIRECTED;
119
-
120
- type AdvertisementData = {
121
-
122
- /**
123
- * The advertised flags value.
124
- */
125
- flags?: number;
126
- /**
127
- * Array of UUID objects corresponding to _Incomplete List
128
- * of 16 bit Service UUIDs_
129
- */
130
- incompleteUUID16List?: Bytes[],
131
-
132
- /**
133
- * Array of UUID objects corresponding to _Complete List of
134
- * 16 bit Service UUIDs_
135
- */
136
- completeUUID16List?: Bytes[],
137
-
138
- /**
139
- * Array of UUID objects corresponding to _Incomplete List of
140
- * 128 bit Service UUIDs_
141
- */
142
- incompleteUUID128List?: Bytes[],
143
-
144
- /**
145
- * Array of UUID objects corresponding to _Complete List of
146
- * 128 bit Service UUIDs_
147
- */
148
- completeUUID128List?: Bytes[],
149
-
150
- /**
151
- * String corresponding to the _Shortened Local Name_.
152
- */
153
- shortName?: string,
154
-
155
- /**
156
- * String corresponding to the _Complete Local Name_.
157
- */
158
- completeName?: string,
159
-
160
- /**
161
- * Object corresponding to the _Manufacturer Specific Data_.
162
- */
163
- manufacturerSpecific?: ManufacturerSpec,
164
-
165
- /**
166
- * Number corresponding to the TX Power Level.
167
- */
168
- txPowerLevel?: number,
169
-
170
- /**
171
- * Object corresponding to the _Slave Connection Interval Range_.
172
- */
173
- connectionInterval?: {
174
- /**
175
- * A number corresponding to the minimum connection interval value.
176
- */
177
- intervalMin: number,
178
-
179
- /**
180
- * A number corresponding to the maximum connection interval value.
181
- */
182
- intervalMax: number,
183
- },
184
-
185
- /**
186
- * Array of UUID objects corresponding to the _List of 16 bit Service
187
- * Solicitation UUIDs_.
188
- */
189
- solicitationUUID16List?: Bytes[],
190
-
191
- /**
192
- * Array of UUID objects corresponding to the _List of 128 bit Service
193
- * Solicitation UUIDs_.
194
- */
195
- solicitationUUID128List?: Bytes[],
196
-
197
- /**
198
- * Object corresponding to the _Service Data - 16 bit UUID_.
199
- */
200
- serviceDataUUID16?: {
201
- /**
202
- * An object corresponding to the 16-bit Service UUID.
203
- */
204
- uuid: Bytes,
205
-
206
- /**
207
- * An array of numbers corresponding to additional service data.
208
- */
209
- data: number[],
210
- },
211
-
212
- /**
213
- * Object corresponding to the _Service Data - 128 bit UUID_.
214
- */
215
- serviceDataUUID128?: {
216
- /**
217
- * An object corresponding to the 128-bit Service UUID.
218
- */
219
- uuid: Bytes,
220
-
221
- /**
222
- * An array of numbers corresponding to additional service data.
223
- */
224
- data: number[],
225
- },
226
-
227
- /**
228
- * Number corresponding to the _Appearance_.
229
- */
230
- appearance?: number,
231
-
232
- /**
233
- * Address object corresponding to the _Public Target Address_.
234
- */
235
- publicAddress?: Bytes,
236
-
237
- /**
238
- * Address object corresponding to the _Random Target Address_.
239
- */
240
- randomAddress?: Bytes,
241
-
242
- /**
243
- * Number corresponding to the _Advertising Interval_.
244
- */
245
- advertisingInterval?: number,
246
-
247
- /**
248
- * Number corresponding to the _LE Role_.
249
- */
250
- role?: number,
251
-
252
- /**
253
- * String corresponding to the _Uniform Resource Identifier_.
254
- */
255
- uri?: string,
256
- };
257
-
258
- /**
259
- * Provides access to the BLE server features.
260
- */
261
- export class BLEServer {
262
-
263
- /**
264
- * Configures the device security requirements and I/O capabilities.
265
- */
266
- set securityParameters(params: {
267
- encryption?: boolean,
268
- bonding?: boolean,
269
- mitm?: boolean,
270
- ioCapability?: IOCapability,
271
- });
272
-
273
- /**
274
- * set/get the Bluetooth peripheral device name.
275
- */
276
- deviceName: string;
277
-
278
- /**
279
- * The Bluetooth peripheral's local address as a
280
- * `Bytes` object.
281
- *
282
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#localaddress
283
- */
284
- readonly localAddress: Bytes;
285
-
286
- /**
287
- * Applications must wait for the `onReady` callback
288
- * before calling other `BLEServer` functions.
289
- */
290
- onReady(): void;
291
-
292
- /**
293
- * Starts broadcasting advertisement and scan response packets.
294
- * The function is also used to configure discoverable and connectable modes.
295
- *
296
- * @param params
297
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#startadvertisingparams
298
- */
299
- startAdvertising(params: {
300
- advertisingData: AdvertisementData,
301
- connectable?: boolean,
302
- discoverable?: boolean,
303
- fast?: boolean,
304
- filterPolicy?: gapScanFilterPolicies,
305
- scanResponseData?: any,
306
- }): void;
307
-
308
- /**
309
- * Stops broadcasting Bluetooth advertisements.
310
- *
311
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#stopadvertising
312
- */
313
- stopAdvertising(): void;
314
-
315
- /**
316
- * Send a characteristic value change notification to the connected client.
317
- *
318
- * @param characteristic
319
- * @param value
320
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#notifyvaluecharacteristic-value
321
- */
322
- notifyValue(characteristic: Characteristic, value: any): void;
323
-
324
- /**
325
- * Called when a client enables notifications on the `characteristic`.
326
- *
327
- * @param characteristic
328
- */
329
- onCharacteristicNotifyEnabled(characteristic: Characteristic): void;
330
-
331
- /**
332
- * Called when a client writes a service characteristic value on demand.
333
- *
334
- * @param characteristic
335
- * @param value
336
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#oncharacteristicwrittencharacteristic-value
337
- */
338
- onCharacteristicWritten(characteristic: Characteristic, value: any): void;
339
-
340
- /**
341
- * Called when a client reads a service characteristic value on demand.
342
- *
343
- * @param characteristic
344
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#oncharacteristicreadcharacteristic
345
- */
346
- onCharacteristicRead(characteristic: Characteristic): Uint8Array | number[] | number | void;
347
-
348
- /**
349
- * Terminate the BLE client connection.
350
- */
351
- disconnect(): void;
352
-
353
- /**
354
- * Called when a client connects to the `BLEServer`.
355
- *
356
- * @param device
357
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#ondisconnecteddevice-1
358
- */
359
- onConnected(device: Client): void;
360
-
361
- /**
362
- * Called when the client connection is closed.
363
- *
364
- * @param device
365
- */
366
- onDisconnected(device: Client): void;
367
-
368
- /**
369
- * Terminate any BLE client connection and release all BLE resources.
370
- */
371
- close(): void;
372
- }
373
-
374
- export { BLEServer as default };
375
- }
376
-
377
- declare module "btutils" {
378
-
379
- export interface Bytes extends ArrayBuffer {
380
- /**
381
- * The `equals` function returns `true` if the instance
382
- * ArrayBuffer data equals the data contained in `buffer`.
383
- *
384
- * @param bytes
385
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#equalsbuffer
386
- */
387
- equals(bytes: Bytes): boolean;
388
- }
389
-
390
- /**
391
- * Provides Accessor functions to read common advertisement and
392
- * scan response data types as JavaScript properties.
393
- *
394
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#class-advertisement
395
- */
396
- export interface Advertisement {
397
-
398
- /**
399
- * Contains the raw advertisement data bytes.
400
- */
401
- buffer: ArrayBuffer;
402
-
403
- /**
404
- * The advertised complete local name.
405
- */
406
- completeName: string;
407
-
408
- /**
409
- * The advertised shortened local name.
410
- */
411
- shortName: string;
412
-
413
- /**
414
- * An object containing the advertised manufacturer specific data.
415
- */
416
- manufacturerSpecific: ManufacturerSpec;
417
-
418
- /**
419
- * The advertised flags value.
420
- */
421
- flags: number;
422
-
423
- /**
424
- * The advertised complete 16-bit UUID list.
425
- */
426
- completeUUID16List: Array<string | number>;
427
-
428
- /**
429
- * The advertised incomplete 16-bit UUID list.
430
- */
431
- incompleteUUID16List: Array<string | number>;
432
- }
433
-
434
- /**
435
- * Convert a Bluetooth UUID expressed as a hex string to a `Bytes` instance.
436
- * @param strings
437
- */
438
- export function uuid(...strings: string[]): Bytes;
439
-
440
- /**
441
- * Convert a Bluetooth address expressed as a hex string to a `Bytes` instance.
442
- * @param strings
443
- */
444
- export function address(...strings: string[]): Bytes;
445
- }
446
-
447
- declare module "gatt" {
448
-
449
- import { Bytes, Advertisement } from "btutils";
450
- import { GAP } from "gap";
451
-
452
- type getAddressType = (typeof GAP.AddressType);
453
-
454
- export interface Client {
455
- connection: number,
456
- address: Bytes,
457
- addressType: getAddressType,
458
- scanResponse: Advertisement,
459
- rssi: number,
460
-
461
- /**
462
- * Read the connected peripheral's signal strength.
463
- *
464
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#readrssi
465
- */
466
- readRSSI(): void;
467
-
468
- /**
469
- * Discover a single GATT primary service by UUID.
470
- *
471
- * @param uuid
472
- */
473
- discoverPrimaryService(uuid: Bytes): void;
474
-
475
- /**
476
- * Discover all the peripheral's GATT primary services.
477
- * Discovered services are returned to the `onServices` callback.
478
- */
479
- discoverAllPrimaryServices(): void;
480
-
481
- /**
482
- * Finds and returns the service identified by `uuid`.
483
- *
484
- * @param uuid
485
- */
486
- findServiceByUUID(uuid: Bytes): void;
487
-
488
- /**
489
- * Called when service discovery completes.
490
- * If `findServiceByUUID` was called to find a single service,
491
- * the `services` array contains the single service found.
492
- *
493
- * @param services
494
- */
495
- onServices(services: Service[]): void;
496
-
497
- /**
498
- * Terminates the peripheral function.
499
- */
500
- close(): void;
501
- }
502
-
503
- /**
504
- * A single Peripheral GATT service.
505
- */
506
- export interface Service {
507
- connection: number;
508
- uuid: Bytes;
509
- start: number;
510
- end: number;
511
- characteristics: Characteristic[];
512
-
513
- /**
514
- * Discover all the service characteristics. Discovered characteristics
515
- * are returned to the `onCharacteristics` callback.
516
- */
517
- discoverAllCharacteristics(): void;
518
-
519
- /**
520
- * Discover a single service characteristic by UUID.
521
- *
522
- * @param uuid
523
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#discovercharacteristicuuid
524
- */
525
- discoverCharacteristic(uuid: Bytes): void;
526
-
527
- /**
528
- * Called when characteristic discovery completes.
529
- * If `findCharacteristicByUUID` was called to find a single characteristic,
530
- * the `characteristics` array contains the single characteristic found.
531
- *
532
- * @param characteristics
533
- */
534
- onCharacteristics(characteristics: Characteristic[]): void;
535
- }
536
-
537
- /**
538
- * A single service Characteristic.
539
- *
540
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#class-characteristic
541
- */
542
- export interface Characteristic {
543
- connection: number;
544
- uuid: Bytes;
545
- service: Service;
546
- handle: number;
547
- name: string;
548
- type: string;
549
- descriptors: Descriptor[];
550
-
551
- /**
552
- * Discover all the characteristic's descriptors.
553
- * Discovered descriptors are returned to the `onDescriptors` callback.
554
- */
555
- discoverAllDescriptors(): void;
556
-
557
- /**
558
- * Called when descriptor discovery completes.
559
- *
560
- * @param descriptors
561
- */
562
- onDescriptors(descriptors: Descriptor[]): void;
563
-
564
- /**
565
- * Enable characteristic value change notifications.
566
- *
567
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#enablenotifications
568
- */
569
- disableNotifications(): void;
570
- }
571
-
572
- /**
573
- * A single Characteristic descriptor.
574
- *
575
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#class-descriptor
576
- */
577
- export interface Descriptor {
578
- connection: number;
579
- uuid: string;
580
- characteristic: Characteristic;
581
- handle: number;
582
- name: string;
583
- type: string;
584
-
585
- /**
586
- * Read a descriptor value on demand.
587
- *
588
- * @param auth
589
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#readvalueauth-1
590
- */
591
- readValue(auth?: number): void;
592
- }
593
- }
594
-
595
- declare module "connection" {
596
- export class Connection {
597
- disconnect(): void;
598
- }
599
- }
600
-
601
- declare module "gap" {
602
-
603
- const enum gapAddressTypes {
604
- PUBLIC = 0,
605
- RANDOM = 1,
606
- RPA_PUBLIC = 2,
607
- RPA_RANDOM = 3,
608
- }
609
-
610
- export const GAP: {
611
- readonly SCAN_FAST_INTERVAL: 0x0030, // TGAP(scan_fast_interval) 30ms to 60ms
612
- readonly SCAN_FAST_WINDOW: 0x0030, // TGAP(scan_fast_window) 30ms
613
- readonly SCAN_SLOW_INTERVAL1: 0x0800, // TGAP(scan_slow_interval1) 1.28s
614
- readonly SCAN_SLOW_WINDOW1: 0x0012, // TGAP(scan_slow_window1) 11.25ms
615
- readonly SCAN_SLOW_INTERVAL2: 0x1000, // TGAP(scan_slow_interval2) 2.56s
616
- readonly SCAN_SLOW_WINDOW2: 0x0024, // TGAP(scan_slow_window2) 22.5ms
617
- readonly ADV_FAST_INTERVAL1: { // TGAP(adv_fast_interval1) 30ms to 60ms
618
- min: 0x0030,
619
- max: 0x0060
620
- },
621
- readonly ADV_FAST_INTERVAL2: { // TGAP(adv_fast_interval2) 100ms to 150ms
622
- min: 0x00A0,
623
- max: 0x00F0,
624
- },
625
- readonly ADV_SLOW_INTERVAL: { // TGAP(adv_slow_interval) 1s to 1.2s
626
- min: 0x0640,
627
- max: 0x0780,
628
- },
629
- readonly ADType: {
630
- /* Service UUID */
631
- INCOMPLETE_UUID16_LIST: 0x02,
632
- COMPLETE_UUID16_LIST: 0x03,
633
- INCOMPLETE_UUID128_LIST: 0x06,
634
- COMPLETE_UUID128_LIST: 0x07,
635
- /* Local Name */
636
- SHORTENED_LOCAL_NAME: 0x08,
637
- COMPLETE_LOCAL_NAME: 0x09,
638
- /* Flags */
639
- FLAGS: 0x01,
640
- /* Manufacturer Specific Data */
641
- MANUFACTURER_SPECIFIC_DATA: 0xFF,
642
- /* TX Power Level */
643
- TX_POWER_LEVEL: 0x0A,
644
- SLAVE_CONNECTION_INTERVAL_RANGE: 0x12,
645
- /* Service Solicitation */
646
- SOLICITATION_UUID16_LIST: 0x14,
647
- SOLICITATION_UUID128_LIST: 0x15,
648
- /* Service Data */
649
- SERVICE_DATA_UUID16: 0x16,
650
- SERVICE_DATA_UUID128: 0x21,
651
- /* Appearance */
652
- APPEARANCE: 0x19,
653
- /* Public Target Address */
654
- PUBLIC_TARGET_ADDRESS: 0x17,
655
- /* Random Target Address */
656
- RANDOM_TARGET_ADDRESS: 0x18,
657
- /* Advertising Interval */
658
- ADVERTISING_INTERVAL: 0x1A,
659
- /* LE Bluetooth Device Address */
660
- LE_BLUETOOTH_DEVICE_ADDRESS: 0x1B,
661
- /* LE Role */
662
- LE_ROLE: 0x1C,
663
- /* URI */
664
- URI: 0x24,
665
- },
666
- MAX_AD_LENGTH: 31,
667
- ADFlag: {
668
- LE_LIMITED_DISCOVERABLE_MODE: 0x01,
669
- LE_GENERAL_DISCOVERABLE_MODE: 0x02,
670
- NO_BR_EDR: 0x04,
671
- LE_BR_EDR_CONTROLLER: 0x08,
672
- LE_BR_EDR_HOST: 0x10,
673
- },
674
- AddressType: typeof gapAddressTypes,
675
- ScanFilterPolicy: {
676
- NONE: 0,
677
- WHITELIST: 1,
678
- NOT_RESOLVED_DIRECTED: 2,
679
- WHITELIST_NOT_RESOLVED_DIRECTED: 3,
680
- },
681
- AdvFilterPolicy: {
682
- NONE: 0,
683
- WHITELIST_SCANS: 1,
684
- WHITELIST_CONNECTIONS: 2,
685
- WHITELIST_SCANS_CONNECTIONS: 3
686
- },
687
- }
688
- export { GAP as default };
689
- }
690
-
691
- declare module "sm" {
692
-
693
- import { GAP } from "gap";
694
-
695
- type getAddressType = (typeof GAP.AddressType);
696
-
697
- /**
698
- * @url https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#class-sm
699
- */
700
- export const enum IOCapability {
701
- NoInputNoOutput = 0,
702
- DisplayOnly = 1,
703
- KeyboardOnly = 2,
704
- KeyboardDisplay = 3,
705
- DisplayYesNo = 4,
706
- }
707
-
708
- /**
709
- * Provides objects used to configure BLE client and server security requirements
710
- * and device capabilities.
711
- */
712
- export class SM {
713
-
714
-
715
- /**
716
- * Delete all bonding information and encryption keys
717
- * from persistent storage.
718
- *
719
- * https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/network/ble/ble.md#deleteallbondings
720
- */
721
- static deleteAllBondings(): void;
722
-
723
- /**
724
- * Delete stored bonding information for the peer device with the provided
725
- * `address` and `addressType`.
726
- *
727
- * @param address Contains peer device Bluetooth address
728
- * @param addressType Peer device Bluetooth address type.
729
- */
730
- static deleteBonding(address: ArrayBuffer, addressType: getAddressType): void;
731
- }
732
- }