Bleno TypeScript definition added (#15656)

Adding definition and required test for compliance for Bleno library.
This commit is contained in:
Manuel Francisco Naranjo
2017-05-01 15:55:25 -07:00
committed by Mohamed Hegazy
parent 7a49d23bc5
commit cfa517b96e
4 changed files with 207 additions and 0 deletions
+56
View File
@@ -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 ] })],
() => {}
);
}
});
+128
View File
@@ -0,0 +1,128 @@
// Type definitions for bleno 0.4
// Project: https://github.com/sandeepmistry/bleno
// Definitions by: Manuel Francisco Naranjo <naranjo.manuel@gmail.com>
// 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;
+22
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "../tslint.json" }