From 12c0225f5ebf2f436bb7c14e81a373a3ee163c7d Mon Sep 17 00:00:00 2001 From: Takeshi YAEDA Date: Tue, 16 May 2017 01:14:52 +0900 Subject: [PATCH 1/5] Add global namespace --- types/noble/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/noble/index.d.ts b/types/noble/index.d.ts index 4e293993f7..ce47d3a010 100644 --- a/types/noble/index.d.ts +++ b/types/noble/index.d.ts @@ -8,6 +8,8 @@ import events = require("events"); +export as namespace Noble; + export declare function startScanning(): void; export declare function startScanning(serviceUUIDs: string[]): void; export declare function startScanning(serviceUUIDs: string[], allowDuplicates: boolean): void; From 5dc25616cc77d1769768202f48a14218be85236c Mon Sep 17 00:00:00 2001 From: Takeshi YAEDA Date: Tue, 16 May 2017 01:17:03 +0900 Subject: [PATCH 2/5] Add listener option to (start|stop)Scanning --- types/noble/index.d.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/types/noble/index.d.ts b/types/noble/index.d.ts index ce47d3a010..4b913a8255 100644 --- a/types/noble/index.d.ts +++ b/types/noble/index.d.ts @@ -10,10 +10,8 @@ import events = require("events"); export as namespace Noble; -export declare function startScanning(): void; -export declare function startScanning(serviceUUIDs: string[]): void; -export declare function startScanning(serviceUUIDs: string[], allowDuplicates: boolean): void; -export declare function stopScanning(): void; +export declare function startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, listener?: (error: Error) => void): void; +export declare function stopScanning(listener?: () => void): void; export declare function on(event: string, listener: Function): events.EventEmitter; export declare function on(event: "stateChange", listener: (state: string) => void): events.EventEmitter; From 12a5b8c297a030ba99fdc203141f1a894e73b60d Mon Sep 17 00:00:00 2001 From: Takeshi YAEDA Date: Tue, 16 May 2017 02:18:02 +0900 Subject: [PATCH 3/5] Replace with --- types/noble/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/noble/index.d.ts b/types/noble/index.d.ts index 4b913a8255..6ee7fd85b3 100644 --- a/types/noble/index.d.ts +++ b/types/noble/index.d.ts @@ -10,8 +10,8 @@ import events = require("events"); export as namespace Noble; -export declare function startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, listener?: (error: Error) => void): void; -export declare function stopScanning(listener?: () => void): void; +export declare function startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, callback?: (error: Error) => void): void; +export declare function stopScanning(callback?: () => void): void; export declare function on(event: string, listener: Function): events.EventEmitter; export declare function on(event: "stateChange", listener: (state: string) => void): events.EventEmitter; From a9be423793f10f010679ae966c2bea3ff2d9642f Mon Sep 17 00:00:00 2001 From: Takeshi YAEDA Date: Tue, 16 May 2017 19:10:07 +0900 Subject: [PATCH 4/5] Update test --- types/noble/noble-tests.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/types/noble/noble-tests.ts b/types/noble/noble-tests.ts index 9c3f403944..3f5a035dcd 100644 --- a/types/noble/noble-tests.ts +++ b/types/noble/noble-tests.ts @@ -6,24 +6,26 @@ function test_startScanning(): void { noble.startScanning(); noble.startScanning(["0x180d"]); noble.startScanning(["0x180d"], true); + noble.startScanning(["0x180d"], true, (error: Error): void => {}); } test_startScanning(); function test_stopScanning(): void { "use strict"; noble.stopScanning(); + noble.stopScanning((): void => {}); } test_stopScanning(); noble.on("stateChange", (state: string): void => {}); noble.on("scanStart", (): void => {}); noble.on("scanStop", (): void => {}); -noble.on("discover", (peripheral: noble.Peripheral): void => { +noble.on("discover", (peripheral: Noble.Peripheral): void => { peripheral.connect((error: string): void => {}); peripheral.disconnect((): void => {}); }); -var peripheral: noble.Peripheral = new noble.Peripheral(); +var peripheral: Noble.Peripheral = new noble.Peripheral(); peripheral.uuid = "12ad4e81"; peripheral.advertisement = { localName: "device", @@ -39,19 +41,19 @@ peripheral.disconnect((): void => {}); peripheral.updateRssi(); peripheral.updateRssi((error: string, rssi: number): void => {}); peripheral.discoverServices(["180d"]); -peripheral.discoverServices(["180d"], (error: string, services: noble.Service[]): void => {}); +peripheral.discoverServices(["180d"], (error: string, services: Noble.Service[]): void => {}); peripheral.discoverAllServicesAndCharacteristics(); -peripheral.discoverAllServicesAndCharacteristics((error: string, services: noble.Service[], characteristics: noble.Characteristic[]): void => {}); +peripheral.discoverAllServicesAndCharacteristics((error: string, services: Noble.Service[], characteristics: Noble.Characteristic[]): void => {}); peripheral.discoverSomeServicesAndCharacteristics(["180d"], ["2a38"]); -peripheral.discoverSomeServicesAndCharacteristics(["180d"], ["2a38"], (error: string, services: noble.Service[], characteristics: noble.Characteristic[]): void => {}); +peripheral.discoverSomeServicesAndCharacteristics(["180d"], ["2a38"], (error: string, services: Noble.Service[], characteristics: Noble.Characteristic[]): void => {}); peripheral.readHandle(new Buffer(1), (error: string, data: NodeBuffer): void => {}); peripheral.writeHandle(new Buffer(1), new Buffer(1), true, (error: string): void => {}); peripheral.on("connect", (error: string): void => {}); peripheral.on("disconnect", (error: string): void => {}); peripheral.on("rssiUpdate", (rssi: number): void => {}); -peripheral.on("servicesDiscover", (services: noble.Service[]): void => {}); +peripheral.on("servicesDiscover", (services: Noble.Service[]): void => {}); -var service: noble.Service = new noble.Service(); +var service: Noble.Service = new noble.Service(); service.uuid = "180a"; service.name = ""; service.type = ""; @@ -59,11 +61,11 @@ service.includedServiceUuids = ["180d"]; service.discoverIncludedServices(["180d"]); service.discoverIncludedServices(["180d"], (error: string, includedServiceUuids: string[]): void => {}); service.discoverCharacteristics(["2a38"]); -service.discoverCharacteristics(["2a38"], (error: string, characteristics: noble.Characteristic[]): void => {}); +service.discoverCharacteristics(["2a38"], (error: string, characteristics: Noble.Characteristic[]): void => {}); service.on("includedServicesDiscover", (includedServiceUuids: string[]): void => {}); -service.on("characteristicsDiscover", (characteristics: noble.Characteristic[]): void => {}); +service.on("characteristicsDiscover", (characteristics: Noble.Characteristic[]): void => {}); -var characteristic: noble.Characteristic = new noble.Characteristic(); +var characteristic: Noble.Characteristic = new noble.Characteristic(); characteristic.uuid = "2a37"; characteristic.name = ""; characteristic.type = ""; @@ -77,14 +79,14 @@ characteristic.broadcast(true, (error: string): void => {}); characteristic.notify(true); characteristic.notify(true, (error: string): void => {}); characteristic.discoverDescriptors(); -characteristic.discoverDescriptors((error: string, descriptors: noble.Descriptor[]): void => {}); +characteristic.discoverDescriptors((error: string, descriptors: Noble.Descriptor[]): void => {}); characteristic.on("read", (data: NodeBuffer, isNotification: boolean): void => {}); characteristic.on("write", true, (error: string): void => {}); characteristic.on("broadcast", (state: string): void => {}); characteristic.on("notify", (state: string): void => {}); -characteristic.on("descriptorsDiscover", (descriptors: noble.Descriptor[]): void => {}); +characteristic.on("descriptorsDiscover", (descriptors: Noble.Descriptor[]): void => {}); -var descriptor: noble.Descriptor = new noble.Descriptor(); +var descriptor: Noble.Descriptor = new noble.Descriptor(); descriptor.uuid = ""; descriptor.name = ""; descriptor.type = ""; From 09d36cb59e3c8317e03539625ba6721bcd084a4d Mon Sep 17 00:00:00 2001 From: Takeshi YAEDA Date: Fri, 19 May 2017 09:03:08 +0900 Subject: [PATCH 5/5] Make namespace lower-case (types/noble) --- types/noble/index.d.ts | 2 +- types/noble/noble-tests.ts | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/types/noble/index.d.ts b/types/noble/index.d.ts index 6ee7fd85b3..94ba4f8922 100644 --- a/types/noble/index.d.ts +++ b/types/noble/index.d.ts @@ -8,7 +8,7 @@ import events = require("events"); -export as namespace Noble; +export as namespace noble; export declare function startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, callback?: (error: Error) => void): void; export declare function stopScanning(callback?: () => void): void; diff --git a/types/noble/noble-tests.ts b/types/noble/noble-tests.ts index 3f5a035dcd..2f985d2888 100644 --- a/types/noble/noble-tests.ts +++ b/types/noble/noble-tests.ts @@ -20,12 +20,12 @@ test_stopScanning(); noble.on("stateChange", (state: string): void => {}); noble.on("scanStart", (): void => {}); noble.on("scanStop", (): void => {}); -noble.on("discover", (peripheral: Noble.Peripheral): void => { +noble.on("discover", (peripheral: noble.Peripheral): void => { peripheral.connect((error: string): void => {}); peripheral.disconnect((): void => {}); }); -var peripheral: Noble.Peripheral = new noble.Peripheral(); +var peripheral: noble.Peripheral = new noble.Peripheral(); peripheral.uuid = "12ad4e81"; peripheral.advertisement = { localName: "device", @@ -41,19 +41,19 @@ peripheral.disconnect((): void => {}); peripheral.updateRssi(); peripheral.updateRssi((error: string, rssi: number): void => {}); peripheral.discoverServices(["180d"]); -peripheral.discoverServices(["180d"], (error: string, services: Noble.Service[]): void => {}); +peripheral.discoverServices(["180d"], (error: string, services: noble.Service[]): void => {}); peripheral.discoverAllServicesAndCharacteristics(); -peripheral.discoverAllServicesAndCharacteristics((error: string, services: Noble.Service[], characteristics: Noble.Characteristic[]): void => {}); +peripheral.discoverAllServicesAndCharacteristics((error: string, services: noble.Service[], characteristics: noble.Characteristic[]): void => {}); peripheral.discoverSomeServicesAndCharacteristics(["180d"], ["2a38"]); -peripheral.discoverSomeServicesAndCharacteristics(["180d"], ["2a38"], (error: string, services: Noble.Service[], characteristics: Noble.Characteristic[]): void => {}); +peripheral.discoverSomeServicesAndCharacteristics(["180d"], ["2a38"], (error: string, services: noble.Service[], characteristics: noble.Characteristic[]): void => {}); peripheral.readHandle(new Buffer(1), (error: string, data: NodeBuffer): void => {}); peripheral.writeHandle(new Buffer(1), new Buffer(1), true, (error: string): void => {}); peripheral.on("connect", (error: string): void => {}); peripheral.on("disconnect", (error: string): void => {}); peripheral.on("rssiUpdate", (rssi: number): void => {}); -peripheral.on("servicesDiscover", (services: Noble.Service[]): void => {}); +peripheral.on("servicesDiscover", (services: noble.Service[]): void => {}); -var service: Noble.Service = new noble.Service(); +var service: noble.Service = new noble.Service(); service.uuid = "180a"; service.name = ""; service.type = ""; @@ -61,11 +61,11 @@ service.includedServiceUuids = ["180d"]; service.discoverIncludedServices(["180d"]); service.discoverIncludedServices(["180d"], (error: string, includedServiceUuids: string[]): void => {}); service.discoverCharacteristics(["2a38"]); -service.discoverCharacteristics(["2a38"], (error: string, characteristics: Noble.Characteristic[]): void => {}); +service.discoverCharacteristics(["2a38"], (error: string, characteristics: noble.Characteristic[]): void => {}); service.on("includedServicesDiscover", (includedServiceUuids: string[]): void => {}); -service.on("characteristicsDiscover", (characteristics: Noble.Characteristic[]): void => {}); +service.on("characteristicsDiscover", (characteristics: noble.Characteristic[]): void => {}); -var characteristic: Noble.Characteristic = new noble.Characteristic(); +var characteristic: noble.Characteristic = new noble.Characteristic(); characteristic.uuid = "2a37"; characteristic.name = ""; characteristic.type = ""; @@ -79,14 +79,14 @@ characteristic.broadcast(true, (error: string): void => {}); characteristic.notify(true); characteristic.notify(true, (error: string): void => {}); characteristic.discoverDescriptors(); -characteristic.discoverDescriptors((error: string, descriptors: Noble.Descriptor[]): void => {}); +characteristic.discoverDescriptors((error: string, descriptors: noble.Descriptor[]): void => {}); characteristic.on("read", (data: NodeBuffer, isNotification: boolean): void => {}); characteristic.on("write", true, (error: string): void => {}); characteristic.on("broadcast", (state: string): void => {}); characteristic.on("notify", (state: string): void => {}); -characteristic.on("descriptorsDiscover", (descriptors: Noble.Descriptor[]): void => {}); +characteristic.on("descriptorsDiscover", (descriptors: noble.Descriptor[]): void => {}); -var descriptor: Noble.Descriptor = new noble.Descriptor(); +var descriptor: noble.Descriptor = new noble.Descriptor(); descriptor.uuid = ""; descriptor.name = ""; descriptor.type = "";