Browse code

Send upload progress from phone back to the watch

Natasha Kerensikova authored on24/03/2016 23:50:32
Showing2 changed files
... ...
@@ -13,6 +13,7 @@
13 13
   "appKeys": {
14 14
     "lastSent": 110,
15 15
     "modalMessage": 120,
16
+    "uploadDone": 130,
16 17
     "dataKey": 210,
17 18
     "dataLine": 220
18 19
   },
... ...
@@ -22,7 +22,7 @@ var sender = new XMLHttpRequest();
22 22
 
23 23
 function sendHead() {
24 24
    if (to_send.length < 1) return;
25
-   var line = to_send.shift();
25
+   var line = to_send[0].split(";")[1];
26 26
    var data = new FormData();
27 27
    data.append(cfg_data_field, line);
28 28
    sender.open("POST", cfg_endpoint, true);
... ...
@@ -30,13 +30,19 @@ function sendHead() {
30 30
 }
31 31
 
32 32
 function enqueue(key, line) {
33
-   to_send.push(line);
33
+   to_send.push(key + ";" + line);
34 34
    if (to_send.length === 1) sendHead();
35 35
 }
36 36
 
37
+function uploadDone() {
38
+   var sent_key = to_send.shift().split(";")[0];
39
+   Pebble.sendAppMessage({ "uploadDone": parseInt(sent_key, 10) });
40
+   sendHead();
41
+}
42
+
37 43
 function uploadError() { console.log(this.statusText); }
38 44
 
39
-sender.addEventListener("load", sendHead);
45
+sender.addEventListener("load", uploadDone);
40 46
 sender.addEventListener("error", uploadError);
41 47
 
42 48
 Pebble.addEventListener("ready", function() {