add socket.io-client 1.2.0

This commit is contained in:
progre
2014-11-04 00:11:09 +09:00
parent d68d470bbd
commit bff52380d6
5 changed files with 145 additions and 42 deletions
@@ -1,10 +1,10 @@
import io = require('socket.io-client');
var socket = io.connect('http://localhost:80');
socket.on('connect', function () {
console.log('Connected!');
socket.emit('event', 'some test data', function () {
console.log('Sent some data.');
});
});
import io = require('socket.io-client-0.9');
var socket = io.connect('http://localhost:80');
socket.on('connect', function () {
console.log('Connected!');
socket.emit('event', 'some test data', function () {
console.log('Sent some data.');
});
});
@@ -0,0 +1,10 @@
/// <reference path="socket.io-client-0.9.d.ts"/>
var socket = io.connect('http://localhost:80');
socket.on('connect', function () {
console.log('Connected!');
socket.emit('event', 'some test data', function () {
console.log('Sent some data.');
});
});
+40
View File
@@ -0,0 +1,40 @@
// Type definitions for socket.io nodejs client
// Project: http://socket.io/
// Definitions by: Maido Kaara <https://github.com/v3rm0n>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "socket.io-client-0.9" {
export = io;
}
declare var io: SocketIOStatic;
interface SocketIOStatic {
connect(host: string, details?: any): SocketIOClient.Socket;
}
declare module SocketIOClient {
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;
}
}
+54 -7
View File
@@ -1,10 +1,57 @@
/// <reference path="socket.io-client.d.ts"/>
var socket = io.connect('http://localhost:80');
socket.on('connect', function () {
console.log('Connected!');
socket.emit('event', 'some test data', function () {
console.log('Sent some data.');
function testUsingWithNodeHTTPServer() {
var socket = io('http://localhost');
socket.on('news', function (data: any) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
});
}
function testUsingWithExpress() {
var socket = io.connect('http://localhost');
socket.on('news', function (data: any) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
}
function testUsingWithTheExpressFramework() {
var socket = io.connect('http://localhost');
socket.on('news', function (data: any) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
}
function testRestrictingYourselfToANamespace() {
var chat = io.connect('http://localhost/chat')
, news = io.connect('http://localhost/news');
chat.on('connect', function () {
chat.emit('hi!');
});
news.on('news', function () {
news.emit('woot');
});
}
function testSendingAndGettingData() {
var socket = io();
socket.on('connect', function () {
socket.emit('ferret', 'tobi', function (data: any) {
console.log(data);
});
});
}
function testUsingItJustAsACrossBrowserWebSocket() {
var socket = io('http://localhost/');
socket.on('connect', function () {
socket.emit('hi');
socket.on('message', function (msg: any) {
});
});
}
+31 -25
View File
@@ -1,40 +1,46 @@
// Type definitions for socket.io nodejs client
// Type definitions for socket.io-client 1.2.0
// Project: http://socket.io/
// Definitions by: Maido Kaara <https://github.com/v3rm0n>
// Definitions by: PROGRE <https://github.com/progre/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "socket.io-client" {
export = io;
///<reference path='../node/node.d.ts' />
declare var io: SocketIOClientStatic;
declare module 'socket.io-client' {
export = io;
}
declare var io: SocketIOStatic;
interface SocketIOStatic {
interface SocketIOClientStatic {
(host: string, details?: any): SocketIOClient.Socket;
(details?: any): SocketIOClient.Socket;
connect(host: string, details?: any): SocketIOClient.Socket;
connect(details?: any): SocketIOClient.Socket;
protocol: number;
Socket: { new (...args: any[]): SocketIOClient.Socket };
Manager: SocketIOClient.ManagerStatic;
}
declare module SocketIOClient {
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 Socket {
on(event: string, fn: Function): Socket;
once(event: string, fn: Function): Socket;
off(event: string, fn: Function): Socket;
emit(event: string, ...args: any[]): Socket;
listeners(event: string): Function[];
hasListeners(event: string): boolean;
}
interface SocketNamespace extends EventEmitter {
of(name: string): SocketNamespace;
send(data: any, fn: Function): SocketNamespace;
emit(name: string): SocketNamespace;
interface ManagerStatic {
(url: string, opts: any): SocketIOClient.Manager;
new (url: string, opts: any): SocketIOClient.Manager;
}
interface Socket extends EventEmitter {
of(name: string): SocketNamespace;
connect(fn: Function): Socket;
packet(data: any): Socket;
flushBuffer(): void;
disconnect(): Socket;
interface Manager {
reconnection(v: boolean): Manager;
reconnectionAttempts(v: boolean): Manager;
reconnectionDelay(v: boolean): Manager;
reconnectionDelayMax(v: boolean): Manager;
timeout(v: boolean): Manager;
}
}