Skip to content

Commit 96d8cf0

Browse files
committed
- Added socket.io
- Small fixes on node definitions
1 parent 758852c commit 96d8cf0

File tree

2 files changed

+222
-2
lines changed

2 files changed

+222
-2
lines changed

node.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ interface EventEmitter {
8383
removeAllListener(event: string): void;
8484
setMaxListeners(n: number): void;
8585
listeners(event: string): { Function; }[];
86-
emit(event: string, arg1?: any, arg2?: any): void;
86+
//emit(event: string, arg1?: any, arg2?: any): void;
87+
emit(event: string, ...args: any[]): void;
8788
}
8889

8990
interface WritableStream extends EventEmitter {
@@ -749,7 +750,7 @@ declare module "fs" {
749750
export function readlink(path: string, callback?: (err: Error, linkString: string) =>any): void;
750751
export function realpath(path: string, callback?: (err: Error, resolvedPath: string) =>any): void;
751752
export function realpath(path: string, cache: string, callback: (err: Error, resolvedPath: string) =>any): void;
752-
export function realpathSync(path: string, cache?: string): void;
753+
export function realpathSync(path: string, cache?: string): string;
753754
export function unlink(path: string, callback?: Function): void;
754755
export function unlinkSync(path: string): void;
755756
export function rmdir(path: string, callback?: Function): void;

socket.io.d.ts

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/*
2+
Example:
3+
4+
/// SERVER
5+
6+
import sio = module("socket.io");
7+
import http = module("http");
8+
9+
var httpServer = http.createServer(app);
10+
11+
var io = sio.listen(httpServer);
12+
io.sockets.on('connection', function (socket: sio.Socket) {
13+
socket.emit('news', { hello: 'world' });
14+
socket.on('my other event', function (data) {
15+
console.log(data);
16+
});
17+
});
18+
19+
httpServer.listen(app.get('port'), function () {
20+
21+
/// CLIENT
22+
23+
<script src="/socket.io/socket.io.js"></script>
24+
<script>
25+
var socket = io.connect('http://localhost');
26+
socket.on('news', function (data) {
27+
console.log(data);
28+
socket.emit('my other event', { my: 'data' });
29+
});
30+
</script>
31+
{% endblock %}
32+
33+
*/
34+
35+
module "socket.io" {
36+
export var version : string;
37+
export var protocol: number;
38+
export var clientVersion : string;
39+
export function listen(server : any, options? : ManagerOptions, fn?) : Manager;
40+
41+
export interface Manager {
42+
constructor (server, options : ManagerOptions);
43+
server : any;
44+
namespaces;
45+
sockets : SocketNamespace;
46+
settings : ManagerOptions;
47+
store;
48+
log;
49+
static;
50+
get(key);
51+
set(key, value);
52+
enable(key);
53+
disable(key);
54+
enabled(key);
55+
disabled(key);
56+
configure(env, fn);
57+
//initStore();
58+
//onHandshake(id, data);
59+
//onConnect(id);
60+
//onOpen(id);
61+
//onDispatch(room, packet, volatile, exceptions);
62+
//onJoin(id, name);
63+
//onLeave(id, room);
64+
//onClose(id);
65+
//onClientDispatch(id, packet);
66+
//onClientMessage(id, packet);
67+
//onClientDisconnect(id, reason);
68+
//onDisconnect(id, reason);
69+
//handleRequest(req, res);
70+
//handleUpgrade(req, socket, head);
71+
//handleHTTPRequest(data, req, res);
72+
//handleClient(data, req);
73+
//generateId();
74+
//handleHandshake(data, req, res);
75+
//handshakeData(data);
76+
//verifyOrigin(request);
77+
//handlePacket(sessid, packet);
78+
//authorize(data, fn);
79+
//transports(data);
80+
//checkRequest(req);
81+
of(nsp);
82+
//garbageCollection();
83+
}
84+
85+
export interface SocketNamespace extends EventEmitter {
86+
manager;
87+
name;
88+
sockets;
89+
auth: bool;
90+
clients(room) : any[];
91+
log;
92+
store;
93+
json : bool;
94+
volatile: bool;
95+
in(room) : SocketNamespace;
96+
to(room) : SocketNamespace;
97+
except(id) : SocketNamespace;
98+
//setFlags(): SocketNamespace;
99+
//packet(packet): SocketNamespace;
100+
send(data: any): SocketNamespace;
101+
socket(sid, readable?);
102+
authorization(fn): SocketNamespace;
103+
// handleDisconnect(sid, reason, raiseOnDisconnect);
104+
// authorize(data, fn)
105+
// handlePacket(sessid, packet)
106+
//
107+
}
108+
109+
export interface Socket extends EventEmitter {
110+
id;
111+
namespace : SocketNamespace;
112+
manager : Manager;
113+
disconnected : bool;
114+
ackPackets: number;
115+
acks: any;
116+
readable: bool;
117+
store;
118+
handshake;
119+
transport;
120+
log: bool;
121+
json: bool;
122+
volatile: bool;
123+
broadcast : bool;
124+
in(room) : SocketNamespace;
125+
to(room) : SocketNamespace;
126+
//setFlags();
127+
//onDisconnect(reason)
128+
join(name, fn) : Socket;
129+
leave(name, fn) : Socket;
130+
//packet(packet);
131+
//dispatch(packet, volatile);
132+
set(key, value, fn) : Socket;
133+
get(key, fn) : Socket;
134+
has(key, fn) : Socket;
135+
del(key, fn) : Socket;
136+
disconnect() : Socket;
137+
send(data, fn) : Socket;
138+
on(name: string, callback : Function) : Socket;
139+
emit(name, ...arguments: any[]) : Socket;
140+
}
141+
142+
export interface StoreClient {
143+
store : Store;
144+
id;
145+
146+
//get(key, fn);
147+
//set(key, value, fn);
148+
//has(key, fn);
149+
//del(key, fn);
150+
//destroy(expiration);
151+
}
152+
153+
export interface Store extends EventEmitter {
154+
constructor (options);
155+
client(id) : StoreClient;
156+
destroyClient(id, expiration);
157+
destroy(expiration);
158+
159+
//publish();
160+
//subscribe();
161+
//unsubscribe();
162+
}
163+
164+
export interface MemoryStore extends Store { }
165+
export interface RedisStore extends Store {
166+
constructor (opts: RedisStoreOptions);
167+
}
168+
169+
export interface Transport {
170+
}
171+
172+
export interface Static {
173+
}
174+
175+
export interface parser {
176+
}
177+
178+
export interface RedisStoreOptions {
179+
nodeId?: Function; // (fn) gets an id that uniquely identifies this node
180+
redis?: Function; // (fn) redis constructor, defaults to redis
181+
redisPub?: any; // (object) options to pass to the pub redis client
182+
redisSub?: any; // (object) options to pass to the sub redis client
183+
redisClient?: any; // (object) options to pass to the general redis client
184+
pack?: Function; // (fn) custom packing, defaults to JSON or msgpack if installed
185+
unpack?: Function; // (fn) custom packing, defaults to JSON or msgpack if installed
186+
}
187+
188+
export interface ManagerOptions {
189+
origins?; // : '*:*'
190+
log?; // : true
191+
store? : Store; // : new MemoryStore;
192+
logger?; // : new Logger
193+
static?;// : new Static(this)
194+
heartbeats?;// : true
195+
resource?;// : '/socket.io'
196+
transports?;// : defaultTransports
197+
authorization?;//: false
198+
blacklist?;//: ['disconnect']
199+
//'log level'?;//: 3
200+
//'log colors'?;//: tty.isatty(process.stdout.fd)
201+
//'close timeout'?;//: 60
202+
//'heartbeat interval'?;//: 25
203+
//'heartbeat timeout'?;//: 60
204+
//'polling duration'?;//: 20
205+
//'flash policy server'?;//: true
206+
//'flash policy port'?;//: 10843
207+
//'destroy upgrade'?;//: true
208+
//'destroy buffer size'?;//: 10E7
209+
//'browser client'?;//: true
210+
//'browser client cache'?;//: true
211+
//'browser client minification'?;//: false
212+
//'browser client etag'?;//: false
213+
//'browser client expires'?;//: 315360000
214+
//'browser client gzip'?;//: false
215+
//'browser client handler'?;//: false
216+
//'client store expiration'?;//: 15
217+
//'match origin protocol'?;//: false
218+
}
219+
}

0 commit comments

Comments
 (0)