@fishjam-cloud/ts-client 0.25.0 → 0.25.2
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/dist/index.d.mts +43 -0
- package/dist/index.mjs +1 -1
- package/dist/index.react-native.mjs +17 -0
- package/dist/protobufs/fishjam/media_events/peer/peer.d.ts +130 -0
- package/dist/protobufs/fishjam/media_events/peer/peer.js +1283 -0
- package/dist/protobufs/fishjam/media_events/server/server.d.ts +197 -0
- package/dist/protobufs/fishjam/media_events/server/server.js +2121 -0
- package/dist/protobufs/fishjam/media_events/shared.d.ts +48 -0
- package/dist/protobufs/fishjam/media_events/shared.js +315 -0
- package/dist/protobufs/fishjam/peer_notifications.d.ts +83 -0
- package/dist/protobufs/fishjam/peer_notifications.js +559 -0
- package/dist/ts-client/package.json +82 -0
- package/dist/ts-client/src/FishjamClient.d.ts +438 -0
- package/dist/ts-client/src/FishjamClient.js +821 -0
- package/dist/ts-client/src/auth.d.ts +3 -0
- package/dist/ts-client/src/auth.js +8 -0
- package/dist/ts-client/src/connectEventsHandler.d.ts +2 -0
- package/dist/ts-client/src/connectEventsHandler.js +22 -0
- package/dist/ts-client/src/errors.d.ts +3 -0
- package/dist/ts-client/src/errors.js +5 -0
- package/dist/ts-client/src/guards.d.ts +7 -0
- package/dist/ts-client/src/guards.js +8 -0
- package/dist/ts-client/src/index.d.ts +9 -0
- package/dist/ts-client/src/index.js +6 -0
- package/dist/ts-client/src/livestream.d.ts +20 -0
- package/dist/ts-client/src/livestream.js +78 -0
- package/dist/ts-client/src/messageQueue.d.ts +13 -0
- package/dist/ts-client/src/messageQueue.js +23 -0
- package/dist/ts-client/src/reconnection.d.ts +27 -0
- package/dist/ts-client/src/reconnection.js +124 -0
- package/dist/ts-client/src/tests/messageQueue.test.d.ts +1 -0
- package/dist/ts-client/src/tests/messageQueue.test.js +54 -0
- package/dist/ts-client/src/types.d.ts +216 -0
- package/dist/ts-client/src/types.js +1 -0
- package/dist/ts-client/src/version.d.ts +1 -0
- package/dist/ts-client/src/version.js +2 -0
- package/package.json +18 -11
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import type { PeerMessage_SdkDeprecation } from '@fishjam-cloud/protobufs/fishjamPeer';
|
|
2
|
+
import type { BandwidthLimit, DataCallback, DataChannelOptions, SimulcastConfig, TrackBandwidthLimit, Variant } from '@fishjam-cloud/webrtc-client';
|
|
3
|
+
import type TypedEmitter from 'typed-emitter';
|
|
4
|
+
import type { Component, ConnectConfig, CreateConfig, FishjamTrackContext, GenericMetadata, MessageEvents, Peer, TrackMetadata } from './types';
|
|
5
|
+
declare const FishjamClient_base: {
|
|
6
|
+
new <P, S>(): TypedEmitter<MessageEvents<P, S>>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* FishjamClient is the main class to interact with Fishjam.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const client = new FishjamClient<PeerMetadata>();
|
|
14
|
+
* const peerToken = "YOUR_PEER_TOKEN";
|
|
15
|
+
*
|
|
16
|
+
* // You can listen to events emitted by the client
|
|
17
|
+
* client.on("joined", (peerId, peersInRoom) => {
|
|
18
|
+
* console.log("join success");
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Start the peer connection
|
|
22
|
+
* client.connect({
|
|
23
|
+
* peerMetadata: {},
|
|
24
|
+
* isSimulcastOn: false,
|
|
25
|
+
* token: peerToken
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Close the peer connection
|
|
29
|
+
* client.disconnect();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* You can register callbacks to handle the events emitted by the Client.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
*
|
|
37
|
+
* client.on("trackReady", (ctx) => {
|
|
38
|
+
* console.log("On track ready");
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class FishjamClient<PeerMetadata = GenericMetadata, ServerMetadata = GenericMetadata> extends FishjamClient_base<PeerMetadata, ServerMetadata> {
|
|
43
|
+
private websocket;
|
|
44
|
+
private webrtc;
|
|
45
|
+
private removeEventListeners;
|
|
46
|
+
private debug;
|
|
47
|
+
private logger;
|
|
48
|
+
private clientType;
|
|
49
|
+
status: 'new' | 'initialized';
|
|
50
|
+
private connectConfig;
|
|
51
|
+
private isAudioOnlyConnection;
|
|
52
|
+
private reconnectManager;
|
|
53
|
+
private peerMessageQueue;
|
|
54
|
+
private sendStatisticsInterval;
|
|
55
|
+
constructor(config?: CreateConfig);
|
|
56
|
+
/**
|
|
57
|
+
* Uses the WebSocket connection and {@link !WebRTCEndpoint | WebRTCEndpoint} to join to the room. Registers the callbacks to
|
|
58
|
+
* handle the events emitted by the {@link !WebRTCEndpoint | WebRTCEndpoint}. Make sure that peer metadata is serializable.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const client = new FishjamClient<PeerMetadata>();
|
|
63
|
+
*
|
|
64
|
+
* client.connect({
|
|
65
|
+
* peerMetadata: {},
|
|
66
|
+
* token: peerToken
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param {ConnectConfig} config - Configuration object for the client
|
|
71
|
+
*/
|
|
72
|
+
connect(config: ConnectConfig<PeerMetadata>): Promise<void>;
|
|
73
|
+
private initConnection;
|
|
74
|
+
private getUrl;
|
|
75
|
+
private initWebsocket;
|
|
76
|
+
handleSdkDeprecation(sdkDeprecation: PeerMessage_SdkDeprecation): void;
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves statistics related to the RTCPeerConnection.
|
|
79
|
+
* These statistics provide insights into the performance and status of the connection.
|
|
80
|
+
*
|
|
81
|
+
* @return {Promise<RTCStatsReport>}
|
|
82
|
+
*
|
|
83
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats | MDN Web Docs: RTCPeerConnection.getStats()}
|
|
84
|
+
*/
|
|
85
|
+
getStatistics(selector?: MediaStreamTrack | null): Promise<RTCStatsReport>;
|
|
86
|
+
/**
|
|
87
|
+
* Returns a snapshot of currently received remote tracks.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* if (client.getRemoteTracks()[trackId]?.simulcastConfig?.enabled) {
|
|
91
|
+
* client.setTargetTrackEncoding(trackId, encoding);
|
|
92
|
+
* }
|
|
93
|
+
*/
|
|
94
|
+
getRemoteTracks(): Readonly<Record<string, FishjamTrackContext>>;
|
|
95
|
+
/**
|
|
96
|
+
* Returns a snapshot of currently received remote peers.
|
|
97
|
+
*/
|
|
98
|
+
getRemotePeers(): Record<string, Peer<PeerMetadata, ServerMetadata>>;
|
|
99
|
+
getRemoteComponents(): Record<string, Component>;
|
|
100
|
+
getLocalPeer(): Peer<PeerMetadata, ServerMetadata> | null;
|
|
101
|
+
getBandwidthEstimation(): bigint;
|
|
102
|
+
private isConnectingRelatedEvent;
|
|
103
|
+
private setupCallbacks;
|
|
104
|
+
private sendStatistics;
|
|
105
|
+
/**
|
|
106
|
+
* Register a callback to be called when the event is emitted.
|
|
107
|
+
* Full list of callbacks can be found here {@link MessageEvents}.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const callback = ()=>{ };
|
|
112
|
+
*
|
|
113
|
+
* client.on("onJoinSuccess", callback);
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @param event - Event name from {@link MessageEvents}
|
|
117
|
+
* @param listener - Callback function to be called when the event is emitted
|
|
118
|
+
* @returns This
|
|
119
|
+
*/
|
|
120
|
+
on<E extends keyof MessageEvents<PeerMetadata, ServerMetadata>>(event: E, listener: MessageEvents<PeerMetadata, ServerMetadata>[E]): this;
|
|
121
|
+
/**
|
|
122
|
+
* Remove a callback from the list of callbacks to be called when the event is emitted.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const callback = ()=>{ };
|
|
127
|
+
*
|
|
128
|
+
* client.on("onJoinSuccess", callback);
|
|
129
|
+
*
|
|
130
|
+
* client.off("onJoinSuccess", callback);
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @param event - Event name from {@link MessageEvents}
|
|
134
|
+
* @param listener - Reference to function to be removed from called callbacks
|
|
135
|
+
* @returns This
|
|
136
|
+
*/
|
|
137
|
+
off<E extends keyof MessageEvents<PeerMetadata, ServerMetadata>>(event: E, listener: MessageEvents<PeerMetadata, ServerMetadata>[E]): this;
|
|
138
|
+
private handleWebRTCNotInitialized;
|
|
139
|
+
/**
|
|
140
|
+
* Adds track that will be sent to the RTC Engine.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const localStream: MediaStream = new MediaStream();
|
|
145
|
+
* try {
|
|
146
|
+
* const localAudioStream = await navigator.mediaDevices.getUserMedia(
|
|
147
|
+
* { audio: true }
|
|
148
|
+
* );
|
|
149
|
+
* localAudioStream
|
|
150
|
+
* .getTracks()
|
|
151
|
+
* .forEach((track) => localStream.addTrack(track));
|
|
152
|
+
* } catch (error) {
|
|
153
|
+
* console.error("Couldn't get microphone permission:", error);
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* try {
|
|
157
|
+
* const localVideoStream = await navigator.mediaDevices.getUserMedia(
|
|
158
|
+
* { video: true }
|
|
159
|
+
* );
|
|
160
|
+
* localVideoStream
|
|
161
|
+
* .getTracks()
|
|
162
|
+
* .forEach((track) => localStream.addTrack(track));
|
|
163
|
+
* } catch (error) {
|
|
164
|
+
* console.error("Couldn't get camera permission:", error);
|
|
165
|
+
* }
|
|
166
|
+
*
|
|
167
|
+
* localStream
|
|
168
|
+
* .getTracks()
|
|
169
|
+
* .forEach((track) => client.addTrack(track, localStream));
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @param track - Audio or video track e.g. from your microphone or camera.
|
|
173
|
+
* @param trackMetadata - Any information about this track that other peers will receive in
|
|
174
|
+
* {@link MessageEvents.peerJoined}. E.g. this can source of the track - wheather it's screensharing, webcam or some
|
|
175
|
+
* other media device.
|
|
176
|
+
* @param simulcastConfig - Simulcast configuration. By default, simulcast is disabled. For more information refer to
|
|
177
|
+
* {@link !SimulcastConfig | SimulcastConfig}.
|
|
178
|
+
* @param maxBandwidth - Maximal bandwidth this track can use. Defaults to 0 which is unlimited. This option has no
|
|
179
|
+
* effect for simulcast and audio tracks. For simulcast tracks use {@link FishjamClient.setTrackBandwidth}.
|
|
180
|
+
* @returns {string} Returns id of added track
|
|
181
|
+
*/
|
|
182
|
+
addTrack(track: MediaStreamTrack, trackMetadata?: TrackMetadata, simulcastConfig?: SimulcastConfig, maxBandwidth?: TrackBandwidthLimit): Promise<string>;
|
|
183
|
+
/**
|
|
184
|
+
* Replaces a track that is being sent to the RTC Engine.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* // setup camera
|
|
189
|
+
* let localStream: MediaStream = new MediaStream();
|
|
190
|
+
* try {
|
|
191
|
+
* localVideoStream = await navigator.mediaDevices.getUserMedia(
|
|
192
|
+
* VIDEO_CONSTRAINTS
|
|
193
|
+
* );
|
|
194
|
+
* localVideoStream
|
|
195
|
+
* .getTracks()
|
|
196
|
+
* .forEach((track) => localStream.addTrack(track));
|
|
197
|
+
* } catch (error) {
|
|
198
|
+
* console.error("Couldn't get camera permission:", error);
|
|
199
|
+
* }
|
|
200
|
+
* let oldTrackId;
|
|
201
|
+
* localStream
|
|
202
|
+
* .getTracks()
|
|
203
|
+
* .forEach((track) => trackId = webrtc.addTrack(track, localStream));
|
|
204
|
+
*
|
|
205
|
+
* // change camera
|
|
206
|
+
* const oldTrack = localStream.getVideoTracks()[0];
|
|
207
|
+
* let videoDeviceId = "abcd-1234";
|
|
208
|
+
* navigator.mediaDevices.getUserMedia({
|
|
209
|
+
* video: {
|
|
210
|
+
* ...(VIDEO_CONSTRAINTS as {}),
|
|
211
|
+
* deviceId: {
|
|
212
|
+
* exact: videoDeviceId,
|
|
213
|
+
* },
|
|
214
|
+
* }
|
|
215
|
+
* })
|
|
216
|
+
* .then((stream) => {
|
|
217
|
+
* let videoTrack = stream.getVideoTracks()[0];
|
|
218
|
+
* webrtc.replaceTrack(oldTrackId, videoTrack);
|
|
219
|
+
* })
|
|
220
|
+
* .catch((error) => {
|
|
221
|
+
* console.error('Error switching camera', error);
|
|
222
|
+
* })
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* @param {string} trackId - Id of audio or video track to replace.
|
|
226
|
+
* @param {MediaStreamTrack} newTrack - New audio or video track.
|
|
227
|
+
* @returns {Promise<boolean>} Success
|
|
228
|
+
*/
|
|
229
|
+
replaceTrack(trackId: string, newTrack: MediaStreamTrack | null): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Updates maximum bandwidth for the track identified by trackId. This value directly translates to quality of the
|
|
232
|
+
* stream and, in case of video, to the amount of RTP packets being sent. In case trackId points at the simulcast
|
|
233
|
+
* track bandwidth is split between all of the variant streams proportionally to their resolution.
|
|
234
|
+
*
|
|
235
|
+
* @param {string} trackId
|
|
236
|
+
* @param {BandwidthLimit} bandwidth In kbps
|
|
237
|
+
* @returns {Promise<boolean>} Success
|
|
238
|
+
*/
|
|
239
|
+
setTrackBandwidth(trackId: string, bandwidth: BandwidthLimit): Promise<boolean>;
|
|
240
|
+
/**
|
|
241
|
+
* Updates maximum bandwidth for the given simulcast encoding of the given track.
|
|
242
|
+
*
|
|
243
|
+
* @param {string} trackId - Id of the track
|
|
244
|
+
* @param {string} rid - Rid of the encoding
|
|
245
|
+
* @param {BandwidthLimit} bandwidth - Desired max bandwidth used by the encoding (in kbps)
|
|
246
|
+
* @returns
|
|
247
|
+
*/
|
|
248
|
+
setEncodingBandwidth(trackId: string, rid: Variant, bandwidth: BandwidthLimit): Promise<boolean>;
|
|
249
|
+
/**
|
|
250
|
+
* Removes a track from connection that was being sent to the RTC Engine.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* // setup camera
|
|
255
|
+
* let localStream: MediaStream = new MediaStream();
|
|
256
|
+
* try {
|
|
257
|
+
* localVideoStream = await navigator.mediaDevices.getUserMedia(
|
|
258
|
+
* VIDEO_CONSTRAINTS
|
|
259
|
+
* );
|
|
260
|
+
* localVideoStream
|
|
261
|
+
* .getTracks()
|
|
262
|
+
* .forEach((track) => localStream.addTrack(track));
|
|
263
|
+
* } catch (error) {
|
|
264
|
+
* console.error("Couldn't get camera permission:", error);
|
|
265
|
+
* }
|
|
266
|
+
*
|
|
267
|
+
* let trackId
|
|
268
|
+
* localStream
|
|
269
|
+
* .getTracks()
|
|
270
|
+
* .forEach((track) => trackId = webrtc.addTrack(track, localStream));
|
|
271
|
+
*
|
|
272
|
+
* // remove track
|
|
273
|
+
* webrtc.removeTrack(trackId)
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @param {string} trackId - Id of audio or video track to remove.
|
|
277
|
+
*/
|
|
278
|
+
removeTrack(trackId: string): Promise<void>;
|
|
279
|
+
/**
|
|
280
|
+
* Sets track encoding that server should send to the client library.
|
|
281
|
+
*
|
|
282
|
+
* The encoding will be sent whenever it is available. If chosen encoding is temporarily unavailable, some other
|
|
283
|
+
* encoding will be sent until chosen encoding becomes active again.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* webrtc.setTargetTrackEncoding(incomingTrackCtx.trackId, "l")
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @param {string} trackId - Id of track
|
|
291
|
+
* @param {Encoding} encoding - Encoding to receive
|
|
292
|
+
*/
|
|
293
|
+
setTargetTrackEncoding(trackId: string, encoding: Variant): void;
|
|
294
|
+
/**
|
|
295
|
+
* Enables track encoding so that it will be sent to the server.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* const trackId = webrtc.addTrack(track, stream, {}, {enabled: true, active_encodings: ["l", "m", "h"]});
|
|
300
|
+
* webrtc.disableTrackEncoding(trackId, "l");
|
|
301
|
+
* // wait some time
|
|
302
|
+
* webrtc.enableTrackEncoding(trackId, "l");
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @param {string} trackId - Id of track
|
|
306
|
+
* @param {Encoding} encoding - Encoding that will be enabled
|
|
307
|
+
*/
|
|
308
|
+
enableTrackEncoding(trackId: string, encoding: Variant): Promise<void>;
|
|
309
|
+
/**
|
|
310
|
+
* Disables track encoding so that it will be no longer sent to the server.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* const trackId = webrtc.addTrack(track, stream, {}, {enabled: true, active_encodings: ["l", "m", "h"]});
|
|
315
|
+
* webrtc.disableTrackEncoding(trackId, "l");
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @param {string} trackId - Id of track
|
|
319
|
+
* @param {Encoding} encoding - Encoding that will be disabled
|
|
320
|
+
*/
|
|
321
|
+
disableTrackEncoding(trackId: string, encoding: Variant): Promise<void>;
|
|
322
|
+
/**
|
|
323
|
+
* Updates the metadata for the current peer.
|
|
324
|
+
*
|
|
325
|
+
* @param peerMetadata - Data about this peer that other peers will receive upon joining.
|
|
326
|
+
*
|
|
327
|
+
* If the metadata is different from what is already tracked in the room, the event {@link MessageEvents.peerUpdated} will
|
|
328
|
+
* be emitted for other peers in the room.
|
|
329
|
+
*/
|
|
330
|
+
updatePeerMetadata: (peerMetadata: PeerMetadata) => void;
|
|
331
|
+
/**
|
|
332
|
+
* Updates the metadata for a specific track.
|
|
333
|
+
*
|
|
334
|
+
* @param trackId - TrackId (generated in addTrack) of audio or video track.
|
|
335
|
+
* @param trackMetadata - Data about this track that other peers will receive upon joining.
|
|
336
|
+
*
|
|
337
|
+
* If the metadata is different from what is already tracked in the room, the event {@link MessageEvents.trackUpdated} will
|
|
338
|
+
* be emitted for other peers in the room.
|
|
339
|
+
*/
|
|
340
|
+
updateTrackMetadata: (trackId: string, trackMetadata: TrackMetadata) => void;
|
|
341
|
+
isReconnecting(): boolean;
|
|
342
|
+
getDataChannelsReadiness(): boolean;
|
|
343
|
+
/**
|
|
344
|
+
* Leaves the room. This function should be called when user leaves the room in a clean way e.g. by clicking a
|
|
345
|
+
* dedicated, custom button `disconnect`. As a result there will be generated one more media event that should be sent
|
|
346
|
+
* to the RTC Engine. Thanks to it each other peer will be notified that peer left in {@link MessageEvents.peerLeft},
|
|
347
|
+
*/
|
|
348
|
+
leave: () => void;
|
|
349
|
+
private isOpen;
|
|
350
|
+
/**
|
|
351
|
+
* Create both reliable and lossy data channel publishers.
|
|
352
|
+
* This method must be called before publishData() can be used (unless negotiateOnConnect is enabled).
|
|
353
|
+
* Emits the 'dataChannelsReady' event when both channels are open and ready.
|
|
354
|
+
*
|
|
355
|
+
* @throws Error if data channels are not enabled in the constructor config
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* const client = new FishjamClient({ dataChannels: {} });
|
|
360
|
+
*
|
|
361
|
+
* client.on('dataChannelsReady', () => {
|
|
362
|
+
* console.log('Data channels ready, can now send data');
|
|
363
|
+
* client.publishData(new TextEncoder().encode('Hello'), { reliable: true });
|
|
364
|
+
* });
|
|
365
|
+
*
|
|
366
|
+
* client.createDataChannels();
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
createDataChannels(): Promise<void>;
|
|
370
|
+
/**
|
|
371
|
+
* Publish data through a data channel.
|
|
372
|
+
* The data channels must be created first by calling createDataChannels() or enabling negotiateOnConnect.
|
|
373
|
+
* Throws an error if the channel doesn't exist or isn't ready yet.
|
|
374
|
+
*
|
|
375
|
+
* @param data - The data to send as Uint8Array
|
|
376
|
+
* @param options - Options specifying which channel to use (reliable or lossy)
|
|
377
|
+
* @throws Error if the channel doesn't exist or isn't ready, or if webrtc is not initialized
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* ```typescript
|
|
381
|
+
* client.on('dataChannelsReady', () => {
|
|
382
|
+
* // Send reliable data
|
|
383
|
+
* const data = new TextEncoder().encode('Hello World');
|
|
384
|
+
* client.publishData(data, { reliable: true });
|
|
385
|
+
*
|
|
386
|
+
* // Send lossy data for low-latency updates
|
|
387
|
+
* const gameState = new Uint8Array([1, 2, 3, 4, 5]);
|
|
388
|
+
* client.publishData(gameState, { reliable: false });
|
|
389
|
+
* });
|
|
390
|
+
*
|
|
391
|
+
* client.createDataChannels();
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
publishData(data: Uint8Array, options: DataChannelOptions): void;
|
|
395
|
+
/**
|
|
396
|
+
* Subscribe to data from a specific channel type.
|
|
397
|
+
* Can be called before or after creating the data channels.
|
|
398
|
+
* If called before, the callback will be applied when the channel is created.
|
|
399
|
+
*
|
|
400
|
+
* @param callback - Function to call when data is received
|
|
401
|
+
* @param options - Options specifying which channel to subscribe to (reliable or lossy)
|
|
402
|
+
* @throws Error if webrtc is not initialized
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* // Subscribe to reliable channel
|
|
407
|
+
* client.subscribeData((data) => {
|
|
408
|
+
* const message = new TextDecoder().decode(data);
|
|
409
|
+
* console.log('Received:', message);
|
|
410
|
+
* }, { reliable: true });
|
|
411
|
+
*
|
|
412
|
+
* // Subscribe to lossy channel
|
|
413
|
+
* client.subscribeData((data) => {
|
|
414
|
+
* console.log('Received game state:', data);
|
|
415
|
+
* }, { reliable: false });
|
|
416
|
+
*
|
|
417
|
+
* // Then create publishers
|
|
418
|
+
* client.createDataChannels();
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
subscribeData(callback: DataCallback, options: DataChannelOptions): () => void;
|
|
422
|
+
/**
|
|
423
|
+
* Disconnect from the room, and close the websocket connection. Tries to leave the room gracefully, but if it fails,
|
|
424
|
+
* it will close the websocket anyway.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* const client = new FishjamClient<PeerMetadata>();
|
|
429
|
+
*
|
|
430
|
+
* client.connect({ ... });
|
|
431
|
+
*
|
|
432
|
+
* client.disconnect();
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
disconnect(): void;
|
|
436
|
+
cleanup(): void;
|
|
437
|
+
}
|
|
438
|
+
export {};
|