forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meshblu.d.ts
281 lines (238 loc) · 7.06 KB
/
meshblu.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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;
}
}