forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.io.users.d.ts
79 lines (70 loc) · 2.35 KB
/
socket.io.users.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="../express/express.d.ts" />
/// <reference path="../express-session/express-session.d.ts" />
/// <reference path="../socket.io/socket.io.d.ts" />
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;
}
}