Advertisement
Guest User

pebble send chunk

a guest
Mar 5th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. // This function sends chunks of data.
  2. sendChunk = function(start) {
  3. var txbuf = bytes.slice(start, start + chunkSize);
  4. console.log("Sending " + txbuf.length + " bytes - starting at offset " + start);
  5. Pebble.sendAppMessage({ "NETDL_DATA": txbuf },
  6. function(e) {
  7. // If there is more data to send - send it.
  8. if (bytes.length > start + chunkSize) {
  9. sendChunk(start + chunkSize);
  10. }
  11. // Otherwise we are done sending. Send closing message.
  12. else {
  13. Pebble.sendAppMessage({"NETDL_END": "done" }, success, failure);
  14. }
  15. },
  16. // Failed to send message - Retry a few times.
  17. function (e) {
  18. if (retries++ < 3) {
  19. console.log("Got a nack for chunk #" + start + " - Retry...");
  20. sendChunk(start);
  21. }
  22. else {
  23. failure(e);
  24. }
  25. }
  26. );
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement