@eleven-am/pondsocket-client 0.0.5 → 0.0.6
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/README.md +0 -12
- package/browser/client.d.ts +12 -13
- package/core/channel.d.ts +23 -48
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,18 +30,6 @@ const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
|
|
|
30
30
|
|
|
31
31
|
// Start the server
|
|
32
32
|
pond.listen(3000);
|
|
33
|
-
|
|
34
|
-
// Or alternatively, working with express
|
|
35
|
-
import pondSocket from "@eleven-am/pondsocket/express";
|
|
36
|
-
import express from "express";
|
|
37
|
-
|
|
38
|
-
const app = pondSocket(express());
|
|
39
|
-
|
|
40
|
-
const endpoint = app.upgrade('/api/socket', (req, res) => {
|
|
41
|
-
// Handle socket connection and authentication
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
app.listen(3000);
|
|
45
33
|
```
|
|
46
34
|
|
|
47
35
|
Within each endpoint, sockets interact through channels. Channels provide an organized way to group users and manage efficient communication among them. When users join a channel, they can participate in real-time events and exchange information with other users in the same channel.
|
package/browser/client.d.ts
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import { JoinParams } from '@eleven-am/pondsocket-common';
|
|
1
|
+
import { SimpleSubject, SimpleBehaviorSubject, ChannelEvent, JoinParams } from '@eleven-am/pondsocket-common';
|
|
2
2
|
import { Channel } from '../core/channel';
|
|
3
|
-
|
|
4
3
|
export default class PondClient {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
#private;
|
|
5
|
+
protected readonly _address: URL;
|
|
6
|
+
protected _socket: WebSocket | any | undefined;
|
|
7
|
+
protected readonly _broadcaster: SimpleSubject<ChannelEvent>;
|
|
8
|
+
protected readonly _connectionState: SimpleBehaviorSubject<boolean>;
|
|
9
|
+
constructor(endpoint: string, params?: Record<string, any>);
|
|
7
10
|
/**
|
|
8
11
|
* @desc Connects to the server and returns the socket.
|
|
9
12
|
*/
|
|
10
|
-
connect
|
|
11
|
-
|
|
13
|
+
connect(backoff?: number): void;
|
|
12
14
|
/**
|
|
13
15
|
* @desc Returns the current state of the socket.
|
|
14
16
|
*/
|
|
15
|
-
getState
|
|
16
|
-
|
|
17
|
+
getState(): boolean;
|
|
17
18
|
/**
|
|
18
19
|
* @desc Disconnects the socket.
|
|
19
20
|
*/
|
|
20
|
-
disconnect
|
|
21
|
-
|
|
21
|
+
disconnect(): void;
|
|
22
22
|
/**
|
|
23
23
|
* @desc Creates a channel with the given name and params.
|
|
24
24
|
* @param name - The name of the channel.
|
|
25
25
|
* @param params - The params to send to the server.
|
|
26
26
|
*/
|
|
27
|
-
createChannel
|
|
28
|
-
|
|
27
|
+
createChannel(name: string, params?: JoinParams): Channel<import("@eleven-am/pondsocket-common").PondEventMap>;
|
|
29
28
|
/**
|
|
30
29
|
* @desc Subscribes to the connection state.
|
|
31
30
|
* @param callback - The callback to call when the state changes.
|
|
32
31
|
*/
|
|
33
|
-
onConnectionChange
|
|
32
|
+
onConnectionChange(callback: (state: boolean) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
34
33
|
}
|
package/core/channel.d.ts
CHANGED
|
@@ -1,125 +1,100 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
PondPresence,
|
|
4
|
-
PondMessage,
|
|
5
|
-
PresencePayload,
|
|
6
|
-
PondEventMap,
|
|
7
|
-
EventWithResponse,
|
|
8
|
-
PayloadForResponse,
|
|
9
|
-
ResponseForEvent,
|
|
10
|
-
} from '@eleven-am/pondsocket-common';
|
|
11
|
-
|
|
1
|
+
import { SimpleSubject, SimpleBehaviorSubject, ChannelState, JoinParams, ChannelEvent, PondPresence, PondMessage, PresencePayload, PondEventMap, EventWithResponse, PayloadForResponse, ResponseForEvent } from '@eleven-am/pondsocket-common';
|
|
2
|
+
import { Publisher } from '../types';
|
|
12
3
|
export declare class Channel<EventMap extends PondEventMap = PondEventMap> {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(publisher: Publisher, clientState: SimpleBehaviorSubject<boolean>, name: string, receiver: SimpleSubject<ChannelEvent>, params: JoinParams);
|
|
13
6
|
/**
|
|
14
7
|
* @desc Gets the current connection state of the channel.
|
|
15
8
|
*/
|
|
16
|
-
get channelState
|
|
17
|
-
|
|
9
|
+
get channelState(): ChannelState;
|
|
18
10
|
/**
|
|
19
11
|
* @desc Connects to the channel.
|
|
20
12
|
*/
|
|
21
|
-
join
|
|
22
|
-
|
|
13
|
+
join(): void;
|
|
23
14
|
/**
|
|
24
15
|
* @desc Disconnects from the channel.
|
|
25
16
|
*/
|
|
26
|
-
leave
|
|
27
|
-
|
|
17
|
+
leave(): void;
|
|
28
18
|
/**
|
|
29
19
|
* @desc Monitors the channel for messages.
|
|
30
20
|
* @param callback - The callback to call when a message is received.
|
|
31
21
|
*/
|
|
32
|
-
onMessage<Event extends keyof EventMap>
|
|
33
|
-
|
|
22
|
+
onMessage<Event extends keyof EventMap>(callback: (event: Event, message: EventMap[Event]) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
34
23
|
/**
|
|
35
24
|
* @desc Monitors the channel for messages.
|
|
36
25
|
* @param event - The event to monitor.
|
|
37
26
|
* @param callback - The callback to call when a message is received.
|
|
38
27
|
*/
|
|
39
|
-
onMessageEvent<Event extends keyof EventMap>
|
|
40
|
-
|
|
28
|
+
onMessageEvent<Event extends keyof EventMap>(event: Event, callback: (message: EventMap[Event]) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
41
29
|
/**
|
|
42
30
|
* @desc Monitors the channel state of the channel.
|
|
43
31
|
* @param callback - The callback to call when the connection state changes.
|
|
44
32
|
*/
|
|
45
|
-
onChannelStateChange
|
|
46
|
-
|
|
33
|
+
onChannelStateChange(callback: (connected: ChannelState) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
47
34
|
/**
|
|
48
35
|
* @desc Detects when clients join the channel.
|
|
49
36
|
* @param callback - The callback to call when a client joins the channel.
|
|
50
37
|
*/
|
|
51
|
-
onJoin
|
|
52
|
-
|
|
38
|
+
onJoin(callback: (presence: PondPresence) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
53
39
|
/**
|
|
54
40
|
* @desc Detects when clients leave the channel.
|
|
55
41
|
* @param callback - The callback to call when a client leaves the channel.
|
|
56
42
|
*/
|
|
57
|
-
onLeave
|
|
58
|
-
|
|
43
|
+
onLeave(callback: (presence: PondPresence) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
59
44
|
/**
|
|
60
45
|
* @desc Detects when clients change their presence in the channel.
|
|
61
46
|
* @param callback - The callback to call when a client changes their presence in the channel.
|
|
62
47
|
*/
|
|
63
|
-
onPresenceChange
|
|
64
|
-
|
|
48
|
+
onPresenceChange(callback: (presence: PresencePayload) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
65
49
|
/**
|
|
66
50
|
* @desc Sends a message to specific clients in the channel.
|
|
67
51
|
* @param event - The event to send.
|
|
68
52
|
* @param payload - The message to send.
|
|
69
53
|
* @param recipient - The clients to send the message to.
|
|
70
54
|
*/
|
|
71
|
-
sendMessage
|
|
72
|
-
|
|
55
|
+
sendMessage(event: string, payload: PondMessage, recipient: string[]): void;
|
|
73
56
|
/**
|
|
74
57
|
* @desc Sends a message to the server and waits for a response.
|
|
75
58
|
* @param sentEvent - The event to send.
|
|
76
59
|
* @param payload - The message to send.
|
|
77
60
|
*/
|
|
78
|
-
sendForResponse<Event extends EventWithResponse<EventMap>>
|
|
79
|
-
|
|
61
|
+
sendForResponse<Event extends EventWithResponse<EventMap>>(sentEvent: Event, payload: PayloadForResponse<EventMap, Event>): Promise<ResponseForEvent<EventMap, Event>>;
|
|
80
62
|
/**
|
|
81
63
|
* @desc Broadcasts a message to every other client in the channel except yourself.
|
|
82
64
|
* @param event - The event to send.
|
|
83
65
|
* @param payload - The message to send.
|
|
84
66
|
*/
|
|
85
|
-
broadcastFrom<Event extends keyof EventMap>
|
|
86
|
-
|
|
67
|
+
broadcastFrom<Event extends keyof EventMap>(event: Event, payload: EventMap[Event]): void;
|
|
87
68
|
/**
|
|
88
69
|
* @desc Broadcasts a message to the channel, including yourself.
|
|
89
70
|
* @param event - The event to send.
|
|
90
71
|
* @param payload - The message to send.
|
|
91
72
|
*/
|
|
92
|
-
broadcast<Event extends keyof EventMap>
|
|
93
|
-
|
|
73
|
+
broadcast<Event extends keyof EventMap>(event: Event, payload: EventMap[Event]): void;
|
|
94
74
|
/**
|
|
95
75
|
* @desc Gets the current presence of the channel.
|
|
96
76
|
*/
|
|
97
|
-
getPresence
|
|
98
|
-
|
|
77
|
+
getPresence(): PondPresence[];
|
|
99
78
|
/**
|
|
100
79
|
* @desc Monitors the presence of the channel.
|
|
101
80
|
* @param callback - The callback to call when the presence changes.
|
|
102
81
|
*/
|
|
103
|
-
onUsersChange
|
|
104
|
-
|
|
82
|
+
onUsersChange(callback: (users: PondPresence[]) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
105
83
|
/**
|
|
106
84
|
* @desc Checks if the channel is connected.
|
|
107
85
|
*/
|
|
108
|
-
isConnected
|
|
109
|
-
|
|
86
|
+
isConnected(): boolean;
|
|
110
87
|
/**
|
|
111
88
|
* @desc Checks if the channel is stalled.
|
|
112
89
|
*/
|
|
113
|
-
isStalled
|
|
114
|
-
|
|
90
|
+
isStalled(): boolean;
|
|
115
91
|
/**
|
|
116
92
|
* @desc Checks if the channel is closed.
|
|
117
93
|
*/
|
|
118
|
-
isClosed
|
|
119
|
-
|
|
94
|
+
isClosed(): boolean;
|
|
120
95
|
/**
|
|
121
96
|
* @desc Monitors the connection state of the channel.
|
|
122
97
|
* @param callback - The callback to call when the connection state changes.
|
|
123
98
|
*/
|
|
124
|
-
onConnectionChange
|
|
99
|
+
onConnectionChange(callback: (connected: boolean) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
125
100
|
}
|