DefinitelyTyped/types/socket.io.users/index.d.ts
Oliver Joseph Ash 3cd6ad7fa4 Express: use generics for params, default to dictionary (#37718)
* Revert "Express: improve type of `Request['params']` aka `req.params` (#37502)"

This reverts commit 9aa863ef23.

* Express: use generics for params, default to dictionary

* Lint

* Bump all dependants

* Spacing

* Bump dependants

* Bump dependants

* Bump dependants

* Bump dependants

* Bump dependants

* Bump dependants

* Bump dependants

* Bump dependants

* Bump dependants

* Bump dependants

* Bump dependants (via tests)

* Bump dependants

* Bump dependants (via tests)

* Bump dependants

* Simplify test

* Hoist imports

* Tidy test

* Add tests

* Add reasons

* Remove redundant params

* Add tests

* Format

* Remove redundant params

* Add tests

* Add JSDoc

* Improve comment

* Improve comment
2019-08-18 17:47:36 -07:00

74 lines
2.3 KiB
TypeScript

// Type definitions for socket.io.users
// Project: https://github.com/nodets/socket.io.users
// Definitions by: Makis Maropoulos <https://github.com/kataras>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { EventEmitter } from 'events';
import { Application } from "express";
import { SessionOptions } from "express-session";
import SocketIO = require("socket.io");
declare var CONNECTION_EVENTS: string[];
declare var Middleware: () => (socket: SocketIO.Socket, next: () => any) => void;
declare var Session: (app: Application, options?: SessionOptions) => void;
type SocketUserList = {
[namespace: string]: Users;
};
declare class Namespaces {
private static socketUsersList: any;
static attach(namespace: string, socketUsersObj: Users): void;
static get(namespace: string): Users;
}
declare 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;
}
declare 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;
}