@dropgate/core 2.0.0-beta.2 → 2.2.0-beta.1
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 +639 -303
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +208 -121
- package/dist/index.d.ts +208 -121
- package/dist/index.js +637 -303
- package/dist/index.js.map +1 -1
- package/dist/p2p/index.cjs +310 -65
- package/dist/p2p/index.cjs.map +1 -1
- package/dist/p2p/index.d.cts +165 -92
- package/dist/p2p/index.d.ts +165 -92
- package/dist/p2p/index.js +309 -65
- package/dist/p2p/index.js.map +1 -1
- package/package.json +88 -88
package/dist/index.d.ts
CHANGED
|
@@ -114,16 +114,26 @@ interface ServerInfo {
|
|
|
114
114
|
/** Server capabilities. */
|
|
115
115
|
capabilities?: ServerCapabilities;
|
|
116
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Base progress event with common fields for all transfer operations.
|
|
119
|
+
* Provides a consistent interface for upload, download, and P2P progress tracking.
|
|
120
|
+
*/
|
|
121
|
+
interface BaseProgressEvent {
|
|
122
|
+
/** Completion percentage (0-100). */
|
|
123
|
+
percent: number;
|
|
124
|
+
/** Bytes processed so far (sent, received, or uploaded). */
|
|
125
|
+
processedBytes: number;
|
|
126
|
+
/** Total bytes expected (may be 0 if unknown). */
|
|
127
|
+
totalBytes: number;
|
|
128
|
+
}
|
|
117
129
|
/**
|
|
118
130
|
* Progress event emitted during upload operations.
|
|
119
131
|
*/
|
|
120
|
-
interface
|
|
121
|
-
/** Current phase of the operation
|
|
122
|
-
phase:
|
|
132
|
+
interface UploadProgressEvent extends BaseProgressEvent {
|
|
133
|
+
/** Current phase of the operation. */
|
|
134
|
+
phase: 'server-info' | 'server-compat' | 'crypto' | 'init' | 'chunk' | 'complete' | 'done' | 'retry-wait' | 'retry';
|
|
123
135
|
/** Human-readable status text. */
|
|
124
136
|
text?: string;
|
|
125
|
-
/** Completion percentage (0-100). */
|
|
126
|
-
percent?: number;
|
|
127
137
|
/** Current chunk index (0-based). */
|
|
128
138
|
chunkIndex?: number;
|
|
129
139
|
/** Total number of chunks. */
|
|
@@ -144,6 +154,18 @@ interface UploadResult {
|
|
|
144
154
|
/** Base64-encoded encryption key (only present if encrypted). */
|
|
145
155
|
keyB64?: string;
|
|
146
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Upload session with cancellation support.
|
|
159
|
+
* Returned by uploadFile() to allow cancelling uploads in progress.
|
|
160
|
+
*/
|
|
161
|
+
interface UploadSession {
|
|
162
|
+
/** Promise that resolves with upload result when complete. */
|
|
163
|
+
result: Promise<UploadResult>;
|
|
164
|
+
/** Cancel the upload. */
|
|
165
|
+
cancel: (reason?: string) => void;
|
|
166
|
+
/** Get current upload status. */
|
|
167
|
+
getStatus: () => 'initializing' | 'uploading' | 'completing' | 'completed' | 'cancelled' | 'error';
|
|
168
|
+
}
|
|
147
169
|
/**
|
|
148
170
|
* Result of a client/server compatibility check.
|
|
149
171
|
*/
|
|
@@ -261,7 +283,9 @@ interface UploadOptions extends ServerTarget {
|
|
|
261
283
|
/** Override the filename sent to the server. */
|
|
262
284
|
filenameOverride?: string;
|
|
263
285
|
/** Callback for progress updates. */
|
|
264
|
-
onProgress?: (evt:
|
|
286
|
+
onProgress?: (evt: UploadProgressEvent) => void;
|
|
287
|
+
/** Callback when upload is cancelled by user. */
|
|
288
|
+
onCancel?: () => void;
|
|
265
289
|
/** AbortSignal to cancel the upload. */
|
|
266
290
|
signal?: AbortSignal;
|
|
267
291
|
/** Timeout settings for various upload phases. */
|
|
@@ -293,6 +317,8 @@ interface GetServerInfoOptions extends ServerTarget {
|
|
|
293
317
|
timeoutMs?: number;
|
|
294
318
|
/** AbortSignal to cancel the request. */
|
|
295
319
|
signal?: AbortSignal;
|
|
320
|
+
/** Custom fetch implementation (uses global fetch by default). */
|
|
321
|
+
fetchFn?: FetchFn;
|
|
296
322
|
}
|
|
297
323
|
/**
|
|
298
324
|
* Options for validating upload inputs before starting an upload.
|
|
@@ -323,17 +349,11 @@ interface FileMetadata {
|
|
|
323
349
|
/**
|
|
324
350
|
* Download progress event.
|
|
325
351
|
*/
|
|
326
|
-
interface DownloadProgressEvent {
|
|
352
|
+
interface DownloadProgressEvent extends BaseProgressEvent {
|
|
327
353
|
/** Current phase of the download. */
|
|
328
|
-
phase: 'metadata' | 'downloading' | 'decrypting' | 'complete';
|
|
354
|
+
phase: 'server-info' | 'server-compat' | 'metadata' | 'downloading' | 'decrypting' | 'complete';
|
|
329
355
|
/** Human-readable status text. */
|
|
330
356
|
text?: string;
|
|
331
|
-
/** Bytes received so far. */
|
|
332
|
-
receivedBytes: number;
|
|
333
|
-
/** Total bytes expected (may be 0 if unknown). */
|
|
334
|
-
totalBytes: number;
|
|
335
|
-
/** Completion percentage (0-100). */
|
|
336
|
-
percent: number;
|
|
337
357
|
}
|
|
338
358
|
/**
|
|
339
359
|
* Options for downloading a file.
|
|
@@ -491,6 +511,17 @@ declare function encryptFilenameToBase64(cryptoObj: CryptoAdapter, filename: str
|
|
|
491
511
|
* Estimate total upload size including encryption overhead.
|
|
492
512
|
*/
|
|
493
513
|
declare function estimateTotalUploadSizeBytes(fileSizeBytes: number, totalChunks: number, isEncrypted: boolean): number;
|
|
514
|
+
/**
|
|
515
|
+
* Fetch server information from the /api/info endpoint.
|
|
516
|
+
* @param opts - Server target and request options.
|
|
517
|
+
* @returns The server base URL and server info object.
|
|
518
|
+
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
519
|
+
* @throws {DropgateProtocolError} If the server returns an invalid response.
|
|
520
|
+
*/
|
|
521
|
+
declare function getServerInfo(opts: GetServerInfoOptions): Promise<{
|
|
522
|
+
baseUrl: string;
|
|
523
|
+
serverInfo: ServerInfo;
|
|
524
|
+
}>;
|
|
494
525
|
/**
|
|
495
526
|
* Headless, environment-agnostic client for Dropgate file uploads.
|
|
496
527
|
* Handles server communication, encryption, and chunked uploads.
|
|
@@ -514,17 +545,6 @@ declare class DropgateClient {
|
|
|
514
545
|
* @throws {DropgateValidationError} If clientVersion is missing or invalid.
|
|
515
546
|
*/
|
|
516
547
|
constructor(opts: DropgateClientOptions);
|
|
517
|
-
/**
|
|
518
|
-
* Fetch server information from the /api/info endpoint.
|
|
519
|
-
* @param opts - Server target and request options.
|
|
520
|
-
* @returns The server base URL and server info object.
|
|
521
|
-
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
522
|
-
* @throws {DropgateProtocolError} If the server returns an invalid response.
|
|
523
|
-
*/
|
|
524
|
-
getServerInfo(opts: GetServerInfoOptions): Promise<{
|
|
525
|
-
baseUrl: string;
|
|
526
|
-
serverInfo: ServerInfo;
|
|
527
|
-
}>;
|
|
528
548
|
/**
|
|
529
549
|
* Resolve a user-entered sharing code or URL via the server.
|
|
530
550
|
* @param value - The sharing code or URL to resolve.
|
|
@@ -535,10 +555,16 @@ declare class DropgateClient {
|
|
|
535
555
|
resolveShareTarget(value: string, opts: GetServerInfoOptions): Promise<ShareTargetResult>;
|
|
536
556
|
/**
|
|
537
557
|
* Check version compatibility between this client and a server.
|
|
538
|
-
*
|
|
539
|
-
* @
|
|
558
|
+
* Fetches server info internally using getServerInfo.
|
|
559
|
+
* @param opts - Server target and request options.
|
|
560
|
+
* @returns Compatibility result with status, message, and server info.
|
|
561
|
+
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
562
|
+
* @throws {DropgateProtocolError} If the server returns an invalid response.
|
|
540
563
|
*/
|
|
541
|
-
checkCompatibility(
|
|
564
|
+
checkCompatibility(opts: GetServerInfoOptions): Promise<CompatibilityResult & {
|
|
565
|
+
serverInfo: ServerInfo;
|
|
566
|
+
baseUrl: string;
|
|
567
|
+
}>;
|
|
542
568
|
/**
|
|
543
569
|
* Validate file and upload settings against server capabilities.
|
|
544
570
|
* @param opts - Validation options containing file, settings, and server info.
|
|
@@ -555,7 +581,7 @@ declare class DropgateClient {
|
|
|
555
581
|
* @throws {DropgateProtocolError} If the server returns an error.
|
|
556
582
|
* @throws {DropgateAbortError} If the upload is cancelled.
|
|
557
583
|
*/
|
|
558
|
-
uploadFile(opts: UploadOptions): Promise<
|
|
584
|
+
uploadFile(opts: UploadOptions): Promise<UploadSession>;
|
|
559
585
|
/**
|
|
560
586
|
* Download a file from the server with optional decryption.
|
|
561
587
|
*
|
|
@@ -592,6 +618,15 @@ declare function getDefaultCrypto(): CryptoAdapter | undefined;
|
|
|
592
618
|
*/
|
|
593
619
|
declare function getDefaultFetch(): FetchFn | undefined;
|
|
594
620
|
|
|
621
|
+
/**
|
|
622
|
+
* Finite state machine states for P2P send sessions.
|
|
623
|
+
* Prevents race conditions and ensures callbacks fire in correct order.
|
|
624
|
+
*/
|
|
625
|
+
type P2PSendState = 'initializing' | 'listening' | 'negotiating' | 'transferring' | 'finishing' | 'completed' | 'cancelled' | 'closed';
|
|
626
|
+
/**
|
|
627
|
+
* Finite state machine states for P2P receive sessions.
|
|
628
|
+
*/
|
|
629
|
+
type P2PReceiveState = 'initializing' | 'connecting' | 'negotiating' | 'transferring' | 'completed' | 'cancelled' | 'closed';
|
|
595
630
|
/**
|
|
596
631
|
* PeerJS Peer constructor interface.
|
|
597
632
|
* Consumer must provide this constructor to P2P functions.
|
|
@@ -619,16 +654,20 @@ interface PeerOptions {
|
|
|
619
654
|
/** PeerJS debug level (0-3). */
|
|
620
655
|
debug?: number;
|
|
621
656
|
}
|
|
657
|
+
/** Event handlers for PeerInstance. */
|
|
658
|
+
interface PeerInstanceEvents {
|
|
659
|
+
open: (id: string) => void;
|
|
660
|
+
connection: (conn: DataConnection) => void;
|
|
661
|
+
error: (err: Error) => void;
|
|
662
|
+
close: () => void;
|
|
663
|
+
}
|
|
622
664
|
/**
|
|
623
665
|
* PeerJS Peer instance interface.
|
|
624
666
|
* Represents a connection to the PeerJS signaling server.
|
|
625
667
|
*/
|
|
626
668
|
interface PeerInstance {
|
|
627
669
|
/** Register an event handler. */
|
|
628
|
-
on(event:
|
|
629
|
-
on(event: 'connection', callback: (conn: DataConnection) => void): void;
|
|
630
|
-
on(event: 'error', callback: (err: Error) => void): void;
|
|
631
|
-
on(event: 'close', callback: () => void): void;
|
|
670
|
+
on<K extends keyof PeerInstanceEvents>(event: K, callback: PeerInstanceEvents[K]): void;
|
|
632
671
|
on(event: string, callback: (...args: unknown[]) => void): void;
|
|
633
672
|
/** Connect to another peer by ID. */
|
|
634
673
|
connect(peerId: string, options?: {
|
|
@@ -637,16 +676,20 @@ interface PeerInstance {
|
|
|
637
676
|
/** Destroy this peer and close all connections. */
|
|
638
677
|
destroy(): void;
|
|
639
678
|
}
|
|
679
|
+
/** Event handlers for DataConnection. */
|
|
680
|
+
interface DataConnectionEvents {
|
|
681
|
+
open: () => void;
|
|
682
|
+
data: (data: unknown) => void;
|
|
683
|
+
close: () => void;
|
|
684
|
+
error: (err: Error) => void;
|
|
685
|
+
}
|
|
640
686
|
/**
|
|
641
687
|
* PeerJS DataConnection interface.
|
|
642
688
|
* Represents a WebRTC data channel connection between peers.
|
|
643
689
|
*/
|
|
644
690
|
interface DataConnection {
|
|
645
691
|
/** Register an event handler. */
|
|
646
|
-
on(event:
|
|
647
|
-
on(event: 'data', callback: (data: unknown) => void): void;
|
|
648
|
-
on(event: 'close', callback: () => void): void;
|
|
649
|
-
on(event: 'error', callback: (err: Error) => void): void;
|
|
692
|
+
on<K extends keyof DataConnectionEvents>(event: K, callback: DataConnectionEvents[K]): void;
|
|
650
693
|
on(event: string, callback: (...args: unknown[]) => void): void;
|
|
651
694
|
/** Send data to the connected peer. */
|
|
652
695
|
send(data: unknown): void;
|
|
@@ -656,58 +699,90 @@ interface DataConnection {
|
|
|
656
699
|
_dc?: RTCDataChannel;
|
|
657
700
|
}
|
|
658
701
|
/**
|
|
659
|
-
*
|
|
702
|
+
* Common server configuration for P2P connections.
|
|
660
703
|
*/
|
|
661
|
-
interface
|
|
662
|
-
/**
|
|
663
|
-
file: FileSource;
|
|
664
|
-
/** PeerJS Peer constructor - REQUIRED */
|
|
665
|
-
Peer: PeerConstructor;
|
|
666
|
-
/** Server info (optional, for capability checking) */
|
|
667
|
-
serverInfo?: ServerInfo;
|
|
668
|
-
/** PeerJS server host */
|
|
704
|
+
interface P2PServerConfig {
|
|
705
|
+
/** PeerJS server host. */
|
|
669
706
|
host?: string;
|
|
670
|
-
/** PeerJS server port */
|
|
707
|
+
/** PeerJS server port. */
|
|
671
708
|
port?: number;
|
|
672
|
-
/** PeerJS server path (default: /peerjs) */
|
|
709
|
+
/** PeerJS server path (default: /peerjs). */
|
|
673
710
|
peerjsPath?: string;
|
|
674
|
-
/** Whether to use secure connection */
|
|
711
|
+
/** Whether to use secure connection. */
|
|
675
712
|
secure?: boolean;
|
|
676
|
-
/** ICE servers for WebRTC */
|
|
713
|
+
/** ICE servers for WebRTC. */
|
|
677
714
|
iceServers?: RTCIceServer[];
|
|
678
|
-
|
|
715
|
+
}
|
|
716
|
+
/** Status event for P2P operations. */
|
|
717
|
+
interface P2PStatusEvent {
|
|
718
|
+
phase: string;
|
|
719
|
+
message: string;
|
|
720
|
+
}
|
|
721
|
+
/** Progress event for P2P send operations. */
|
|
722
|
+
interface P2PSendProgressEvent extends BaseProgressEvent {
|
|
723
|
+
}
|
|
724
|
+
/** Progress event for P2P receive operations. */
|
|
725
|
+
interface P2PReceiveProgressEvent extends BaseProgressEvent {
|
|
726
|
+
}
|
|
727
|
+
/** Metadata event when receiving a file. */
|
|
728
|
+
interface P2PMetadataEvent {
|
|
729
|
+
name: string;
|
|
730
|
+
total: number;
|
|
731
|
+
/** Call this to signal the sender to begin transfer (when autoReady is false). */
|
|
732
|
+
sendReady?: () => void;
|
|
733
|
+
}
|
|
734
|
+
/** Completion event for P2P receive operations. */
|
|
735
|
+
interface P2PReceiveCompleteEvent {
|
|
736
|
+
received: number;
|
|
737
|
+
total: number;
|
|
738
|
+
}
|
|
739
|
+
/** Cancellation event for P2P operations. */
|
|
740
|
+
interface P2PCancellationEvent {
|
|
741
|
+
/** Who cancelled the transfer ('sender' or 'receiver'). */
|
|
742
|
+
cancelledBy: 'sender' | 'receiver';
|
|
743
|
+
/** Optional cancellation message. */
|
|
744
|
+
message?: string;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Options for starting a P2P send session.
|
|
748
|
+
*/
|
|
749
|
+
interface P2PSendOptions extends P2PServerConfig {
|
|
750
|
+
/** File to send. */
|
|
751
|
+
file: FileSource;
|
|
752
|
+
/** PeerJS Peer constructor - REQUIRED. */
|
|
753
|
+
Peer: PeerConstructor;
|
|
754
|
+
/** Server info (optional, for capability checking). */
|
|
755
|
+
serverInfo?: ServerInfo;
|
|
756
|
+
/** Custom code generator function. */
|
|
679
757
|
codeGenerator?: (cryptoObj?: CryptoAdapter) => string;
|
|
680
|
-
/** Crypto object for secure code generation */
|
|
758
|
+
/** Crypto object for secure code generation. */
|
|
681
759
|
cryptoObj?: CryptoAdapter;
|
|
682
|
-
/** Max attempts to register a peer ID */
|
|
760
|
+
/** Max attempts to register a peer ID. */
|
|
683
761
|
maxAttempts?: number;
|
|
684
|
-
/** Chunk size for data transfer */
|
|
762
|
+
/** Chunk size for data transfer. */
|
|
685
763
|
chunkSize?: number;
|
|
686
|
-
/** Timeout waiting for
|
|
687
|
-
readyTimeoutMs?: number;
|
|
688
|
-
/** Timeout waiting for end acknowledgment */
|
|
764
|
+
/** Timeout waiting for end acknowledgment. */
|
|
689
765
|
endAckTimeoutMs?: number;
|
|
690
|
-
/** Buffer high water mark for flow control */
|
|
766
|
+
/** Buffer high water mark for flow control. */
|
|
691
767
|
bufferHighWaterMark?: number;
|
|
692
|
-
/** Buffer low water mark for flow control */
|
|
768
|
+
/** Buffer low water mark for flow control. */
|
|
693
769
|
bufferLowWaterMark?: number;
|
|
694
|
-
/**
|
|
770
|
+
/** Heartbeat interval in ms for long transfers (default: 5000, 0 to disable). */
|
|
771
|
+
heartbeatIntervalMs?: number;
|
|
772
|
+
/** Callback when code is generated. */
|
|
695
773
|
onCode?: (code: string, attempt: number) => void;
|
|
696
|
-
/** Callback for status updates */
|
|
697
|
-
onStatus?: (evt:
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
/** Callback for progress updates */
|
|
702
|
-
onProgress?: (evt: {
|
|
703
|
-
sent: number;
|
|
704
|
-
total: number;
|
|
705
|
-
percent: number;
|
|
706
|
-
}) => void;
|
|
707
|
-
/** Callback when transfer completes */
|
|
774
|
+
/** Callback for status updates. */
|
|
775
|
+
onStatus?: (evt: P2PStatusEvent) => void;
|
|
776
|
+
/** Callback for progress updates. */
|
|
777
|
+
onProgress?: (evt: P2PSendProgressEvent) => void;
|
|
778
|
+
/** Callback when transfer completes. */
|
|
708
779
|
onComplete?: () => void;
|
|
709
|
-
/** Callback on error */
|
|
780
|
+
/** Callback on error. */
|
|
710
781
|
onError?: (err: Error) => void;
|
|
782
|
+
/** Callback when receiver disconnects. */
|
|
783
|
+
onDisconnect?: () => void;
|
|
784
|
+
/** Callback when transfer is cancelled by either party. */
|
|
785
|
+
onCancel?: (evt: P2PCancellationEvent) => void;
|
|
711
786
|
}
|
|
712
787
|
/**
|
|
713
788
|
* Return value from startP2PSend containing session control.
|
|
@@ -717,56 +792,59 @@ interface P2PSendSession {
|
|
|
717
792
|
peer: PeerInstance;
|
|
718
793
|
/** The generated sharing code. */
|
|
719
794
|
code: string;
|
|
795
|
+
/** The unique session ID for this transfer. */
|
|
796
|
+
sessionId: string;
|
|
720
797
|
/** Stop the session and clean up resources. */
|
|
721
798
|
stop: () => void;
|
|
799
|
+
/** Get the current session state. */
|
|
800
|
+
getStatus: () => P2PSendState;
|
|
801
|
+
/** Get the number of bytes sent so far. */
|
|
802
|
+
getBytesSent: () => number;
|
|
803
|
+
/** Get the connected receiver's peer ID (if connected). */
|
|
804
|
+
getConnectedPeerId: () => string | null;
|
|
722
805
|
}
|
|
723
806
|
/**
|
|
724
807
|
* Options for starting a P2P receive session.
|
|
725
808
|
*/
|
|
726
|
-
interface P2PReceiveOptions {
|
|
727
|
-
/** Sharing code to connect to */
|
|
809
|
+
interface P2PReceiveOptions extends P2PServerConfig {
|
|
810
|
+
/** Sharing code to connect to. */
|
|
728
811
|
code: string;
|
|
729
|
-
/** PeerJS Peer constructor - REQUIRED */
|
|
812
|
+
/** PeerJS Peer constructor - REQUIRED. */
|
|
730
813
|
Peer: PeerConstructor;
|
|
731
|
-
/** Server info (optional, for capability checking) */
|
|
814
|
+
/** Server info (optional, for capability checking). */
|
|
732
815
|
serverInfo?: ServerInfo;
|
|
733
|
-
/**
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
/** Callback when data chunk is received - consumer handles file writing */
|
|
816
|
+
/**
|
|
817
|
+
* Whether to automatically send the "ready" signal after receiving metadata.
|
|
818
|
+
* Default: true.
|
|
819
|
+
* Set to false to show a preview and manually control when the transfer starts.
|
|
820
|
+
* When false, call the sendReady function passed to onMeta to start the transfer.
|
|
821
|
+
*/
|
|
822
|
+
autoReady?: boolean;
|
|
823
|
+
/**
|
|
824
|
+
* Timeout in ms for detecting dead connections (no data received).
|
|
825
|
+
* Default: 15000 (15 seconds). Set to 0 to disable.
|
|
826
|
+
*/
|
|
827
|
+
watchdogTimeoutMs?: number;
|
|
828
|
+
/** Callback for status updates. */
|
|
829
|
+
onStatus?: (evt: P2PStatusEvent) => void;
|
|
830
|
+
/**
|
|
831
|
+
* Callback when file metadata is received.
|
|
832
|
+
* When autoReady is false, this callback receives a sendReady function
|
|
833
|
+
* that must be called to signal the sender to begin the transfer.
|
|
834
|
+
*/
|
|
835
|
+
onMeta?: (evt: P2PMetadataEvent) => void;
|
|
836
|
+
/** Callback when data chunk is received - consumer handles file writing. */
|
|
754
837
|
onData?: (chunk: Uint8Array) => Promise<void> | void;
|
|
755
|
-
/** Callback for progress updates */
|
|
756
|
-
onProgress?: (evt:
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}) => void;
|
|
761
|
-
/** Callback when transfer completes */
|
|
762
|
-
onComplete?: (evt: {
|
|
763
|
-
received: number;
|
|
764
|
-
total: number;
|
|
765
|
-
}) => void;
|
|
766
|
-
/** Callback on error */
|
|
838
|
+
/** Callback for progress updates. */
|
|
839
|
+
onProgress?: (evt: P2PReceiveProgressEvent) => void;
|
|
840
|
+
/** Callback when transfer completes. */
|
|
841
|
+
onComplete?: (evt: P2PReceiveCompleteEvent) => void;
|
|
842
|
+
/** Callback on error. */
|
|
767
843
|
onError?: (err: Error) => void;
|
|
768
|
-
/** Callback when sender disconnects */
|
|
844
|
+
/** Callback when sender disconnects. */
|
|
769
845
|
onDisconnect?: () => void;
|
|
846
|
+
/** Callback when transfer is cancelled by either party. */
|
|
847
|
+
onCancel?: (evt: P2PCancellationEvent) => void;
|
|
770
848
|
}
|
|
771
849
|
/**
|
|
772
850
|
* Return value from startP2PReceive containing session control.
|
|
@@ -776,6 +854,14 @@ interface P2PReceiveSession {
|
|
|
776
854
|
peer: PeerInstance;
|
|
777
855
|
/** Stop the session and clean up resources. */
|
|
778
856
|
stop: () => void;
|
|
857
|
+
/** Get the current session state. */
|
|
858
|
+
getStatus: () => P2PReceiveState;
|
|
859
|
+
/** Get the number of bytes received so far. */
|
|
860
|
+
getBytesReceived: () => number;
|
|
861
|
+
/** Get the expected total bytes (0 if metadata not received). */
|
|
862
|
+
getTotalBytes: () => number;
|
|
863
|
+
/** Get the current session ID (if received from sender). */
|
|
864
|
+
getSessionId: () => string | null;
|
|
779
865
|
}
|
|
780
866
|
|
|
781
867
|
/**
|
|
@@ -854,17 +940,18 @@ declare function generateP2PCode(cryptoObj?: CryptoAdapter): string;
|
|
|
854
940
|
*/
|
|
855
941
|
declare function isP2PCodeLike(code: string): boolean;
|
|
856
942
|
|
|
857
|
-
interface BuildPeerOptionsInput {
|
|
858
|
-
host?: string;
|
|
859
|
-
port?: number;
|
|
860
|
-
peerjsPath?: string;
|
|
861
|
-
secure?: boolean;
|
|
862
|
-
iceServers?: RTCIceServer[];
|
|
863
|
-
}
|
|
864
943
|
/**
|
|
865
|
-
*
|
|
944
|
+
* Resolve P2P server configuration from user options and server capabilities.
|
|
945
|
+
* User-provided values take precedence over server capabilities.
|
|
946
|
+
*/
|
|
947
|
+
declare function resolvePeerConfig(userConfig: P2PServerConfig, serverCaps?: P2PCapabilities): {
|
|
948
|
+
path: string;
|
|
949
|
+
iceServers: RTCIceServer[];
|
|
950
|
+
};
|
|
951
|
+
/**
|
|
952
|
+
* Build PeerJS connection options from P2P server configuration.
|
|
866
953
|
*/
|
|
867
|
-
declare function buildPeerOptions(
|
|
954
|
+
declare function buildPeerOptions(config?: P2PServerConfig): PeerOptions;
|
|
868
955
|
interface CreatePeerWithRetriesOptions {
|
|
869
956
|
code?: string | null;
|
|
870
957
|
codeGenerator: () => string;
|
|
@@ -880,4 +967,4 @@ declare function createPeerWithRetries(opts: CreatePeerWithRetriesOptions): Prom
|
|
|
880
967
|
code: string;
|
|
881
968
|
}>;
|
|
882
969
|
|
|
883
|
-
export { AES_GCM_IV_BYTES, AES_GCM_TAG_BYTES, type AbortSignalWithCleanup, type Base64Adapter, type CompatibilityResult, type CryptoAdapter, DEFAULT_CHUNK_SIZE, type DataConnection, type DownloadOptions, type DownloadProgressEvent, type DownloadResult, DropgateAbortError, DropgateClient, type DropgateClientOptions, DropgateError, type DropgateErrorOptions, DropgateNetworkError, DropgateProtocolError, DropgateTimeoutError, DropgateValidationError, ENCRYPTION_OVERHEAD_PER_CHUNK, type FetchFn, type FetchJsonOptions, type FetchJsonResult, type FileMetadata, type FileSource, type GetServerInfoOptions, type LoggerFn, type P2PCapabilities, type P2PReceiveOptions, type P2PReceiveSession, type P2PSendOptions, type P2PSendSession, type PeerConstructor, type PeerInstance, type
|
|
970
|
+
export { AES_GCM_IV_BYTES, AES_GCM_TAG_BYTES, type AbortSignalWithCleanup, type Base64Adapter, type BaseProgressEvent, type CompatibilityResult, type CryptoAdapter, DEFAULT_CHUNK_SIZE, type DataConnection, type DataConnectionEvents, type DownloadOptions, type DownloadProgressEvent, type DownloadResult, DropgateAbortError, DropgateClient, type DropgateClientOptions, DropgateError, type DropgateErrorOptions, DropgateNetworkError, DropgateProtocolError, DropgateTimeoutError, DropgateValidationError, ENCRYPTION_OVERHEAD_PER_CHUNK, type FetchFn, type FetchJsonOptions, type FetchJsonResult, type FileMetadata, type FileSource, type GetServerInfoOptions, type LoggerFn, type P2PCapabilities, type P2PMetadataEvent, type P2PReceiveCompleteEvent, type P2PReceiveOptions, type P2PReceiveProgressEvent, type P2PReceiveSession, type P2PSendOptions, type P2PSendProgressEvent, type P2PSendSession, type P2PServerConfig, type P2PStatusEvent, type PeerConstructor, type PeerInstance, type PeerInstanceEvents, type PeerOptions, type SemverParts, type ServerCapabilities, type ServerInfo, type ServerTarget, type ShareTargetResult, type UploadCapabilities, type UploadOptions, type UploadProgressEvent, type UploadResult, type ValidateUploadOptions, type WebUICapabilities, arrayBufferToBase64, base64ToBytes, buildBaseUrl, buildPeerOptions, bytesToBase64, createPeerWithRetries, decryptChunk, decryptFilenameFromBase64, encryptFilenameToBase64, encryptToBlob, estimateTotalUploadSizeBytes, exportKeyBase64, fetchJson, generateAesGcmKey, generateP2PCode, getDefaultBase64, getDefaultCrypto, getDefaultFetch, getServerInfo, importKeyFromBase64, isLocalhostHostname, isP2PCodeLike, isSecureContextForP2P, lifetimeToMs, makeAbortSignal, parseSemverMajorMinor, parseServerUrl, resolvePeerConfig, sha256Hex, sleep, startP2PReceive, startP2PSend, validatePlainFilename };
|