@dropgate/core 2.0.0-beta.1 → 2.1.0
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 +76 -15
- package/dist/index.browser.js +1 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +385 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +182 -120
- package/dist/index.d.ts +182 -120
- package/dist/index.js +383 -138
- package/dist/index.js.map +1 -1
- package/dist/p2p/index.cjs +268 -62
- package/dist/p2p/index.cjs.map +1 -1
- package/dist/p2p/index.d.cts +154 -92
- package/dist/p2p/index.d.ts +154 -92
- package/dist/p2p/index.js +267 -62
- package/dist/p2p/index.js.map +1 -1
- package/package.json +88 -88
package/dist/p2p/index.d.ts
CHANGED
|
@@ -51,6 +51,18 @@ interface ServerInfo {
|
|
|
51
51
|
/** Server capabilities. */
|
|
52
52
|
capabilities?: ServerCapabilities;
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Base progress event with common fields for all transfer operations.
|
|
56
|
+
* Provides a consistent interface for upload, download, and P2P progress tracking.
|
|
57
|
+
*/
|
|
58
|
+
interface BaseProgressEvent {
|
|
59
|
+
/** Completion percentage (0-100). */
|
|
60
|
+
percent: number;
|
|
61
|
+
/** Bytes processed so far (sent, received, or uploaded). */
|
|
62
|
+
processedBytes: number;
|
|
63
|
+
/** Total bytes expected (may be 0 if unknown). */
|
|
64
|
+
totalBytes: number;
|
|
65
|
+
}
|
|
54
66
|
/**
|
|
55
67
|
* Crypto adapter interface compatible with the Web Crypto API.
|
|
56
68
|
* Used for encryption operations and secure random generation.
|
|
@@ -78,6 +90,15 @@ interface FileSource {
|
|
|
78
90
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
79
91
|
}
|
|
80
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Finite state machine states for P2P send sessions.
|
|
95
|
+
* Prevents race conditions and ensures callbacks fire in correct order.
|
|
96
|
+
*/
|
|
97
|
+
type P2PSendState = 'initializing' | 'listening' | 'negotiating' | 'transferring' | 'finishing' | 'completed' | 'closed';
|
|
98
|
+
/**
|
|
99
|
+
* Finite state machine states for P2P receive sessions.
|
|
100
|
+
*/
|
|
101
|
+
type P2PReceiveState = 'initializing' | 'connecting' | 'negotiating' | 'transferring' | 'completed' | 'closed';
|
|
81
102
|
/**
|
|
82
103
|
* PeerJS Peer constructor interface.
|
|
83
104
|
* Consumer must provide this constructor to P2P functions.
|
|
@@ -105,16 +126,20 @@ interface PeerOptions {
|
|
|
105
126
|
/** PeerJS debug level (0-3). */
|
|
106
127
|
debug?: number;
|
|
107
128
|
}
|
|
129
|
+
/** Event handlers for PeerInstance. */
|
|
130
|
+
interface PeerInstanceEvents {
|
|
131
|
+
open: (id: string) => void;
|
|
132
|
+
connection: (conn: DataConnection) => void;
|
|
133
|
+
error: (err: Error) => void;
|
|
134
|
+
close: () => void;
|
|
135
|
+
}
|
|
108
136
|
/**
|
|
109
137
|
* PeerJS Peer instance interface.
|
|
110
138
|
* Represents a connection to the PeerJS signaling server.
|
|
111
139
|
*/
|
|
112
140
|
interface PeerInstance {
|
|
113
141
|
/** Register an event handler. */
|
|
114
|
-
on(event:
|
|
115
|
-
on(event: 'connection', callback: (conn: DataConnection) => void): void;
|
|
116
|
-
on(event: 'error', callback: (err: Error) => void): void;
|
|
117
|
-
on(event: 'close', callback: () => void): void;
|
|
142
|
+
on<K extends keyof PeerInstanceEvents>(event: K, callback: PeerInstanceEvents[K]): void;
|
|
118
143
|
on(event: string, callback: (...args: unknown[]) => void): void;
|
|
119
144
|
/** Connect to another peer by ID. */
|
|
120
145
|
connect(peerId: string, options?: {
|
|
@@ -123,16 +148,20 @@ interface PeerInstance {
|
|
|
123
148
|
/** Destroy this peer and close all connections. */
|
|
124
149
|
destroy(): void;
|
|
125
150
|
}
|
|
151
|
+
/** Event handlers for DataConnection. */
|
|
152
|
+
interface DataConnectionEvents {
|
|
153
|
+
open: () => void;
|
|
154
|
+
data: (data: unknown) => void;
|
|
155
|
+
close: () => void;
|
|
156
|
+
error: (err: Error) => void;
|
|
157
|
+
}
|
|
126
158
|
/**
|
|
127
159
|
* PeerJS DataConnection interface.
|
|
128
160
|
* Represents a WebRTC data channel connection between peers.
|
|
129
161
|
*/
|
|
130
162
|
interface DataConnection {
|
|
131
163
|
/** Register an event handler. */
|
|
132
|
-
on(event:
|
|
133
|
-
on(event: 'data', callback: (data: unknown) => void): void;
|
|
134
|
-
on(event: 'close', callback: () => void): void;
|
|
135
|
-
on(event: 'error', callback: (err: Error) => void): void;
|
|
164
|
+
on<K extends keyof DataConnectionEvents>(event: K, callback: DataConnectionEvents[K]): void;
|
|
136
165
|
on(event: string, callback: (...args: unknown[]) => void): void;
|
|
137
166
|
/** Send data to the connected peer. */
|
|
138
167
|
send(data: unknown): void;
|
|
@@ -142,58 +171,81 @@ interface DataConnection {
|
|
|
142
171
|
_dc?: RTCDataChannel;
|
|
143
172
|
}
|
|
144
173
|
/**
|
|
145
|
-
*
|
|
174
|
+
* Common server configuration for P2P connections.
|
|
146
175
|
*/
|
|
147
|
-
interface
|
|
148
|
-
/**
|
|
149
|
-
file: FileSource;
|
|
150
|
-
/** PeerJS Peer constructor - REQUIRED */
|
|
151
|
-
Peer: PeerConstructor;
|
|
152
|
-
/** Server info (optional, for capability checking) */
|
|
153
|
-
serverInfo?: ServerInfo;
|
|
154
|
-
/** PeerJS server host */
|
|
176
|
+
interface P2PServerConfig {
|
|
177
|
+
/** PeerJS server host. */
|
|
155
178
|
host?: string;
|
|
156
|
-
/** PeerJS server port */
|
|
179
|
+
/** PeerJS server port. */
|
|
157
180
|
port?: number;
|
|
158
|
-
/** PeerJS server path (default: /peerjs) */
|
|
181
|
+
/** PeerJS server path (default: /peerjs). */
|
|
159
182
|
peerjsPath?: string;
|
|
160
|
-
/** Whether to use secure connection */
|
|
183
|
+
/** Whether to use secure connection. */
|
|
161
184
|
secure?: boolean;
|
|
162
|
-
/** ICE servers for WebRTC */
|
|
185
|
+
/** ICE servers for WebRTC. */
|
|
163
186
|
iceServers?: RTCIceServer[];
|
|
164
|
-
|
|
187
|
+
}
|
|
188
|
+
/** Status event for P2P operations. */
|
|
189
|
+
interface P2PStatusEvent {
|
|
190
|
+
phase: string;
|
|
191
|
+
message: string;
|
|
192
|
+
}
|
|
193
|
+
/** Progress event for P2P send operations. */
|
|
194
|
+
interface P2PSendProgressEvent extends BaseProgressEvent {
|
|
195
|
+
}
|
|
196
|
+
/** Progress event for P2P receive operations. */
|
|
197
|
+
interface P2PReceiveProgressEvent extends BaseProgressEvent {
|
|
198
|
+
}
|
|
199
|
+
/** Metadata event when receiving a file. */
|
|
200
|
+
interface P2PMetadataEvent {
|
|
201
|
+
name: string;
|
|
202
|
+
total: number;
|
|
203
|
+
/** Call this to signal the sender to begin transfer (when autoReady is false). */
|
|
204
|
+
sendReady?: () => void;
|
|
205
|
+
}
|
|
206
|
+
/** Completion event for P2P receive operations. */
|
|
207
|
+
interface P2PReceiveCompleteEvent {
|
|
208
|
+
received: number;
|
|
209
|
+
total: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Options for starting a P2P send session.
|
|
213
|
+
*/
|
|
214
|
+
interface P2PSendOptions extends P2PServerConfig {
|
|
215
|
+
/** File to send. */
|
|
216
|
+
file: FileSource;
|
|
217
|
+
/** PeerJS Peer constructor - REQUIRED. */
|
|
218
|
+
Peer: PeerConstructor;
|
|
219
|
+
/** Server info (optional, for capability checking). */
|
|
220
|
+
serverInfo?: ServerInfo;
|
|
221
|
+
/** Custom code generator function. */
|
|
165
222
|
codeGenerator?: (cryptoObj?: CryptoAdapter) => string;
|
|
166
|
-
/** Crypto object for secure code generation */
|
|
223
|
+
/** Crypto object for secure code generation. */
|
|
167
224
|
cryptoObj?: CryptoAdapter;
|
|
168
|
-
/** Max attempts to register a peer ID */
|
|
225
|
+
/** Max attempts to register a peer ID. */
|
|
169
226
|
maxAttempts?: number;
|
|
170
|
-
/** Chunk size for data transfer */
|
|
227
|
+
/** Chunk size for data transfer. */
|
|
171
228
|
chunkSize?: number;
|
|
172
|
-
/** Timeout waiting for
|
|
173
|
-
readyTimeoutMs?: number;
|
|
174
|
-
/** Timeout waiting for end acknowledgment */
|
|
229
|
+
/** Timeout waiting for end acknowledgment. */
|
|
175
230
|
endAckTimeoutMs?: number;
|
|
176
|
-
/** Buffer high water mark for flow control */
|
|
231
|
+
/** Buffer high water mark for flow control. */
|
|
177
232
|
bufferHighWaterMark?: number;
|
|
178
|
-
/** Buffer low water mark for flow control */
|
|
233
|
+
/** Buffer low water mark for flow control. */
|
|
179
234
|
bufferLowWaterMark?: number;
|
|
180
|
-
/**
|
|
235
|
+
/** Heartbeat interval in ms for long transfers (default: 5000, 0 to disable). */
|
|
236
|
+
heartbeatIntervalMs?: number;
|
|
237
|
+
/** Callback when code is generated. */
|
|
181
238
|
onCode?: (code: string, attempt: number) => void;
|
|
182
|
-
/** Callback for status updates */
|
|
183
|
-
onStatus?: (evt:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
/** Callback for progress updates */
|
|
188
|
-
onProgress?: (evt: {
|
|
189
|
-
sent: number;
|
|
190
|
-
total: number;
|
|
191
|
-
percent: number;
|
|
192
|
-
}) => void;
|
|
193
|
-
/** Callback when transfer completes */
|
|
239
|
+
/** Callback for status updates. */
|
|
240
|
+
onStatus?: (evt: P2PStatusEvent) => void;
|
|
241
|
+
/** Callback for progress updates. */
|
|
242
|
+
onProgress?: (evt: P2PSendProgressEvent) => void;
|
|
243
|
+
/** Callback when transfer completes. */
|
|
194
244
|
onComplete?: () => void;
|
|
195
|
-
/** Callback on error */
|
|
245
|
+
/** Callback on error. */
|
|
196
246
|
onError?: (err: Error) => void;
|
|
247
|
+
/** Callback when receiver disconnects. */
|
|
248
|
+
onDisconnect?: () => void;
|
|
197
249
|
}
|
|
198
250
|
/**
|
|
199
251
|
* Return value from startP2PSend containing session control.
|
|
@@ -203,55 +255,56 @@ interface P2PSendSession {
|
|
|
203
255
|
peer: PeerInstance;
|
|
204
256
|
/** The generated sharing code. */
|
|
205
257
|
code: string;
|
|
258
|
+
/** The unique session ID for this transfer. */
|
|
259
|
+
sessionId: string;
|
|
206
260
|
/** Stop the session and clean up resources. */
|
|
207
261
|
stop: () => void;
|
|
262
|
+
/** Get the current session state. */
|
|
263
|
+
getStatus: () => P2PSendState;
|
|
264
|
+
/** Get the number of bytes sent so far. */
|
|
265
|
+
getBytesSent: () => number;
|
|
266
|
+
/** Get the connected receiver's peer ID (if connected). */
|
|
267
|
+
getConnectedPeerId: () => string | null;
|
|
208
268
|
}
|
|
209
269
|
/**
|
|
210
270
|
* Options for starting a P2P receive session.
|
|
211
271
|
*/
|
|
212
|
-
interface P2PReceiveOptions {
|
|
213
|
-
/** Sharing code to connect to */
|
|
272
|
+
interface P2PReceiveOptions extends P2PServerConfig {
|
|
273
|
+
/** Sharing code to connect to. */
|
|
214
274
|
code: string;
|
|
215
|
-
/** PeerJS Peer constructor - REQUIRED */
|
|
275
|
+
/** PeerJS Peer constructor - REQUIRED. */
|
|
216
276
|
Peer: PeerConstructor;
|
|
217
|
-
/** Server info (optional, for capability checking) */
|
|
277
|
+
/** Server info (optional, for capability checking). */
|
|
218
278
|
serverInfo?: ServerInfo;
|
|
219
|
-
/**
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
/** Callback when data chunk is received - consumer handles file writing */
|
|
279
|
+
/**
|
|
280
|
+
* Whether to automatically send the "ready" signal after receiving metadata.
|
|
281
|
+
* Default: true.
|
|
282
|
+
* Set to false to show a preview and manually control when the transfer starts.
|
|
283
|
+
* When false, call the sendReady function passed to onMeta to start the transfer.
|
|
284
|
+
*/
|
|
285
|
+
autoReady?: boolean;
|
|
286
|
+
/**
|
|
287
|
+
* Timeout in ms for detecting dead connections (no data received).
|
|
288
|
+
* Default: 15000 (15 seconds). Set to 0 to disable.
|
|
289
|
+
*/
|
|
290
|
+
watchdogTimeoutMs?: number;
|
|
291
|
+
/** Callback for status updates. */
|
|
292
|
+
onStatus?: (evt: P2PStatusEvent) => void;
|
|
293
|
+
/**
|
|
294
|
+
* Callback when file metadata is received.
|
|
295
|
+
* When autoReady is false, this callback receives a sendReady function
|
|
296
|
+
* that must be called to signal the sender to begin the transfer.
|
|
297
|
+
*/
|
|
298
|
+
onMeta?: (evt: P2PMetadataEvent) => void;
|
|
299
|
+
/** Callback when data chunk is received - consumer handles file writing. */
|
|
240
300
|
onData?: (chunk: Uint8Array) => Promise<void> | void;
|
|
241
|
-
/** Callback for progress updates */
|
|
242
|
-
onProgress?: (evt:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}) => void;
|
|
247
|
-
/** Callback when transfer completes */
|
|
248
|
-
onComplete?: (evt: {
|
|
249
|
-
received: number;
|
|
250
|
-
total: number;
|
|
251
|
-
}) => void;
|
|
252
|
-
/** Callback on error */
|
|
301
|
+
/** Callback for progress updates. */
|
|
302
|
+
onProgress?: (evt: P2PReceiveProgressEvent) => void;
|
|
303
|
+
/** Callback when transfer completes. */
|
|
304
|
+
onComplete?: (evt: P2PReceiveCompleteEvent) => void;
|
|
305
|
+
/** Callback on error. */
|
|
253
306
|
onError?: (err: Error) => void;
|
|
254
|
-
/** Callback when sender disconnects */
|
|
307
|
+
/** Callback when sender disconnects. */
|
|
255
308
|
onDisconnect?: () => void;
|
|
256
309
|
}
|
|
257
310
|
/**
|
|
@@ -262,6 +315,14 @@ interface P2PReceiveSession {
|
|
|
262
315
|
peer: PeerInstance;
|
|
263
316
|
/** Stop the session and clean up resources. */
|
|
264
317
|
stop: () => void;
|
|
318
|
+
/** Get the current session state. */
|
|
319
|
+
getStatus: () => P2PReceiveState;
|
|
320
|
+
/** Get the number of bytes received so far. */
|
|
321
|
+
getBytesReceived: () => number;
|
|
322
|
+
/** Get the expected total bytes (0 if metadata not received). */
|
|
323
|
+
getTotalBytes: () => number;
|
|
324
|
+
/** Get the current session ID (if received from sender). */
|
|
325
|
+
getSessionId: () => string | null;
|
|
265
326
|
}
|
|
266
327
|
|
|
267
328
|
/**
|
|
@@ -340,17 +401,18 @@ declare function generateP2PCode(cryptoObj?: CryptoAdapter): string;
|
|
|
340
401
|
*/
|
|
341
402
|
declare function isP2PCodeLike(code: string): boolean;
|
|
342
403
|
|
|
343
|
-
interface BuildPeerOptionsInput {
|
|
344
|
-
host?: string;
|
|
345
|
-
port?: number;
|
|
346
|
-
peerjsPath?: string;
|
|
347
|
-
secure?: boolean;
|
|
348
|
-
iceServers?: RTCIceServer[];
|
|
349
|
-
}
|
|
350
404
|
/**
|
|
351
|
-
*
|
|
405
|
+
* Resolve P2P server configuration from user options and server capabilities.
|
|
406
|
+
* User-provided values take precedence over server capabilities.
|
|
407
|
+
*/
|
|
408
|
+
declare function resolvePeerConfig(userConfig: P2PServerConfig, serverCaps?: P2PCapabilities): {
|
|
409
|
+
path: string;
|
|
410
|
+
iceServers: RTCIceServer[];
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Build PeerJS connection options from P2P server configuration.
|
|
352
414
|
*/
|
|
353
|
-
declare function buildPeerOptions(
|
|
415
|
+
declare function buildPeerOptions(config?: P2PServerConfig): PeerOptions;
|
|
354
416
|
interface CreatePeerWithRetriesOptions {
|
|
355
417
|
code?: string | null;
|
|
356
418
|
codeGenerator: () => string;
|
|
@@ -366,4 +428,4 @@ declare function createPeerWithRetries(opts: CreatePeerWithRetriesOptions): Prom
|
|
|
366
428
|
code: string;
|
|
367
429
|
}>;
|
|
368
430
|
|
|
369
|
-
export { type DataConnection, type P2PReceiveOptions, type P2PReceiveSession, type P2PSendOptions, type P2PSendSession, type PeerConstructor, type PeerInstance, type PeerOptions, buildPeerOptions, createPeerWithRetries, generateP2PCode, isLocalhostHostname, isP2PCodeLike, isSecureContextForP2P, startP2PReceive, startP2PSend };
|
|
431
|
+
export { type DataConnection, type DataConnectionEvents, type P2PMetadataEvent, type P2PReceiveCompleteEvent, type P2PReceiveOptions, type P2PReceiveProgressEvent, type P2PReceiveSession, type P2PReceiveState, type P2PSendOptions, type P2PSendProgressEvent, type P2PSendSession, type P2PSendState, type P2PServerConfig, type P2PStatusEvent, type PeerConstructor, type PeerInstance, type PeerInstanceEvents, type PeerOptions, buildPeerOptions, createPeerWithRetries, generateP2PCode, isLocalhostHostname, isP2PCodeLike, isSecureContextForP2P, resolvePeerConfig, startP2PReceive, startP2PSend };
|