@@ -169,8 +169,9 @@ class File {
169169 this . _remotePeers [ data . peer_id ] . interval = setInterval ( ( ) => this . _isAlive ( conn . peer ) , 500 )
170170
171171 // Define vars for chunk processing
172- const chunkSize = 65536 // 64 KB
172+ const chunkSize = 128 * 1024 // 128 KB
173173 let offset = 0
174+ let position = 0
174175
175176 // Recursive function to process each chunk
176177 const processChunk = async ( ) => {
@@ -181,12 +182,13 @@ class File {
181182 // Check if the connection to the remote peer is open
182183 if ( conn . peerConnection != null && conn . peerConnection . iceConnectionState != 'disconnected' ) {
183184 // const encryptedChunk = await this._encrypt(chunk, `PASSWORD_VALUE`)
184- conn . send ( { "webrtc-file-transfer" : { "file" : chunk , "transferred" : chunk . size , "last" : isLastChunk } } )
185+ conn . send ( { "webrtc-file-transfer" : { "file" : chunk , "transferred" : chunk . size , "last" : isLastChunk , "position" : position } } )
185186 }
186187
187188 // If it's not the last chunk, process the next one
188189 if ( data . peer_id in this . _remotePeers && ! isLastChunk ) {
189190 offset += chunkSize
191+ position += 1
190192 await processChunk ( )
191193 }
192194 }
@@ -272,7 +274,7 @@ class File {
272274
273275 // Store file chunk
274276 // const decryptedChunk = await this._decrypt(data.file, `PASSWORD_VALUE`)
275- this . _chunks . push ( data . file )
277+ this . _chunks [ data . position ] = data . file
276278 this . _transferred += data . transferred
277279
278280 // Compute progress
0 commit comments