diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ee6261a5b4..a3f729ca96 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,6 +1,6 @@ # Contributors -This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url. +This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url. All definitions files include a header with the author and editors, so at some point this list will be auto-generated. @@ -207,6 +207,7 @@ All definitions files include a header with the author and editors, so at some p * [msgpack.js](https://github.com/uupaa/msgpack.js) (by [Shinya Mochizuki](https://github.com/enrapt-mochizuki)) * [Mustache.js](https://github.com/janl/mustache.js) (by [Boris Yankov](https://github.com/borisyankov)) * [nconf](https://github.com/flatiron/nconf) (by [Jeff Goddard](https://github.com/jedigo)) +* [noble](https://github.com/sandeepmistry/noble) (by [Seon-Wook Park](https://github.com/swook)) * [nock](https://github.com/pgte/nock) (by [bonnici](https://github.com/bonnici)) * [Node.js](http://nodejs.org/) (from TypeScript samples) * [node_redis](https://github.com/mranney/node_redis) (by [Boris Yankov](https://github.com/borisyankov)) diff --git a/noble/noble-tests.ts b/noble/noble-tests.ts new file mode 100644 index 0000000000..46851ab523 --- /dev/null +++ b/noble/noble-tests.ts @@ -0,0 +1,82 @@ +/// + +import noble = require("noble"); + +function test_startScanning(): void { + "use strict"; + noble.startScanning(); + noble.startScanning(["0x180d"]); + noble.startScanning(["0x180d"], true); +} +test_startScanning(); + +function test_stopScanning(): void { + "use strict"; + noble.stopScanning(); +} +test_stopScanning(); + +noble.on("stateChange", (state: string): void => {}); +noble.on("scanStart", (): void => {}); +noble.on("scanStop", (): void => {}); +noble.on("discover", (peripheral: noble.Peripheral): void => { + peripheral.connect((error: string): void => {}); + peripheral.disconnect((): void => {}); +}); + +var peripheral: noble.Peripheral = new noble.Peripheral(); +peripheral.uuid = "12ad4e81"; +peripheral.advertisement = { + localName: "device", + serviceData: new Buffer(1), + txPowerLevel: 1, + manufacturerData: new Buffer(1), + serviceUuids: ["0x180a", "0x180d"] +}; +peripheral.connect((error: string): void => {}); +peripheral.disconnect((): void => {}); +peripheral.discoverServices(["180d"], (error: string, services: noble.Service[]): void => {}); +peripheral.discoverAllServicesAndCharacteristics((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 => {}); + +var service: noble.Service = new noble.Service(); +service.uuid = "180a"; +service.name = ""; +service.type = ""; +service.includedServiceUuids = ["180d"]; +service.discoverIncludedServices(["180d"], (error: string, includedServiceUuids: string[]): void => {}); +service.discoverCharacteristics(["2a38"], (error: string, characteristics: noble.Characteristic[]): void => {}); +service.on("includedServicesDiscover", (includedServiceUuids: string[]): void => {}); +service.on("characteristicsDiscover", (characteristics: noble.Characteristic[]): void => {}); + +var characteristic: noble.Characteristic = new noble.Characteristic(); +characteristic.uuid = "2a37"; +characteristic.name = ""; +characteristic.type = ""; +characteristic.properties = ["read", "notify"]; +characteristic.read((error: string, data: NodeBuffer): void => {}); +characteristic.write(new Buffer(1), true, (error: string): void => {}); +characteristic.broadcast(true, (error: string): void => {}); +characteristic.notify(true, (error: string): 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 => {}); + +var descriptor: noble.Descriptor = new noble.Descriptor(); +descriptor.uuid = ""; +descriptor.name = ""; +descriptor.type = ""; +descriptor.readValue((error: string, data: NodeBuffer): void => {}); +descriptor.writeValue(new Buffer(1), (error: string): void => {}); +descriptor.on("valueRead", (error: string, data: NodeBuffer): void => {}); +descriptor.on("valueWrite", (error: string): void => {}); + diff --git a/noble/noble.d.ts b/noble/noble.d.ts new file mode 100644 index 0000000000..f9c833bd13 --- /dev/null +++ b/noble/noble.d.ts @@ -0,0 +1,106 @@ +// Type definitions for noble +// Project: https://github.com/sandeepmistry/noble +// Definitions by: Seon-Wook Park +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "noble" { + import events = require("events"); + + export function startScanning(): void; + export function startScanning(serviceUUIDs: string[]): void; + export function startScanning(serviceUUIDs: string[], allowDuplicates: boolean): void; + export function stopScanning(): void; + + export function on(event: string, listener: Function): events.EventEmitter; + export function on(event: "stateChange", listener: (state: string) => void): events.EventEmitter; + export function on(event: "scanStart", listener: () => void): events.EventEmitter; + export function on(event: "scanStop", listener: () => void): events.EventEmitter; + export function on(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter; + + export class Peripheral extends events.EventEmitter { + uuid: string; + advertisement: Advertisement; + rssi: number; + services: string[]; + + connect(callback: (error: string) => void): void; + disconnect(callback: () => void): void; + discoverServices(serviceUUIDs: string[], listener: (error: string, services: Service[]) => void): void; + discoverAllServicesAndCharacteristics(callback: (error: string, services: Service[], characteristics: Characteristic[]) => void): void; + discoverSomeServicesAndCharacteristics(serviceUUIDs: string[], characteristicUUIDs: string[], callback: (error: string, services: Service[], characteristics: Characteristic[]) => void): void; + + readHandle(handle: NodeBuffer, callback: (error: string, data: NodeBuffer) => void): void; + writeHandle(handle: NodeBuffer, data: NodeBuffer, withoutResponse: boolean, callback: (error: string) => void): void; + toString(): string; + + on(event: string, listener: Function): events.EventEmitter; + on(event: "connect", listener: (error: string) => void): events.EventEmitter; + on(event: "disconnect", listener: (error: string) => void): events.EventEmitter; + on(event: "rssiUpdate", listener: (rssi: number) => void): events.EventEmitter; + on(event: "servicesDiscover", listener: (services: Service[]) => void): events.EventEmitter; + } + + export interface Advertisement { + localName: string; + serviceData: NodeBuffer; + txPowerLevel: number; + manufacturerData: NodeBuffer; + serviceUuids: string[]; + } + + export class Service extends events.EventEmitter { + uuid: string; + name: string; + type: string; + includedServiceUuids: string[]; + characteristics: Characteristic[]; + + discoverIncludedServices(serviceUUIDs: string[], callback: (error: string, includedServiceUuids: string[]) => void): void; + discoverCharacteristics(characteristicUUIDs: string[], callback: (error: string, characteristics: Characteristic[]) => void): void; + toString(): string; + + on(event: string, listener: Function): events.EventEmitter; + on(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): events.EventEmitter; + on(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): events.EventEmitter; + } + + export class Characteristic extends events.EventEmitter { + uuid: string; + name: string; + type: string; + properties: string[]; + descriptors: Descriptor[]; + + read(callback: (error: string, data: NodeBuffer) => void): void; + write(data: NodeBuffer, notify: boolean, callback: (error: string) => void): void; + broadcast(broadcast: boolean, callback: (error: string) => void): void; + notify(notify: boolean, callback: (error: string) => void): void; + discoverDescriptors(callback: (error: string, descriptors: Descriptor[]) => void): void; + toString(): string; + + on(event: string, listener: Function): events.EventEmitter; + on(event: string, option: boolean, listener: Function): events.EventEmitter; + on(event: "read", listener: (data: NodeBuffer, isNotification: boolean) => void): events.EventEmitter; + on(event: "write", withoutResponse: boolean, listener: (error: string) => void): events.EventEmitter; + on(event: "broadcast", listener: (state: string) => void): events.EventEmitter; + on(event: "notify", listener: (state: string) => void): events.EventEmitter; + on(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): events.EventEmitter; + } + + export class Descriptor extends events.EventEmitter { + uuid: string; + name: string; + type: string; + + readValue(callback: (error: string, data: NodeBuffer) => void): void; + writeValue(data: NodeBuffer, callback: (error: string) => void): void; + toString(): string; + + on(event: string, listener: Function): events.EventEmitter; + on(event: "valueRead", listener: (error: string, data: NodeBuffer) => void): events.EventEmitter; + on(event: "valueWrite", listener: (error: string) => void): events.EventEmitter; + } +} +