@eleven-am/pondsocket 0.1.216 → 0.1.217
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abstracts/types.d.ts +12 -9
- package/contexts/baseContext.d.ts +16 -11
- package/contexts/baseContext.js +6 -0
- package/contexts/connectionContext.d.ts +1 -1
- package/contexts/connectionContext.js +4 -1
- package/contexts/eventContext.d.ts +9 -8
- package/contexts/eventContext.js +3 -0
- package/contexts/joinContext.d.ts +10 -10
- package/contexts/joinContext.js +4 -1
- package/contexts/outgoingContext.d.ts +4 -4
- package/engines/endpointEngine.d.ts +2 -2
- package/engines/endpointEngine.js +1 -1
- package/engines/lobbyEngine.d.ts +3 -3
- package/engines/lobbyEngine.js +1 -1
- package/package.json +4 -2
- package/server/server.js +1 -1
- package/wrappers/channel.d.ts +12 -12
- package/wrappers/endpoint.d.ts +2 -2
- package/wrappers/pondChannel.d.ts +9 -9
package/abstracts/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IncomingHttpHeaders } from 'http';
|
|
2
2
|
import { IncomingMessage } from 'node:http';
|
|
3
3
|
import internal from 'node:stream';
|
|
4
|
-
import { ChannelEvent, EventParams,
|
|
4
|
+
import { ChannelEvent, AnyPondSchema, AssignsOf, EventParams, EventsOf, JoinParamsOf, PondAssigns, PondEventMap, PondMessage, PondPresence, ServerActions, SystemSender, Unsubscribe, UserData } from '@eleven-am/pondsocket-common';
|
|
5
5
|
import { WebSocket, WebSocketServer } from 'ws';
|
|
6
6
|
import { ConnectionContext } from '../contexts/connectionContext';
|
|
7
7
|
import { EventContext } from '../contexts/eventContext';
|
|
@@ -17,10 +17,13 @@ export interface SocketRequest {
|
|
|
17
17
|
headers: IncomingHttpHeaders;
|
|
18
18
|
address: string;
|
|
19
19
|
}
|
|
20
|
-
export type
|
|
21
|
-
export type
|
|
22
|
-
export type
|
|
23
|
-
export type
|
|
20
|
+
export type EventPayload<EventMap extends PondEventMap, Event extends keyof EventMap> = EventMap[Event] extends [PondMessage, PondMessage] ? EventMap[Event][0] : EventMap[Event];
|
|
21
|
+
export type EventResponse<EventMap extends PondEventMap, Event extends keyof EventMap> = EventMap[Event] extends [PondMessage, PondMessage] ? EventMap[Event][1] : PondMessage;
|
|
22
|
+
export type EventKey<Schema extends AnyPondSchema> = Extract<keyof EventsOf<Schema>, string>;
|
|
23
|
+
export type ConnectionHandler<Path extends string> = (ctx: ConnectionContext<Path>, next: NextFunction) => unknown | Promise<unknown>;
|
|
24
|
+
export type AuthorizationHandler<Path extends string, Schema extends AnyPondSchema = AnyPondSchema> = (ctx: JoinContext<Path, Schema>, next: NextFunction) => unknown | Promise<unknown>;
|
|
25
|
+
export type EventHandler<Path extends string, Schema extends AnyPondSchema = AnyPondSchema, Event extends EventKey<Schema> = EventKey<Schema>> = (ctx: EventContext<Path, Schema, Event>, next: NextFunction) => unknown | Promise<unknown>;
|
|
26
|
+
export type OutgoingEventHandler<Path extends string, Schema extends AnyPondSchema = AnyPondSchema, Event extends EventKey<Schema> = EventKey<Schema>> = (event: OutgoingContext<Path, Schema, Event>, next: NextFunction) => EventPayload<EventsOf<Schema>, Event> | Promise<EventPayload<EventsOf<Schema>, Event>> | void | Promise<void>;
|
|
24
27
|
export interface ConnectionParams {
|
|
25
28
|
head: Buffer;
|
|
26
29
|
socket: internal.Duplex;
|
|
@@ -39,10 +42,10 @@ export interface ConnectionResponseOptions {
|
|
|
39
42
|
params: ConnectionParams;
|
|
40
43
|
webSocketServer: WebSocketServer;
|
|
41
44
|
}
|
|
42
|
-
export interface JoinRequestOptions<Path extends string> {
|
|
45
|
+
export interface JoinRequestOptions<Path extends string, Schema extends AnyPondSchema = AnyPondSchema> {
|
|
43
46
|
clientId: string;
|
|
44
|
-
assigns:
|
|
45
|
-
joinParams:
|
|
47
|
+
assigns: AssignsOf<Schema>;
|
|
48
|
+
joinParams: JoinParamsOf<Schema>;
|
|
46
49
|
params: EventParams<Path>;
|
|
47
50
|
}
|
|
48
51
|
export interface RequestCache extends SocketCache {
|
|
@@ -59,7 +62,7 @@ export type BroadcastEvent = Omit<InternalChannelEvent, 'action' | 'payload' | '
|
|
|
59
62
|
payload: PondMessage;
|
|
60
63
|
};
|
|
61
64
|
export interface LeaveEvent {
|
|
62
|
-
user: UserData
|
|
65
|
+
user: UserData<PondPresence, PondAssigns>;
|
|
63
66
|
channel: Channel;
|
|
64
67
|
}
|
|
65
68
|
export type LeaveCallback = (event: LeaveEvent) => void;
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import { ChannelReceivers, EventParams, PondEvent, PondMessage, PondObject, UserAssigns, UserPresences } from '@eleven-am/pondsocket-common';
|
|
1
|
+
import { ChannelReceivers, AnyPondSchema, AssignsOf, EventParams, EventPayload, EventsOf, PondEvent, PondMessage, PondObject, PresenceOf, UserAssigns, UserPresences } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { ChannelEngine } from '../engines/channelEngine';
|
|
3
3
|
import { Channel } from '../wrappers/channel';
|
|
4
|
-
export declare abstract class BaseContext<Path extends string> {
|
|
4
|
+
export declare abstract class BaseContext<Path extends string, Schema extends AnyPondSchema = AnyPondSchema, EventName extends Extract<keyof EventsOf<Schema>, string> = Extract<keyof EventsOf<Schema>, string>, Payload extends PondMessage = EventPayload<EventsOf<Schema>, EventName>> {
|
|
5
5
|
#private;
|
|
6
|
-
constructor(engine: ChannelEngine, params: EventParams<Path>, event: string, payload:
|
|
7
|
-
get event(): PondEvent<Path
|
|
6
|
+
protected constructor(engine: ChannelEngine, params: EventParams<Path>, event: string, payload: Payload, sender: string);
|
|
7
|
+
get event(): PondEvent<Path> & {
|
|
8
|
+
event: EventName;
|
|
9
|
+
payload: Payload;
|
|
10
|
+
};
|
|
11
|
+
get query(): EventParams<Path>['query'];
|
|
12
|
+
get params(): EventParams<Path>['params'];
|
|
8
13
|
get channelName(): string;
|
|
9
|
-
get channel(): Channel
|
|
10
|
-
get presences(): UserPresences
|
|
11
|
-
get assigns(): UserAssigns
|
|
12
|
-
get user(): import("@eleven-am/pondsocket-common").UserData<
|
|
13
|
-
broadcast(event:
|
|
14
|
-
broadcastFrom(event:
|
|
15
|
-
broadcastTo(event:
|
|
14
|
+
get channel(): Channel<Schema>;
|
|
15
|
+
get presences(): UserPresences<PresenceOf<Schema>>;
|
|
16
|
+
get assigns(): UserAssigns<AssignsOf<Schema>>;
|
|
17
|
+
get user(): import("@eleven-am/pondsocket-common").UserData<PresenceOf<Schema>, AssignsOf<Schema>> | null;
|
|
18
|
+
broadcast<Event extends Extract<keyof EventsOf<Schema>, string>>(event: Event, payload: EventPayload<EventsOf<Schema>, Event>): this;
|
|
19
|
+
broadcastFrom<Event extends Extract<keyof EventsOf<Schema>, string>>(event: Event, payload: EventPayload<EventsOf<Schema>, Event>): this;
|
|
20
|
+
broadcastTo<Event extends Extract<keyof EventsOf<Schema>, string>>(event: Event, payload: EventPayload<EventsOf<Schema>, Event>, userIds: string | string[]): this;
|
|
16
21
|
protected abstract _sendMessageToRecipients(recipient: ChannelReceivers, event: string, payload: PondObject): void;
|
|
17
22
|
protected get engine(): ChannelEngine;
|
|
18
23
|
protected get sender(): string;
|
package/contexts/baseContext.js
CHANGED
|
@@ -36,6 +36,12 @@ class BaseContext {
|
|
|
36
36
|
payload: __classPrivateFieldGet(this, _BaseContext_payload, "f"),
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
get query() {
|
|
40
|
+
return __classPrivateFieldGet(this, _BaseContext_params, "f").query;
|
|
41
|
+
}
|
|
42
|
+
get params() {
|
|
43
|
+
return __classPrivateFieldGet(this, _BaseContext_params, "f").params;
|
|
44
|
+
}
|
|
39
45
|
get channelName() {
|
|
40
46
|
return __classPrivateFieldGet(this, _BaseContext_engine, "f").name;
|
|
41
47
|
}
|
|
@@ -115,7 +115,10 @@ class ConnectionContext {
|
|
|
115
115
|
/**
|
|
116
116
|
* Accepts the connection request
|
|
117
117
|
*/
|
|
118
|
-
accept() {
|
|
118
|
+
accept(assigns) {
|
|
119
|
+
if (assigns) {
|
|
120
|
+
this.assign(assigns);
|
|
121
|
+
}
|
|
119
122
|
__classPrivateFieldGet(this, _ConnectionContext_instances, "m", _ConnectionContext_performChecks).call(this);
|
|
120
123
|
__classPrivateFieldGet(this, _ConnectionContext_webSocketServer, "f").handleUpgrade(__classPrivateFieldGet(this, _ConnectionContext_params, "f").request, __classPrivateFieldGet(this, _ConnectionContext_params, "f").socket, __classPrivateFieldGet(this, _ConnectionContext_params, "f").head, (ws) => {
|
|
121
124
|
const cache = {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { ChannelReceivers, EventParams,
|
|
1
|
+
import { ChannelReceivers, AnyPondSchema, AssignsOf, EventParams, EventPayload, EventsOf, PondObject, PresenceOf } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { BaseContext } from './baseContext';
|
|
3
3
|
import { BroadcastEvent } from '../abstracts/types';
|
|
4
4
|
import { ChannelEngine } from '../engines/channelEngine';
|
|
5
|
-
export declare class EventContext<Path extends string> extends BaseContext<Path
|
|
5
|
+
export declare class EventContext<Path extends string, Schema extends AnyPondSchema = AnyPondSchema, EventName extends Extract<keyof EventsOf<Schema>, string> = Extract<keyof EventsOf<Schema>, string>> extends BaseContext<Path, Schema, EventName, EventPayload<EventsOf<Schema>, EventName>> {
|
|
6
6
|
#private;
|
|
7
7
|
constructor(event: BroadcastEvent, params: EventParams<Path>, engine: ChannelEngine);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
get payload(): EventPayload<EventsOf<Schema>, EventName>;
|
|
9
|
+
assign(assigns: Partial<AssignsOf<Schema>>): EventContext<Path, Schema, EventName>;
|
|
10
|
+
reply<Event extends Extract<keyof EventsOf<Schema>, string>>(event: Event, payload: EventPayload<EventsOf<Schema>, Event>): this;
|
|
11
|
+
trackPresence(presence: PresenceOf<Schema>, userId?: string): EventContext<Path, Schema, EventName>;
|
|
12
|
+
updatePresence(presence: Partial<PresenceOf<Schema>>, userId?: string): EventContext<Path, Schema, EventName>;
|
|
13
|
+
evictUser(reason: string, userId?: string): EventContext<Path, Schema, EventName>;
|
|
14
|
+
removePresence(userId?: string): EventContext<Path, Schema, EventName>;
|
|
14
15
|
protected _sendMessageToRecipients(recipient: ChannelReceivers, event: string, payload: PondObject): void;
|
|
15
16
|
}
|
package/contexts/eventContext.js
CHANGED
|
@@ -23,6 +23,9 @@ class EventContext extends baseContext_1.BaseContext {
|
|
|
23
23
|
__classPrivateFieldSet(this, _EventContext_event, event, "f");
|
|
24
24
|
__classPrivateFieldSet(this, _EventContext_requestId, event.requestId, "f");
|
|
25
25
|
}
|
|
26
|
+
get payload() {
|
|
27
|
+
return __classPrivateFieldGet(this, _EventContext_event, "f").payload;
|
|
28
|
+
}
|
|
26
29
|
assign(assigns) {
|
|
27
30
|
this.channel.updateAssigns(__classPrivateFieldGet(this, _EventContext_event, "f").sender, assigns);
|
|
28
31
|
return this;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { ChannelReceivers,
|
|
1
|
+
import { ChannelReceivers, AnyPondSchema, AssignsOf, EventsOf, JoinParamsOf, PondMessage, PondObject, PresenceOf, UserData } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { BaseContext } from './baseContext';
|
|
3
3
|
import { JoinRequestOptions, RequestCache } from '../abstracts/types';
|
|
4
4
|
import { ChannelEngine } from '../engines/channelEngine';
|
|
5
|
-
export declare class JoinContext<Path extends string> extends BaseContext<Path
|
|
5
|
+
export declare class JoinContext<Path extends string, Schema extends AnyPondSchema = AnyPondSchema> extends BaseContext<Path, Schema, Extract<keyof EventsOf<Schema>, string>, JoinParamsOf<Schema>> {
|
|
6
6
|
#private;
|
|
7
|
-
constructor(options: JoinRequestOptions<Path>, engine: ChannelEngine, user: RequestCache);
|
|
8
|
-
get user(): UserData
|
|
9
|
-
get joinParams():
|
|
7
|
+
constructor(options: JoinRequestOptions<Path, Schema>, engine: ChannelEngine, user: RequestCache);
|
|
8
|
+
get user(): UserData<PresenceOf<Schema>, AssignsOf<Schema>>;
|
|
9
|
+
get joinParams(): JoinParamsOf<Schema>;
|
|
10
10
|
get hasResponded(): boolean;
|
|
11
|
-
accept(): JoinContext<Path>;
|
|
12
|
-
decline(message?: string, errorCode?: number): JoinContext<Path>;
|
|
13
|
-
assign(assigns:
|
|
14
|
-
reply(event: string, payload: PondMessage): JoinContext<Path>;
|
|
15
|
-
trackPresence(presence:
|
|
11
|
+
accept(assigns?: Partial<AssignsOf<Schema>>): JoinContext<Path, Schema>;
|
|
12
|
+
decline(message?: string, errorCode?: number): JoinContext<Path, Schema>;
|
|
13
|
+
assign(assigns: Partial<AssignsOf<Schema>>): JoinContext<Path, Schema>;
|
|
14
|
+
reply(event: string, payload: PondMessage): JoinContext<Path, Schema>;
|
|
15
|
+
trackPresence(presence: PresenceOf<Schema>): JoinContext<Path, Schema>;
|
|
16
16
|
protected _sendMessageToRecipients(recipient: ChannelReceivers, event: string, payload: PondObject): void;
|
|
17
17
|
}
|
package/contexts/joinContext.js
CHANGED
|
@@ -44,8 +44,11 @@ class JoinContext extends baseContext_1.BaseContext {
|
|
|
44
44
|
get hasResponded() {
|
|
45
45
|
return __classPrivateFieldGet(this, _JoinContext_executed, "f");
|
|
46
46
|
}
|
|
47
|
-
accept() {
|
|
47
|
+
accept(assigns) {
|
|
48
48
|
var _a;
|
|
49
|
+
if (assigns) {
|
|
50
|
+
this.assign(assigns);
|
|
51
|
+
}
|
|
49
52
|
__classPrivateFieldGet(this, _JoinContext_instances, "m", _JoinContext_performChecks).call(this);
|
|
50
53
|
const onMessage = this.engine.parent.parent.sendMessage.bind(this.engine.parent.parent, __classPrivateFieldGet(this, _JoinContext_user, "f").socket);
|
|
51
54
|
const subscription = this.engine.addUser(__classPrivateFieldGet(this, _JoinContext_user, "f").clientId, __classPrivateFieldGet(this, _JoinContext_newAssigns, "f"), onMessage);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ChannelReceivers, Event, EventParams,
|
|
1
|
+
import { ChannelReceivers, AnyPondSchema, Event, EventParams, EventPayload, EventsOf, PondObject } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { BaseContext } from './baseContext';
|
|
3
3
|
import { ChannelEngine } from '../engines/channelEngine';
|
|
4
|
-
export declare class OutgoingContext<Path extends string> extends BaseContext<Path
|
|
4
|
+
export declare class OutgoingContext<Path extends string, Schema extends AnyPondSchema = AnyPondSchema, EventName extends Extract<keyof EventsOf<Schema>, string> = Extract<keyof EventsOf<Schema>, string>> extends BaseContext<Path, Schema, EventName, EventPayload<EventsOf<Schema>, EventName>> {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(event: Event, params: EventParams<Path>, engine: ChannelEngine, userid: string);
|
|
7
|
-
get payload():
|
|
7
|
+
get payload(): EventPayload<EventsOf<Schema>, EventName>;
|
|
8
8
|
/**
|
|
9
9
|
* Blocks the outgoing context, preventing further processing of the event.
|
|
10
10
|
*/
|
|
@@ -18,7 +18,7 @@ export declare class OutgoingContext<Path extends string> extends BaseContext<Pa
|
|
|
18
18
|
* Transforms the outgoing context with a new payload.
|
|
19
19
|
* @param payload - The new payload to set for the context.
|
|
20
20
|
*/
|
|
21
|
-
transform(payload:
|
|
21
|
+
transform(payload: EventPayload<EventsOf<Schema>, EventName>): this;
|
|
22
22
|
/**
|
|
23
23
|
* Updates the parameters of the outgoing context.
|
|
24
24
|
* @param params - The new parameters to set for the context.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChannelEvent, PondPath } from '@eleven-am/pondsocket-common';
|
|
1
|
+
import { ChannelEvent, AnyPondSchema, PondPath } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { WebSocket } from 'ws';
|
|
3
3
|
import { AuthorizationHandler, SocketCache } from '../abstracts/types';
|
|
4
4
|
import { IDistributedBackend } from '../types';
|
|
@@ -10,7 +10,7 @@ export declare class EndpointEngine {
|
|
|
10
10
|
/**
|
|
11
11
|
* Creates a new channel on a specified path
|
|
12
12
|
*/
|
|
13
|
-
createChannel<Path extends string>(path: PondPath<Path>, handler: AuthorizationHandler<Path>): PondChannel
|
|
13
|
+
createChannel<Path extends string, Schema extends AnyPondSchema = AnyPondSchema>(path: PondPath<Path>, handler: AuthorizationHandler<Path, Schema>): PondChannel<Schema>;
|
|
14
14
|
/**
|
|
15
15
|
* Gets all connected clients
|
|
16
16
|
*/
|
|
@@ -52,7 +52,7 @@ class EndpointEngine {
|
|
|
52
52
|
};
|
|
53
53
|
const channel = lobbyEngine.getOrCreateChannel(user.channelName);
|
|
54
54
|
const context = new joinContext_1.JoinContext(options, channel, user);
|
|
55
|
-
return handler(context, next);
|
|
55
|
+
return Promise.resolve(handler(context, next)).then(() => undefined);
|
|
56
56
|
}
|
|
57
57
|
next();
|
|
58
58
|
});
|
package/engines/lobbyEngine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Event, PondPath } from '@eleven-am/pondsocket-common';
|
|
1
|
+
import { AnyPondSchema, Event, EventsOf, PondPath } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { ChannelEngine } from './channelEngine';
|
|
3
3
|
import { EndpointEngine } from './endpointEngine';
|
|
4
4
|
import { Middleware } from '../abstracts/middleware';
|
|
@@ -20,11 +20,11 @@ export declare class LobbyEngine {
|
|
|
20
20
|
/**
|
|
21
21
|
* Attaches a handler for a specific event pattern
|
|
22
22
|
*/
|
|
23
|
-
onEvent<
|
|
23
|
+
onEvent<Schema extends AnyPondSchema, Path extends Extract<keyof EventsOf<Schema>, string>>(event: PondPath<Path>, handler: EventHandler<Path, Schema, Path>): void;
|
|
24
24
|
/**
|
|
25
25
|
* Attaches a handler for outgoing events
|
|
26
26
|
*/
|
|
27
|
-
handleOutgoingEvent<
|
|
27
|
+
handleOutgoingEvent<Schema extends AnyPondSchema, Path extends Extract<keyof EventsOf<Schema>, string>>(event: PondPath<Path>, handler: OutgoingEventHandler<Path, Schema, Path>): void;
|
|
28
28
|
/**
|
|
29
29
|
* Processes an outgoing event, applying middleware and returning a new event
|
|
30
30
|
* @param event - The channel event to process
|
package/engines/lobbyEngine.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.217",
|
|
4
4
|
"description": "PondSocket is a fast simple socket server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"socket",
|
|
@@ -43,7 +43,9 @@
|
|
|
43
43
|
"url": "git+https://github.com/Eleven-am/pondSocket.git"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@eleven-am/pondsocket-common": "^0.0.
|
|
46
|
+
"@eleven-am/pondsocket-common": "^0.0.39",
|
|
47
|
+
"@types/node": "^25.3.3",
|
|
48
|
+
"@types/ws": "^8.18.1",
|
|
47
49
|
"redis": "^5.12.1",
|
|
48
50
|
"ws": "^8.20.1"
|
|
49
51
|
},
|
package/server/server.js
CHANGED
|
@@ -93,7 +93,7 @@ class PondSocket {
|
|
|
93
93
|
webSocketServer: __classPrivateFieldGet(this, _PondSocket_socketServer, "f"),
|
|
94
94
|
};
|
|
95
95
|
const context = new connectionContext_1.ConnectionContext(request, newParams);
|
|
96
|
-
return handler(context, next);
|
|
96
|
+
return Promise.resolve(handler(context, next)).then(() => undefined);
|
|
97
97
|
});
|
|
98
98
|
return new endpoint_1.Endpoint(endpoint);
|
|
99
99
|
}
|
package/wrappers/channel.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyPondSchema, AssignsOf, EventsOf, EventPayload, PresenceOf, UserData, UserAssigns, UserPresences } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { ChannelEngine } from '../engines/channelEngine';
|
|
3
|
-
export declare class Channel {
|
|
3
|
+
export declare class Channel<Schema extends AnyPondSchema = AnyPondSchema> {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(engine: ChannelEngine);
|
|
6
6
|
/**
|
|
7
7
|
* Gets a user's data
|
|
8
8
|
*/
|
|
9
|
-
getUserData(userId: string):
|
|
9
|
+
getUserData(userId: string): UserData<PresenceOf<Schema>, AssignsOf<Schema>> | null;
|
|
10
10
|
/**
|
|
11
11
|
* Gets all presence data
|
|
12
12
|
*/
|
|
13
|
-
getPresences():
|
|
13
|
+
getPresences(): UserPresences<PresenceOf<Schema>>;
|
|
14
14
|
/**
|
|
15
15
|
* Gets all assigns data
|
|
16
16
|
*/
|
|
17
|
-
getAssigns():
|
|
17
|
+
getAssigns(): UserAssigns<AssignsOf<Schema>>;
|
|
18
18
|
/**
|
|
19
19
|
* Broadcasts a message to all users
|
|
20
20
|
*/
|
|
21
|
-
broadcast(event:
|
|
21
|
+
broadcast<Event extends Extract<keyof EventsOf<Schema>, string>>(event: Event, payload: EventPayload<EventsOf<Schema>, Event>): this;
|
|
22
22
|
/**
|
|
23
23
|
* Broadcasts a message from a specific user to all others
|
|
24
24
|
*/
|
|
25
|
-
broadcastFrom(userId: string, event:
|
|
25
|
+
broadcastFrom<Event extends Extract<keyof EventsOf<Schema>, string>>(userId: string, event: Event, payload: EventPayload<EventsOf<Schema>, Event>): this;
|
|
26
26
|
/**
|
|
27
27
|
* Broadcasts a message to specific users
|
|
28
28
|
*/
|
|
29
|
-
broadcastTo(userIds: string | string[], event:
|
|
29
|
+
broadcastTo<Event extends Extract<keyof EventsOf<Schema>, string>>(userIds: string | string[], event: Event, payload: EventPayload<EventsOf<Schema>, Event>): this;
|
|
30
30
|
/**
|
|
31
31
|
* Kicks a user from the channel
|
|
32
32
|
*/
|
|
@@ -34,11 +34,11 @@ export declare class Channel {
|
|
|
34
34
|
/**
|
|
35
35
|
* Tracks a user's presence
|
|
36
36
|
*/
|
|
37
|
-
trackPresence(userId: string, presence:
|
|
37
|
+
trackPresence(userId: string, presence: PresenceOf<Schema>): this;
|
|
38
38
|
/**
|
|
39
39
|
* Updates a user's presence
|
|
40
40
|
*/
|
|
41
|
-
updatePresence(userId: string, presence:
|
|
41
|
+
updatePresence(userId: string, presence: Partial<PresenceOf<Schema>>): this;
|
|
42
42
|
/**
|
|
43
43
|
* Removes a user's presence
|
|
44
44
|
*/
|
|
@@ -46,9 +46,9 @@ export declare class Channel {
|
|
|
46
46
|
/**
|
|
47
47
|
* Adds or updates a user's presence
|
|
48
48
|
*/
|
|
49
|
-
upsertPresence(userId: string, presence:
|
|
49
|
+
upsertPresence(userId: string, presence: PresenceOf<Schema>): this;
|
|
50
50
|
/**
|
|
51
51
|
* Updates a user's assigns
|
|
52
52
|
*/
|
|
53
|
-
updateAssigns(userId: string, assigns:
|
|
53
|
+
updateAssigns(userId: string, assigns: Partial<AssignsOf<Schema>>): this;
|
|
54
54
|
}
|
package/wrappers/endpoint.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { PondPath } from '@eleven-am/pondsocket-common';
|
|
1
|
+
import { AnyPondSchema, PondPath } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { AuthorizationHandler } from '../abstracts/types';
|
|
3
3
|
import { EndpointEngine } from '../engines/endpointEngine';
|
|
4
4
|
export declare class Endpoint {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(engine: EndpointEngine);
|
|
7
|
-
createChannel<Path extends string>(path: PondPath<Path>, handler: AuthorizationHandler<Path>): import("./pondChannel").PondChannel
|
|
7
|
+
createChannel<Path extends string, Schema extends AnyPondSchema = AnyPondSchema>(path: PondPath<Path>, handler: AuthorizationHandler<Path, Schema>): import("./pondChannel").PondChannel<Schema>;
|
|
8
8
|
closeConnection(clientIds: string | string[]): void;
|
|
9
9
|
getClients(): import("ws").WebSocket[];
|
|
10
10
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyPondSchema, EventPayload, EventsOf, PondPath } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { Channel } from './channel';
|
|
3
3
|
import { EventHandler, LeaveCallback, OutgoingEventHandler } from '../abstracts/types';
|
|
4
4
|
import { LobbyEngine } from '../engines/lobbyEngine';
|
|
5
|
-
export declare class PondChannel {
|
|
5
|
+
export declare class PondChannel<Schema extends AnyPondSchema = AnyPondSchema> {
|
|
6
6
|
#private;
|
|
7
7
|
constructor(lobby: LobbyEngine);
|
|
8
|
-
onEvent<Event extends string
|
|
9
|
-
onLeave(callback: LeaveCallback): PondChannel
|
|
10
|
-
handleOutgoingEvent<Event extends string
|
|
11
|
-
getChannel(channelName: string): Channel | null;
|
|
12
|
-
broadcast(channelName: string, event:
|
|
13
|
-
broadcastFrom(channelName: string, userId: string, event:
|
|
14
|
-
broadcastTo(channelName: string, userIds: string | string[], event:
|
|
8
|
+
onEvent<Event extends Extract<keyof EventsOf<Schema>, string>>(event: PondPath<Event>, handler: EventHandler<Event, Schema, Event>): PondChannel<Schema>;
|
|
9
|
+
onLeave(callback: LeaveCallback): PondChannel<Schema>;
|
|
10
|
+
handleOutgoingEvent<Event extends Extract<keyof EventsOf<Schema>, string>>(event: PondPath<Event>, handler: OutgoingEventHandler<Event, Schema, Event>): this;
|
|
11
|
+
getChannel(channelName: string): Channel<Schema> | null;
|
|
12
|
+
broadcast<Event extends Extract<keyof EventsOf<Schema>, string>>(channelName: string, event: Event, payload: EventPayload<EventsOf<Schema>, Event>): PondChannel<Schema>;
|
|
13
|
+
broadcastFrom<Event extends Extract<keyof EventsOf<Schema>, string>>(channelName: string, userId: string, event: Event, payload: EventPayload<EventsOf<Schema>, Event>): PondChannel<Schema>;
|
|
14
|
+
broadcastTo<Event extends Extract<keyof EventsOf<Schema>, string>>(channelName: string, userIds: string | string[], event: Event, payload: EventPayload<EventsOf<Schema>, Event>): PondChannel<Schema>;
|
|
15
15
|
}
|