Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This function sends chunks of data.
- sendChunk = function(start) {
- var txbuf = bytes.slice(start, start + chunkSize);
- console.log("Sending " + txbuf.length + " bytes - starting at offset " + start);
- Pebble.sendAppMessage({ "NETDL_DATA": txbuf },
- function(e) {
- // If there is more data to send - send it.
- if (bytes.length > start + chunkSize) {
- sendChunk(start + chunkSize);
- }
- // Otherwise we are done sending. Send closing message.
- else {
- Pebble.sendAppMessage({"NETDL_END": "done" }, success, failure);
- }
- },
- // Failed to send message - Retry a few times.
- function (e) {
- if (retries++ < 3) {
- console.log("Got a nack for chunk #" + start + " - Retry...");
- sendChunk(start);
- }
- else {
- failure(e);
- }
- }
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement