@@ -11,7 +11,12 @@ function onProgress(nsSession, nsTask, sent, expectedTotal) {
1111 const task = Task . getTask ( nsSession , nsTask ) ;
1212 task . notifyPropertyChange ( "upload" , task . upload ) ;
1313 task . notifyPropertyChange ( "totalUpload" , task . totalUpload ) ;
14- task . notify ( { eventName : "progress" , object : task , currentBytes : sent , totalBytes : expectedTotal } ) ;
14+ task . notify ( < common . ProgressEventData > {
15+ eventName : "progress" ,
16+ object : task ,
17+ currentBytes : sent ,
18+ totalBytes : expectedTotal
19+ } ) ;
1520}
1621
1722function onError ( session , nsTask , error ) {
@@ -22,12 +27,27 @@ function onError(session, nsTask, error) {
2227 }
2328 if ( error ) {
2429 task . notifyPropertyChange ( "status" , task . status ) ;
25- task . notify ( { eventName : "error" , object : task , error : error } ) ;
30+ task . notify ( < common . ErrorEventData > {
31+ eventName : "error" ,
32+ object : task ,
33+ error,
34+ responseCode : nsTask && nsTask . response ? ( < NSHTTPURLResponse > nsTask . response ) . statusCode : - 1
35+ } ) ;
2636 } else {
2737 task . notifyPropertyChange ( "upload" , task . upload ) ;
2838 task . notifyPropertyChange ( "totalUpload" , task . totalUpload ) ;
29- task . notify ( { eventName : "progress" , object : task , currentBytes : nsTask . countOfBytesSent , totalBytes : nsTask . countOfBytesExpectedToSend } ) ;
30- task . notify ( { eventName : "complete" , object : task } ) ;
39+ task . notify ( < common . ProgressEventData > {
40+ eventName : "progress" ,
41+ object : task ,
42+ currentBytes : nsTask . countOfBytesSent ,
43+ totalBytes : nsTask . countOfBytesExpectedToSend
44+ } ) ;
45+ task . notify ( < common . CompleteEventData > {
46+ eventName : "complete" ,
47+ object : task ,
48+ responseCode : nsTask && nsTask . response ? ( < NSHTTPURLResponse > nsTask . response ) . statusCode : - 1
49+ } ) ;
50+
3151 Task . _tasks . delete ( nsTask ) ;
3252 }
3353}
@@ -55,26 +75,9 @@ class BackgroundUploadDelegate extends NSObject implements NSURLSessionDelegate,
5575 }
5676
5777 // NSURLSessionTaskDelegate
58- URLSessionTaskDidCompleteWithError ( session , nsTask , error ) {
78+ URLSessionTaskDidCompleteWithError ( session : NSURLSession , nsTask : NSURLSessionTask , error : NSError ) {
5979 dispatch_async ( main_queue , ( ) => {
6080 zonedOnError ( session , nsTask , error ) ;
61- task . notify ( < common . ErrorEventData > {
62- eventName : "error" ,
63- object : task ,
64- error,
65- responseCode : nsTask && nsTask . response ? ( < NSHTTPURLResponse > nsTask . response ) . statusCode : - 1
66- } ) ;
67- task . notify ( < common . ProgressEventData > {
68- eventName : "progress" ,
69- object : task ,
70- currentBytes : nsTask . countOfBytesSent ,
71- totalBytes : nsTask . countOfBytesExpectedToSend
72- } ) ;
73- task . notify ( < common . CompleteEventData > {
74- eventName : "complete" ,
75- object : task ,
76- responseCode : nsTask && nsTask . response ? ( < NSHTTPURLResponse > nsTask . response ) . statusCode : - 1
77- } ) ;
7881 } ) ;
7982 }
8083
@@ -88,12 +91,6 @@ class BackgroundUploadDelegate extends NSObject implements NSURLSessionDelegate,
8891 URLSessionTaskDidSendBodyDataTotalBytesSentTotalBytesExpectedToSend ( nsSession : NSURLSession , nsTask : NSURLSessionTask , data , sent : number , expectedTotal : number ) {
8992 dispatch_async ( main_queue , ( ) => {
9093 zonedOnProgress ( nsSession , nsTask , sent , expectedTotal ) ;
91- task . notify ( < common . ProgressEventData > {
92- eventName : "progress" ,
93- object : task ,
94- currentBytes : sent ,
95- totalBytes : expectedTotal
96- } ) ;
9794 } ) ;
9895 }
9996
@@ -125,10 +122,10 @@ class BackgroundUploadDelegate extends NSObject implements NSURLSessionDelegate,
125122 const jsonString = NSString . alloc ( ) . initWithDataEncoding ( data , NSUTF8StringEncoding ) ;
126123
127124 jsTask . notify ( < common . ResultEventData > {
128- eventName : "responded" ,
129- object : jsTask ,
130- data : jsonString . toString ( ) ,
131- responseCode : dataTask && dataTask . response ? ( < NSHTTPURLResponse > dataTask . response ) . statusCode : - 1
125+ eventName : "responded" ,
126+ object : jsTask ,
127+ data : jsonString . toString ( ) ,
128+ responseCode : dataTask && dataTask . response ? ( < NSHTTPURLResponse > dataTask . response ) . statusCode : - 1
132129 } ) ;
133130 } ) ;
134131 }
@@ -253,7 +250,7 @@ class Task extends Observable {
253250 public _fileToCleanup : string ;
254251 private _task : NSURLSessionTask ;
255252 private _session : NSURLSession ;
256- public testProp = 0 ;
253+
257254 constructor ( nsSession : NSURLSession , nsTask : NSURLSessionTask ) {
258255 super ( ) ;
259256 this . _task = nsTask ;
0 commit comments