Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-17327] (3_5_X): Add ceiling and floor to httpClient's onDataStream progress #6425

Merged
merged 6 commits into from
Dec 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class NetworkModule extends KrollModule {
@Kroll.constant public static final int NETWORK_LAN = 3;
@Kroll.constant public static final int NETWORK_UNKNOWN = 4;

@Kroll.constant public static final int PROGRESS_UNKNOWN = -1;

public enum State {
UNKNOWN,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,12 @@ else if (contentLength > maxBufferSize) {

TiBlob blob = TiBlob.blobFromData(blobData, contentType);
callbackData.put("blob", blob);
callbackData.put("progress", ((double)totalSize)/((double)contentLength));
double progress = ((double)totalSize)/((double)contentLength);
// return progress as -1 if it is outside the valid range
if (progress > 1 || progress < 0) {
progress = NetworkModule.PROGRESS_UNKNOWN;
}
callbackData.put("progress", progress);

dispatchCallback("ondatastream", callbackData);
}
Expand Down
3 changes: 2 additions & 1 deletion apidoc/Titanium/Network/HTTPClient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ properties:
Must be set before calling `open`.

The `progress` property of the event will contain a value from 0.0-1.0 with the progress of
the request.
the request. On iOS and Android as of 3.5.0, if the progress can not be calculated,
the value will be [PROGRESS_UNKNOWN](Titanium.Network.PROGRESS_UNKNOWN).
type: Callback<Object>

- name: onerror
Expand Down
7 changes: 7 additions & 0 deletions apidoc/Titanium/Network/Network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,13 @@ properties:
platforms: [iphone, ipad]
since: "1.8.0.1"

- name: PROGRESS_UNKNOWN
summary: Constant value specifying that the progress of a download can not be calculated.
type: Number
permission: read-only
platforms: [android, iphone, ipad]
since: "3.5.0"

- name: allHTTPCookies
summary: A list of all cookies in the cookie storage.
type: Array<Titanium.Network.Cookie>
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/NetworkModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ -(NSNumber*)networkType
MAKE_SYSTEM_PROP(TLS_VERSION_1_1, TLS_VERSION_1_1);
MAKE_SYSTEM_PROP(TLS_VERSION_1_2, TLS_VERSION_1_2);

MAKE_SYSTEM_NUMBER(PROGRESS_UNKNOWN, NUMINT(-1));

#pragma mark Push Notifications

- (NSString*) remoteDeviceUUID
Expand Down
7 changes: 6 additions & 1 deletion iphone/Classes/TiNetworkHTTPClientProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,12 @@ -(void)request:(APSHTTPRequest *)request onDataStream:(APSHTTPResponse *)respons
if(_downloadTime == 0 || diff > TI_HTTP_REQUEST_PROGRESS_INTERVAL || [response readyState] == APSHTTPResponseStateDone) {
_downloadTime = 0;
NSDictionary *eventDict = [NSMutableDictionary dictionary];
[eventDict setValue:[NSNumber numberWithFloat: [response downloadProgress]] forKey:@"progress"];
float downloadProgress = [response downloadProgress];
// return progress as -1 if it is outside the valid range
if (downloadProgress > 1 || downloadProgress < 0) {
downloadProgress = -1.0f;
}
[eventDict setValue:[NSNumber numberWithFloat: downloadProgress] forKey:@"progress"];
[self fireCallback:@"ondatastream" withArg:eventDict withSource:self];
}
if(_downloadTime == 0) {
Expand Down