From cbca947722c7bf81b4e2d1324609d04248339bc1 Mon Sep 17 00:00:00 2001 From: Phil McCloghry-Laing Date: Tue, 18 Mar 2014 12:49:45 +1100 Subject: [PATCH 1/2] Added definition for sockjs-node --- CONTRIBUTORS.md | 1 + sockjs-node/sockjs-node.d.ts | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 sockjs-node/sockjs-node.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4c2fbc8e1..3aebce86b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -286,6 +286,7 @@ All definitions files include a header with the author and editors, so at some p * [socket.io](http://socket.io) (by [William Orr](https://github.com/worr)) * [socket.io-client](http://socket.io) (by [Maido Kaara](https://github.com/v3rm0n)) * [SockJS](https://github.com/sockjs/sockjs-client) (by [Emil Ivanov](https://github.com/vladev)) +* [sockjs-node](https://github.com/sockjs/sockjs-node) (by [Phil McCloghry-Laing](https://github.com/pmccloghrylaing)) * [SoundJS](http://www.createjs.com/#!/SoundJS) (by [Pedro Ferreira](https://bitbucket.org/drk4)) * [Spin](http://fgnass.github.com/spin.js/) (by [Boris Yankov](https://github.com/borisyankov)) * [sqlite3](https://github.com/mapbox/node-sqlite3) (by [Nick Malaguti](https://github.com/nmalaguti)) diff --git a/sockjs-node/sockjs-node.d.ts b/sockjs-node/sockjs-node.d.ts new file mode 100644 index 000000000..99e4663b7 --- /dev/null +++ b/sockjs-node/sockjs-node.d.ts @@ -0,0 +1,56 @@ +// Type definitions for sockjs-node 0.3.x +// Project: https://github.com/sockjs/sockjs-node +// Definitions by: Phil McCloghry-Laing +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "sockjs" { + import http = require('http'); + + export interface ServerOptions { + sockjs_url?: string; + prefix?: string; + response_limit?: number; + websocket?: boolean; + jsessionid?: any; + log?: (severity: string, message: string) => void; + heartbeat_delay?: number; + disconnect_delay?: number; + } + + export function createServer(options?: ServerOptions): Server; + + export interface Server extends NodeJS.EventEmitter { + installHandlers(server: http.Server, options?: ServerOptions): any; + + on(event: 'connection', listener: (conn: Connection) => any): Server; + on(event: string, listener: Function): Server; + } + + export interface Connection extends NodeJS.ReadWriteStream { + remoteAddress: string; + remotePort: number; + address: { + [key: string]: { + address: string; + port: number; + }; + }; + headers: { + [key: string]: string; + }; + url: string; + pathname: string; + prefix: string; + protocol: string; + readyState: number; + + close(code?: string, reason?: string): boolean; + destroy(): void; + + on(event: 'data', listener: (message: string) => any): Connection; + on(event: 'close', listener: () => void): Connection; + on(event: string, listener: Function): Connection; + } +} From aa25033360d0653711bd12faa24fb6d9082cb103 Mon Sep 17 00:00:00 2001 From: Phil McCloghry-Laing Date: Thu, 19 Jun 2014 14:15:27 +1000 Subject: [PATCH 2/2] Added tests for sockjs-node --- sockjs-node/sockjs-node-tests.ts | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sockjs-node/sockjs-node-tests.ts diff --git a/sockjs-node/sockjs-node-tests.ts b/sockjs-node/sockjs-node-tests.ts new file mode 100644 index 000000000..25e5b496a --- /dev/null +++ b/sockjs-node/sockjs-node-tests.ts @@ -0,0 +1,44 @@ +/// +import sockjs = require("sockjs"); +import http = require("http"); +import stream = require("stream"); + +var server: sockjs.Server, + serverOptions: sockjs.ServerOptions = {}; + +// createServer method +server = sockjs.createServer(); +server = sockjs.createServer(serverOptions); + +// installHandlers method +var httpServer: http.Server = http.createServer(); +server.installHandlers(httpServer); +server.installHandlers(httpServer, serverOptions); + +// serverOptions +serverOptions.sockjs_url = 'http://cdn.sockjs.org/sockjs-0.3.min.js'; +serverOptions.prefix = '/prefix'; +serverOptions.response_limit = 128000; +serverOptions.websocket = true; + +serverOptions.jsessionid = true; +serverOptions.jsessionid = () => true; + +serverOptions.log = (severity, message) => { }; +serverOptions.heartbeat_delay = 25000; +serverOptions.disconnect_delay = 5000; + +// Connection +var connection: sockjs.Connection; + +// on('connection') passes a sockJS connection +server.on('connection', (conn) => { + connection = conn; + conn = connection; +}); + +// connection is a ReadWriteStream +var connectionAsReadWrite: NodeJS.ReadWriteStream = connection; + +connection.on('data', (message: string) => { }); +connection.on('close', () => { });