tidev / titanium-sdk

🚀 Native iOS and Android Apps with JavaScript
https://titaniumsdk.com/
Other
2.76k stars 1.21k forks source link

XHR onsendstream progress event fires slow #14085

Open dlewis23 opened 4 months ago

dlewis23 commented 4 months ago

I have searched and made sure there are no existing issues for the issue I am filing

Description

When doing an XHR upload the onsendstream event is not fired often if the user has a slow connection (< ~5 Mbps). It can take many seconds in-between event fires. This means you can not get a very accurate status of the upload or a nice progress. It seems to be only updating for every 250 - 750 KB of data sent.

Expected Behavior

The onsendstream event should fire more often even if the connection or progress is slow.

Actual behavior

The onsendstream is fired at long intervals when the user has a slow connection.

Reproducible sample

var uploadData = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'upload_file.bin').read();

var xhr = Titanium.Network.createHTTPClient();
xhr.onsendstream = function(e){ 
    console.log(e.progress);
};

xhr.onload = function(e) {
    xhr.abort();
    xhr = null;
};

xhr.open('POST','https://nyc.speedsmart.net/upload.php', true);
xhr.send({media: uploadData});

Steps to reproduce

Use the above code to upload a file and watch the progress, if you have a fast connection it will work as expected, on a slow connection you will see long pauses between the progress events being fired.

To slow your connection use: network link conditioner from Xcode additional tools and set a profile with a 1 Mbps upload speed. You can get Xcode additional tools here: https://download.developer.apple.com/Developer_Tools/Additional_Tools_for_Xcode_15.4/Additional_Tools_for_Xcode_15.4.dmg

Platform

iOS

SDK version you are using

12.4.0.GA

Alloy version you are using

No response