Merge pull request #5916 from fnipo/meshblu

Add definitions for meshblu 1.30.1
This commit is contained in:
Masahiro Wakame
2015-09-20 21:53:12 +09:00
2 changed files with 404 additions and 0 deletions

123
meshblu/meshblu-tests.ts Normal file
View File

@@ -0,0 +1,123 @@
/// <reference path="meshblu.d.ts" />
import Meshblu = require('meshblu');
var UUID = "26de691f-8068-4cdc-907a-4cb5961a1aba";
var TOKEN = "4cb5961a1aba26de691f80684cdc907a";
var meshblu = Meshblu.createConnection({
uuid: UUID,
token: TOKEN
});
meshblu.data({
uuid: UUID,
online: true,
x: -53,
y: 234
}, function(result) {
console.log(result);
});
meshblu.device({
uuid: UUID
}, function(result) {
console.log(result);
});
meshblu.devices({
color: "green"
}, function(result) {
console.log(result);
});
meshblu.generateAndStoreToken({
uuid: UUID
}, function(result) {
console.log(result);
});
meshblu.getdata({
uuid: UUID,
start: "2015-04-23T18:25:43.511Z",
finish: "2015-04-24T18:25:43.511Z",
limit: 10
}, function(result) {
console.log(result);
});
meshblu.identify();
meshblu.message({
devices: [UUID],
topic: "status",
payload: {
online: true
}
}, function(result) {
console.log(result);
});
meshblu.register({
type: "drone"
}, function(result) {
console.log(result);
});
meshblu.revokeToken({
uuid: UUID,
token: TOKEN
}, function(result) {
console.log(result);
});
meshblu.subscribe({
uuid: UUID
}, function(result) {
console.log(result);
});
meshblu.subscribe({
uuid: UUID,
types: ["sent", "received"]
}, function(result) {
console.log(result);
});
meshblu.subscribe({
uuid: UUID,
types: ["sent", "received"],
topics: ["device*", "-*status"]
}, function(result) {
console.log(result);
});
meshblu.unsubscribe({
uuid: UUID
}, function(result) {
console.log(result);
});
meshblu.unsubscribe({
uuid: UUID,
types: ["sent", "broadcast"]
}, function(result) {
console.log(result);
});
meshblu.update({
uuid: UUID,
color: "blue"
}, function(result) {
console.log(result);
});
meshblu.whoami({}, function(result) {
console.log(result);
});
meshblu.unregister({
uuid: UUID
}, function(result) {
console.log(result);
});

281
meshblu/meshblu.d.ts vendored Normal file
View File

@@ -0,0 +1,281 @@
// Type definitions for meshblu.js 1.30.1
// Project: https://github.com/octoblu/meshblu-npm
// Definitions by: Felipe Nipo <https://github.com/fnipo>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path='../node/node.d.ts' />
declare module 'meshblu' {
var Meshblu: MeshbluStatic;
export = Meshblu;
}
interface MeshbluStatic {
/**
* Establish a secure socket.io connection to Meshblu.
* @param opt
* @returns A Meshblu Connection.
*/
createConnection(opt: Meshblu.ConnectionOptions): Meshblu.Connection;
}
declare module Meshblu {
interface Connection {
/**
* Authenticate with Meshblu.
* @returns This Connection.
*/
identify(): Connection;
/**
* @param data {string|number|object|array|Buffer} - data for signing.
*/
sign(data: any): string;
/**
* @param message {string|number|object|array|Buffer} - signed data.
* @param signature
* @returns {*}
*/
verify(message: any, signature: any): any;
/**
* @param uuid
* @param message {string|number|object|array|Buffer} - data for encrypting.
* @param options
* @param fn The callback to be called. It should take one parameter, result,
* which is an object containing a property "error".
* @returns This Connection.
*/
encryptMessage(uuid: string, message: any, options: Meshblu.ConnectionOptions, fn:(result: any) => void): Connection;
/**
* Send a meshblu message.
* @param payload An array of devices UUIDs.
* @param fn The callback to be called. It should take one parameter, result,
* which is an object containing a property "error".
* @returns This Connection.
*/
message(payload: MessagePayload, fn:(result: any) => void): Connection;
/**
* Update a device record.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
update(data: UpdateData, fn:(result: UpdateSuccess) => void): Connection;
/**
* Register a new device record.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
register(data: RegisterData, fn:(result: RegisterResponse) => void): Connection;
/**
* Removes a device record.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
unregister(data: Device, fn:(result: Device) => void): Connection;
/**
* Get my device info.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
whoami(data: any, fn:(result: DeviceResponse) => void): Connection;
/**
* Find a Meshblu device.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
device(data: Device, fn:(result: DeviceResponse) => void): Connection
/**
* Find Meshblu devices.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
devices(data: Color, fn:(result: DeviceResponse[]) => void): Connection
/**
* Returns device messages as they are sent and received.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
subscribe(data: SubscribeData, fn:(result: any) => void): Connection
/**
* Cancels device subscription.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
unsubscribe(data: UnsubscribeData, fn:(result: any) => void): Connection
/**
* Send a meshblu data message.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
data(data: DataInput, fn:(result: any) => void): Connection
/**
* Get a meshblu data for a device.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
* @returns This Connection.
*/
getdata(data: GetDataInput, fn:(result: any) => void): Connection
/**
* Generate a new session token for a device.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
*/
generateAndStoreToken(data: Device, fn:(result: ConnectionOptions) => void): void
/**
* Remove a session token from a device.
* @param data
* @param fn The callback to be called. It should take one parameter, result.
*/
revokeToken(data: ConnectionOptions, fn:(result: Device) => void): void
/**
*
* @param uuid
* @param fn The callback to be called. It should take one parameter, err,
* which will be null if there was no problem, and one parameter, publicKey,
* of type NodeRSA.
*/
getPublicKey(uuid: string, fn:(err: Error, publicKey: any) => void): void;
/*
* Lack of documentation about these api functions.
*/
send(text: string): Connection;
bufferedSocketEmit(): void;
parseUrl(serverUrl: string, port: string): string;
generateKeyPair(): KeyPair;
setPrivateKey(privateKey: string): void;
setup(): Connection;
connect(): void;
reconnect(): void;
claimdevice(data: Device, fn:(result: Device) => void): Connection;
mydevices(data: any, fn:(result: any) => void): Connection
status(data: any): Connection
authenticate(data: any, fn:(result: any) => void): Connection
events(data: any, fn:(result: any) => void): Connection
localdevices(fn:(result: any) => void): Connection
unclaimeddevices(data: any, fn:(result: any) => void): Connection
textBroadcast(data: any): Connection
directText(data: any): Connection
subscribeText(data: any, fn:(result: any) => void): Connection
unsubscribeText(data: any, fn:(result: any) => void): Connection
close(fn:(result: any) => void): Connection
resetToken(data: any, fn:(result: any) => void): void
}
/**
* Contains the primary means of identifying a device.
*/
interface ConnectionOptions {
uuid: string;
token: string;
}
interface KeyPair {
privateKey: string;
publicKey: string;
}
interface MessagePayload {
devices: string[];
topic: string;
payload: any;
qos?: number;
}
interface UpdateData {
uuid: string;
color: string;
}
interface UpdateSuccess {
uuid: string;
token: string;
status: string;
}
interface RegisterData {
type: string;
}
interface RegisterResponse {
uuid: string;
token: string;
type: string;
}
interface Device {
uuid: string;
}
interface DeviceResponse {
uuid: string;
online: boolean;
color: string;
}
interface Color {
color: string;
}
interface SubscribeData {
uuid: string;
types?: string[];
topics?: string[];
}
interface UnsubscribeData {
uuid: string;
types?: string[];
}
interface DataInput {
uuid: string;
online: boolean;
x: number;
y: number;
}
interface GetDataInput {
uuid: string;
start: string;
finish: string;
limit: number;
}
interface IdentifySuccess {
uuid: string;
token: string;
status: string;
}
}