From 8265a175698b41774b3b467292856f5de3719e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maido=20Ka=CC=88a=CC=88ra?= Date: Sun, 16 Feb 2014 13:51:13 +0000 Subject: [PATCH] Type definitions for server side nodejs socket.io client. --- README.md | 1 + socket.io-client/socket.io-client-tests.ts | 10 +++++++ socket.io-client/socket.io-client.d.ts | 33 ++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 socket.io-client/socket.io-client-tests.ts create mode 100644 socket.io-client/socket.io-client.d.ts diff --git a/README.md b/README.md index 251263010..4ce7c2ca1 100755 --- a/README.md +++ b/README.md @@ -233,6 +233,7 @@ List of Definitions * [SlickGrid](https://github.com/mleibman/SlickGrid) (by [Josh Baldwin](https://github.com/jbaldwin)) * [smoothie](https://github.com/joewalnes/smoothie) (by [Mike H. Hawley](https://github.com/mikehhawley)) * [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)) * [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)) diff --git a/socket.io-client/socket.io-client-tests.ts b/socket.io-client/socket.io-client-tests.ts new file mode 100644 index 000000000..9c6018a19 --- /dev/null +++ b/socket.io-client/socket.io-client-tests.ts @@ -0,0 +1,10 @@ +import io = require('socket.io-client'); + +var socket = io('http://localhost:80'); + +socket.on('connect', function () { + console.log('Connected!'); + socket.send('some test data', function () { + console.log('Sent some data.'); + }); +}); \ No newline at end of file diff --git a/socket.io-client/socket.io-client.d.ts b/socket.io-client/socket.io-client.d.ts new file mode 100644 index 000000000..0bef47c58 --- /dev/null +++ b/socket.io-client/socket.io-client.d.ts @@ -0,0 +1,33 @@ +// Type definitions for socket.io nodejs client +// Project: http://socket.io/ +// Definitions by: Maido Kaara +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "socket.io-client" { + + export function connect(host: string, details?: any): Socket; + + interface EventEmitter { + emit(name: string, ...data: any[]): any; + on(ns: string, fn: Function): EventEmitter; + addListener(ns: string, fn: Function): EventEmitter; + removeListener(ns: string, fn: Function): EventEmitter; + removeAllListeners(ns: string): EventEmitter; + once(ns: string, fn: Function): EventEmitter; + listeners(ns: string): Function[]; + } + + interface SocketNamespace extends EventEmitter { + of(name: string): SocketNamespace; + send(data: any, fn: Function): SocketNamespace; + emit(name: string): SocketNamespace; + } + + interface Socket extends EventEmitter { + of(name: string): SocketNamespace; + connect(fn: Function): Socket; + packet(data: any): Socket; + flushBuffer(): void; + disconnect(): Socket; + } +} \ No newline at end of file