filepizza-client 2.0.0-alpha.3 → 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 CHANGED
@@ -28,8 +28,10 @@ import { FilePizzaUploader } from 'filepizza-client';
28
28
 
29
29
  const uploader = new FilePizzaUploader({
30
30
  filePizzaServerUrl: 'https://your-filepizza-server.com',
31
- // You can optionally specify an additional shared slug where multiple uploaders can connect and share files
32
- sharedSlug: 'filepizza-demo'
31
+
32
+ // You can optionally specify an additional shared slug
33
+ // where multiple uploaders can connect and share files
34
+ sharedSlug: 'filepizza-demo',
33
35
  });
34
36
 
35
37
  await uploader.initialize();
@@ -39,8 +41,13 @@ uploader.on('progress', (progressInfo) => {
39
41
  });
40
42
 
41
43
  uploader.setFiles(fileList); // From an input element
44
+
42
45
  const links = uploader.getShareableLinks();
43
- console.log(`Shareable links: ${links.join(', ')}`);
46
+
47
+ if (links) {
48
+ console.log(`Long link: ${links.long}`);
49
+ console.log(`Short link: ${links.short}`);
50
+ }
44
51
  ```
45
52
 
46
53
  Set up a FilePizza client instance and use it to download files:
@@ -49,7 +56,7 @@ Set up a FilePizza client instance and use it to download files:
49
56
  import { FilePizzaDownloader } from 'filepizza-client';
50
57
 
51
58
  const downloader = new FilePizzaDownloader({
52
- filePizzaServerUrl: 'https://your-filepizza-server.com'
59
+ filePizzaServerUrl: 'https://your-filepizza-server.com',
53
60
  });
54
61
 
55
62
  await downloader.initialize();
@@ -62,6 +69,45 @@ await downloader.connect(filePizzaUrl);
62
69
  await downloader.startDownload();
63
70
  ```
64
71
 
72
+ By default, the client:
73
+
74
+ - Fetches ICE server configuration from the FilePizza server
75
+ - Attempts to discover a PeerJS signaling server from:
76
+ ```
77
+ /api/peerjs-servers
78
+ ```
79
+ - Falls back to PeerJS defaults if no signaling server is configured
80
+
81
+ You can also explicitly override the PeerJS signaling server configuration.
82
+
83
+ The uploader and downloader must use the same PeerJS signaling server in order to connect:
84
+
85
+ ```javascript
86
+ import {
87
+ FilePizzaUploader,
88
+ FilePizzaDownloader,
89
+ } from 'filepizza-client';
90
+
91
+ const peerJSSignalingServer = {
92
+ host: 'peerjs.example.com',
93
+ port: 443,
94
+ path: '/',
95
+ secure: true,
96
+ };
97
+
98
+ const uploader = new FilePizzaUploader({
99
+ filePizzaServerUrl: 'https://your-filepizza-server.com',
100
+ peerJSSignalingServer,
101
+ });
102
+
103
+ const downloader = new FilePizzaDownloader({
104
+ filePizzaServerUrl: 'https://your-filepizza-server.com',
105
+ peerJSSignalingServer,
106
+ });
107
+ ```
108
+
109
+ If no `peerJSSignalingServer` is provided, the client will use the FilePizza server configuration (if available) or default PeerJS behavior.
110
+
65
111
  ## Examples
66
112
 
67
113
  ### Regular Example
@@ -1,7 +1,12 @@
1
1
  import { EventEmitter } from './event-emitter';
2
- import { FileInfo, ProgressInfo, ConnectionStatus, CompletedFile } from './types';
2
+ import { FileInfo, ProgressInfo, ConnectionStatus, CompletedFile, PeerJSSignalingServer } from './types';
3
+ type DownloaderOptions = {
4
+ filePizzaServerUrl?: string;
5
+ peerJSSignalingServer?: PeerJSSignalingServer;
6
+ discoverPeerJSSignalingServer?: boolean;
7
+ };
3
8
  /**
4
- * FilePizza Downloader - connects to FilePizza uploads
9
+ * FilePizza Downloader - connects to FilePizza uploads.
5
10
  */
6
11
  export declare class FilePizzaDownloader extends EventEmitter {
7
12
  private peer?;
@@ -17,143 +22,55 @@ export declare class FilePizzaDownloader extends EventEmitter {
17
22
  private isPasswordRequired;
18
23
  private isPasswordInvalid;
19
24
  private errorMessage?;
20
- private iceServers?;
21
25
  private completedFiles;
22
- /**
23
- * Create a new FilePizza downloader
24
- * @param options Configuration options
25
- */
26
- constructor(options?: {
27
- filePizzaServerUrl?: string;
28
- });
29
- /**
30
- * Initialize the downloader
31
- */
26
+ private peerJSSignalingServer?;
27
+ private discoverPeerJSSignalingServer;
28
+ constructor(options?: DownloaderOptions);
32
29
  initialize(): Promise<void>;
33
- /**
34
- * Connect to an uploader using a FilePizza URL or slug
35
- */
36
30
  connect(urlOrSlug: string): Promise<boolean>;
37
- /**
38
- * Reset the connection state to begin new download
39
- */
40
31
  private resetConnectionState;
41
- /**
42
- * Submit password for protected download
43
- */
44
32
  submitPassword(password: string): void;
45
- /**
46
- * Start downloading the files
47
- */
48
33
  startDownload(): Promise<void>;
49
- /**
50
- * Pause the download
51
- */
52
34
  pauseDownload(): void;
53
35
  /**
54
- * Resume the download
36
+ * Kept for public API compatibility.
37
+ *
38
+ * The server frontend protocol currently supports pause/stop, not resume.
39
+ * A paused transfer should be restarted by creating a new connection.
55
40
  */
56
41
  resumeDownload(): void;
57
- /**
58
- * Cancel the download
59
- */
60
42
  cancelDownload(): void;
61
- /**
62
- * Cleanup resources when done
63
- */
64
43
  private cleanupFileStreams;
65
- /**
66
- * Get file information
67
- */
68
44
  getFileInfo(): FileInfo[];
69
- /**
70
- * Get download status
71
- */
72
45
  getStatus(): {
73
46
  status: ConnectionStatus;
74
47
  isPasswordRequired: boolean;
75
48
  isPasswordInvalid: boolean;
76
49
  errorMessage?: string;
77
50
  };
78
- /**
79
- * Get progress information
80
- */
81
51
  getProgress(): ProgressInfo;
82
- /**
83
- * Extract slug from URL or use directly
84
- */
85
52
  private extractSlug;
53
+ private fetchChannel;
86
54
  /**
87
- * Extract uploader peer IDs from the FilePizza server when multiple uploaders are present
55
+ * Fallback for older FilePizza servers that do not expose /api/channel/:slug.
88
56
  */
57
+ private extractUploaderPeerIDsFromHtml;
89
58
  private extractUploaderPeerIDs;
90
- /**
91
- * Look up the uploader's peer ID from the FilePizza server
92
- */
93
59
  private lookupUploaderPeerID;
94
- /**
95
- * Connect to a specific uploader by ID
96
- */
97
60
  getAvailableUploaders(urlOrSlug: string): Promise<string[]>;
98
- /**
99
- * Connect to a specific uploader by ID
100
- */
101
61
  connectToUploader(uploaderId: string): Promise<boolean>;
102
- /**
103
- * Get ICE servers from the FilePizza server
104
- */
105
- private getIceServers;
106
- /**
107
- * Connect directly to a peer
108
- */
109
62
  private connectToPeer;
110
- /**
111
- * Handle incoming data from uploader
112
- */
113
63
  private handleData;
114
- /**
115
- * Handle password required message
116
- */
117
64
  private handlePasswordRequired;
118
- /**
119
- * Handle file info message
120
- */
121
65
  private handleInfo;
122
- /**
123
- * Handle error message
124
- */
125
66
  private handleError;
126
- /**
127
- * Handle report message (channel reported for violation)
128
- */
129
67
  private handleReport;
130
- /**
131
- * Handle chunk message
132
- */
133
68
  private handleChunk;
134
- /**
135
- * Initialize streams for all files
136
- */
137
69
  private initializeFileStreams;
138
- /**
139
- * Store a completed file
140
- */
141
70
  private storeCompletedFile;
142
- /**
143
- * Download a completed file
144
- */
145
71
  downloadFile(fileName: string): Promise<void>;
146
- /**
147
- * Get completed files
148
- */
149
72
  getCompletedFiles(): CompletedFile[];
150
- /**
151
- * Download all completed files
152
- */
153
73
  downloadAllFiles(): Promise<void>;
154
- /**
155
- * Request the next file
156
- */
157
74
  private requestNextFile;
158
75
  private getBrowserName;
159
76
  private getBrowserVersion;
@@ -162,3 +79,4 @@ export declare class FilePizzaDownloader extends EventEmitter {
162
79
  private getMobileVendor;
163
80
  private getMobileModel;
164
81
  }
82
+ export {};