From cfa517b96ef57f28c94d56dd50ba68870e1d89fd Mon Sep 17 00:00:00 2001 From: Manuel Francisco Naranjo Date: Mon, 1 May 2017 19:55:25 -0300 Subject: [PATCH] Bleno TypeScript definition added (#15656) Adding definition and required test for compliance for Bleno library. --- types/bleno/bleno-tests.ts | 56 ++++++++++++++++ types/bleno/index.d.ts | 128 +++++++++++++++++++++++++++++++++++++ types/bleno/tsconfig.json | 22 +++++++ types/bleno/tslint.json | 1 + 4 files changed, 207 insertions(+) create mode 100644 types/bleno/bleno-tests.ts create mode 100644 types/bleno/index.d.ts create mode 100644 types/bleno/tsconfig.json create mode 100644 types/bleno/tslint.json diff --git a/types/bleno/bleno-tests.ts b/types/bleno/bleno-tests.ts new file mode 100644 index 0000000000..7dcb47ff35 --- /dev/null +++ b/types/bleno/bleno-tests.ts @@ -0,0 +1,56 @@ +import * as Bleno from 'bleno'; + +export class EchoCharacteristic extends Bleno.Characteristic { + _value: any; + _updateValueCallback: any; + + constructor() { + super({ + uuid: 'ec0e', + properties: ['read', 'write', 'notify'], + value: null + }); + this._value = new ArrayBuffer(0); + this._updateValueCallback = null; + } + + onReadRequest(offset: number, callback: any) { + callback(Bleno.Characteristic.RESULT_SUCCESS, this._value); + } + + onWriteRequest(data: any, offset: number, withoutResponse: boolean, callback: any) { + this._value = data; + + if (this._updateValueCallback) { + this._updateValueCallback(this._value); + } + + callback(Bleno.Characteristic.RESULT_SUCCESS); + } + + onSubscribe(maxValueSize: number, updateValueCallback: any) { + this._updateValueCallback = updateValueCallback; + } + + onUnsubscribefunction() { + this._updateValueCallback = null; + } +} + +Bleno.on('stateChange', (state: string) => { + if (state === 'poweredOn') { + Bleno.startAdvertising('echo', ['ec00'], () => {}); + } else { + Bleno.stopAdvertising(() => {}); + } +}); + +let characteristic = new EchoCharacteristic(); +Bleno.on('advertisingStart', (error: string) => { + if (!error) { + Bleno.setServices( + [new Bleno.PrimaryService({uuid: 'ec00', characteristics: [ characteristic ] })], + () => {} + ); + } +}); diff --git a/types/bleno/index.d.ts b/types/bleno/index.d.ts new file mode 100644 index 0000000000..a59e394a84 --- /dev/null +++ b/types/bleno/index.d.ts @@ -0,0 +1,128 @@ +// Type definitions for bleno 0.4 +// Project: https://github.com/sandeepmistry/bleno +// Definitions by: Manuel Francisco Naranjo +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export class Characteristic { + uuid: any; + properties: any; + secure: any; + value: any; + descriptors: any; + + constructor(options: any); + + onIndicate(): void; + + onNotify(): void; + + onReadRequest(offset: any, callback: any): void; + + onSubscribe(maxValueSize: any, updateValueCallback: any): void; + + onUnsubscribe(): void; + + onWriteRequest(data: any, offset: any, withoutResponse: any, callback: any): void; + + toString(): any; + + static RESULT_ATTR_NOT_LONG: number; + + static RESULT_INVALID_ATTRIBUTE_LENGTH: number; + + static RESULT_INVALID_OFFSET: number; + + static RESULT_SUCCESS: number; + + static RESULT_UNLIKELY_ERROR: number; +} + +export class Descriptor { + uuid: any; + value: any; + + constructor(options: any); + + toString(): any; +} + +export class PrimaryService { + uuid: any; + characteristics: any; + + constructor(options: any); + + toString(): any; +} + +export const address: string; + +export const domain: any; + +export const mtu: number; + +export const platform: string; + +export const rssi: number; + +export const state: string; + +export function addListener(type: any, listener: any): any; + +export function disconnect(): void; + +export function emit(type: any, ...args: any[]): any; + +export function eventNames(): any; + +export function getMaxListeners(): any; + +export function listenerCount(type: any): any; + +export function listeners(type: any): any; + +export function on(type: any, listener: any): any; + +export function onAccept(clientAddress: any): void; + +export function onAddressChange(address: any): void; + +export function onAdvertisingStart(error: any): void; + +export function onAdvertisingStop(): void; + +export function onDisconnect(clientAddress: any): void; + +export function onMtuChange(mtu: any): void; + +export function onPlatform(platform: any): void; + +export function onRssiUpdate(rssi: any): void; + +export function onServicesSet(error: any): void; + +export function onStateChange(state: any): void; + +export function once(type: any, listener: any): any; + +export function prependListener(type: any, listener: any): any; + +export function prependOnceListener(type: any, listener: any): any; + +export function removeAllListeners(type: any, ...args: any[]): any; + +export function removeListener(type: any, listener: any): any; + +export function setMaxListeners(n: any): any; + +export function setServices(services: any, callback: any): void; + +export function startAdvertising(name: any, serviceUuids: any, callback: any): void; + +export function startAdvertisingIBeacon(uuid: any, major: any, minor: any, measuredPower: any, callback: any): void; + +export function startAdvertisingWithEIRData(advertisementData: any, scanData: any, callback: any): void; + +export function stopAdvertising(callback: any): void; + +export function updateRssi(callback: any): void; diff --git a/types/bleno/tsconfig.json b/types/bleno/tsconfig.json new file mode 100644 index 0000000000..44fa6c893f --- /dev/null +++ b/types/bleno/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "bleno-tests.ts" + ] +} diff --git a/types/bleno/tslint.json b/types/bleno/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/types/bleno/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }