forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socketty.d.ts
57 lines (49 loc) · 1.59 KB
/
socketty.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
// Type definitions for Socketty v0.2.2
// Project: https://www.npmjs.com/package/socketty
// Definitions by: Nax <https://github.com/Nax>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare var socketty: Socketty;
declare module 'socketty' {
export = socketty;
}
interface Socketty {
/**
* Connect to a socketty server.
* @param url The server url
* @param callback The callback to be run when the connection is open
* @return A Socket
*/
connect(url: string, callback: (socket: SockettySocket) => void): SockettySocket;
/**
* Create a socketty server.
* @param httpServer The HTTP server to use
* @return A socketty server
*/
createServer(httpServer: any): SockettyServer;
}
interface SockettySocket {
/**
* Listen for an action.
* @param action The action to listen to
* @param callback A callback to be run when the action is fired
*/
on(action: string, callback: (message?: any) => void): void;
/**
* Send an action, as well as an optional message.
* @param action The action to send
* @param message The message to send
*/
send(action: string, message?: any): void;
/**
* Specify a callback to be run when the socket is disconnected.
* @param callback The disconnect callback
*/
disconnect(callback: () => void): void;
}
interface SockettyServer {
/**
* Specify a callback to be run when a new socket connects to the server.
* @param callback The callback
*/
connection(callback: (socket: SockettySocket) => void): void;
}