Skip to content

Commit 47ebd39

Browse files
committed
Merge pull request DefinitelyTyped#2361 from pmccloghrylaing/sockjs-node
Added definition for sockjs-node
2 parents 1937051 + aa25033 commit 47ebd39

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ All definitions files include a header with the author and editors, so at some p
291291
* [socket.io](http://socket.io) (by [William Orr](https://github.com/worr))
292292
* [socket.io-client](http://socket.io) (by [Maido Kaara](https://github.com/v3rm0n))
293293
* [SockJS](https://github.com/sockjs/sockjs-client) (by [Emil Ivanov](https://github.com/vladev))
294+
* [sockjs-node](https://github.com/sockjs/sockjs-node) (by [Phil McCloghry-Laing](https://github.com/pmccloghrylaing))
294295
* [SoundJS](http://www.createjs.com/#!/SoundJS) (by [Pedro Ferreira](https://bitbucket.org/drk4))
295296
* [Spin](http://fgnass.github.com/spin.js/) (by [Boris Yankov](https://github.com/borisyankov))
296297
* [sqlite3](https://github.com/mapbox/node-sqlite3) (by [Nick Malaguti](https://github.com/nmalaguti))

sockjs-node/sockjs-node-tests.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/// <reference path="sockjs-node.d.ts" />
2+
import sockjs = require("sockjs");
3+
import http = require("http");
4+
import stream = require("stream");
5+
6+
var server: sockjs.Server,
7+
serverOptions: sockjs.ServerOptions = {};
8+
9+
// createServer method
10+
server = sockjs.createServer();
11+
server = sockjs.createServer(serverOptions);
12+
13+
// installHandlers method
14+
var httpServer: http.Server = http.createServer();
15+
server.installHandlers(httpServer);
16+
server.installHandlers(httpServer, serverOptions);
17+
18+
// serverOptions
19+
serverOptions.sockjs_url = 'http://cdn.sockjs.org/sockjs-0.3.min.js';
20+
serverOptions.prefix = '/prefix';
21+
serverOptions.response_limit = 128000;
22+
serverOptions.websocket = true;
23+
24+
serverOptions.jsessionid = true;
25+
serverOptions.jsessionid = () => true;
26+
27+
serverOptions.log = (severity, message) => { };
28+
serverOptions.heartbeat_delay = 25000;
29+
serverOptions.disconnect_delay = 5000;
30+
31+
// Connection
32+
var connection: sockjs.Connection;
33+
34+
// on('connection') passes a sockJS connection
35+
server.on('connection', (conn) => {
36+
connection = conn;
37+
conn = connection;
38+
});
39+
40+
// connection is a ReadWriteStream
41+
var connectionAsReadWrite: NodeJS.ReadWriteStream = connection;
42+
43+
connection.on('data', (message: string) => { });
44+
connection.on('close', () => { });

sockjs-node/sockjs-node.d.ts

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Type definitions for sockjs-node 0.3.x
2+
// Project: https://github.com/sockjs/sockjs-node
3+
// Definitions by: Phil McCloghry-Laing <https://github.com/pmccloghrylaing>
4+
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped
5+
6+
/// <reference path="../node/node.d.ts" />
7+
8+
declare module "sockjs" {
9+
import http = require('http');
10+
11+
export interface ServerOptions {
12+
sockjs_url?: string;
13+
prefix?: string;
14+
response_limit?: number;
15+
websocket?: boolean;
16+
jsessionid?: any;
17+
log?: (severity: string, message: string) => void;
18+
heartbeat_delay?: number;
19+
disconnect_delay?: number;
20+
}
21+
22+
export function createServer(options?: ServerOptions): Server;
23+
24+
export interface Server extends NodeJS.EventEmitter {
25+
installHandlers(server: http.Server, options?: ServerOptions): any;
26+
27+
on(event: 'connection', listener: (conn: Connection) => any): Server;
28+
on(event: string, listener: Function): Server;
29+
}
30+
31+
export interface Connection extends NodeJS.ReadWriteStream {
32+
remoteAddress: string;
33+
remotePort: number;
34+
address: {
35+
[key: string]: {
36+
address: string;
37+
port: number;
38+
};
39+
};
40+
headers: {
41+
[key: string]: string;
42+
};
43+
url: string;
44+
pathname: string;
45+
prefix: string;
46+
protocol: string;
47+
readyState: number;
48+
49+
close(code?: string, reason?: string): boolean;
50+
destroy(): void;
51+
52+
on(event: 'data', listener: (message: string) => any): Connection;
53+
on(event: 'close', listener: () => void): Connection;
54+
on(event: string, listener: Function): Connection;
55+
}
56+
}

0 commit comments

Comments
 (0)