From b8e30e877593e8e632a858dbce8115527bf99ff4 Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Mon, 14 Sep 2015 09:51:02 +0300 Subject: [PATCH] Create socket.io.users.d.ts --- socket.io.users/socket.io.users.d.ts | 79 ++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 socket.io.users/socket.io.users.d.ts diff --git a/socket.io.users/socket.io.users.d.ts b/socket.io.users/socket.io.users.d.ts new file mode 100644 index 000000000..f7ee9b2d8 --- /dev/null +++ b/socket.io.users/socket.io.users.d.ts @@ -0,0 +1,79 @@ +// Type definitions for socket.io.users +// Project: https://github.com/nodets/socket.io.users +// Definitions by: Makis Maropoulos +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// +/// +/// + +declare module "socket.io.users" { + import { EventEmitter } from 'events'; + import { Application } from "express"; + import { SessionOptions } from "express-session"; + + var CONNECTION_EVENTS: string[]; + var Middleware: () => (socket: SocketIO.Socket, next: () => any) => void; + var Session: (app: Application, options?: SessionOptions) => void; + + type SocketUserList = { + [namespace: string]: Users; + }; + + class Namespaces { + private static socketUsersList: any; + static attach(namespace: string, socketUsersObj: Users): void; + static get(namespace: string): Users; + } + + class User { + id: string | number; + socket: SocketIO.Socket; + sockets: SocketIO.Socket[]; + rooms: string[]; + ip: string; + remoteAddresses: string[]; + store: any; + attach(socket: SocketIO.Socket): void; + detachSocket(socket: SocketIO.Socket): void; + detach(): void; + join(room: string): boolean; + leave(room: string): void; + leaveAll(): void; + /** same as in, checks if this user is inside a room */ + belong(room: string): boolean; + /** same as belong, checks if this user is inside a room */ + in(room: string): boolean; + set(key: string, value: any, callback?: () => void): void; + get: (key: string) => any; + toString(): string; + emit(...args: any[]): void; + to(room: string): SocketIO.Socket; + } + + + class Users extends EventEmitter { + namespace: string; + users: User[]; + constructor(namespace?: string); + static of(namespace?: string): Users; + takeId: (request: any) => string | number; + create(socket: SocketIO.Socket): User; + getById(id: string | number): User; + get(socket: SocketIO.Socket): User; + list(): User[]; + size(): number; + push(_user: User): void; + add(socket: SocketIO.Socket): User; + indexOf(user: User): number; + remove(user: User): void; + room(room: string): User[]; + in(room: string): User[]; + from(room: string): User[]; + update(user: User): void; + emitAll(...args: any[]): void; + registerSocketEvents(currentUser: User): void; + } + +}