diff --git a/doc/CHANNELING-API.txt b/doc/CHANNELING-API.txt index d8dbd5ee..dbd84460 100644 --- a/doc/CHANNELING-API.txt +++ b/doc/CHANNELING-API.txt @@ -681,11 +681,22 @@ File sharing data channel protocol m is the mode. Currently only "r" is known to request chunks. i is the chunk sequence number to request (integer). - Whenever you want the peer to send a chunk, request it by sending a - JSON chunk request over the data channel with the sequence which - should be transmitted. The current web implementation requests chunks - sequentially, and waiting for each chunk to be complete before - sending the request for the next one. + Whenever you want the peer to send a chunk, request it by sending a + JSON chunk request over the data channel with the sequence which + should be transmitted. The current web implementation requests chunks + sequentially, and waiting for each chunk to be complete before + sending the request for the next one. + + JSON bye request + + { + "m": "bye" + } + + This is used to clean up connections when the downloader is finished + or has manually aborted downloading. The downloader sends this message + to the connected peer which then may close the connection where this + message was received. End of Channeling API. diff --git a/static/js/mediastream/peerxfer.js b/static/js/mediastream/peerxfer.js index 855b5020..38978abb 100644 --- a/static/js/mediastream/peerxfer.js +++ b/static/js/mediastream/peerxfer.js @@ -48,8 +48,8 @@ define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens', 'w }; this.sdpConstraints = {}; // SCTP is supported from Chrome M31. - // No need to pass DTLS constraint as it is on by default in Chrome M31. - // For SCTP, reliable and ordered is true by default. + // No need to pass DTLS constraint as it is on by default in Chrome M31. + // For SCTP, reliable and ordered is true by default. this.pcConstraints = {}; // Inject token into sessiondescription and ice candidate data. @@ -58,13 +58,6 @@ define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens', 'w data._id = this.id; }, this)); - this.e.on("connectionStateChange", _.bind(function(event, iceConnectionState) { - if (iceConnectionState === "disconnected") { - // Auto cleanup stuff when we get disconnected. - this.close(); - } - }, this)); - }; // Inherit from PeerCall. @@ -78,7 +71,7 @@ define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens', 'w PeerXfer.prototype.cancel = function() { this.e.triggerHandler("cancel", [this]); this.close(); - } + }; PeerXfer.prototype.onMessage = function(event) { // Our own datachannel event. diff --git a/static/js/services/filedownload.js b/static/js/services/filedownload.js index 5cf3c02d..05788104 100644 --- a/static/js/services/filedownload.js +++ b/static/js/services/filedownload.js @@ -20,7 +20,7 @@ */ define(["jquery", "underscore"], function($, _) { - return ["fileData", "fileTransfer", "$window", "mediaStream", "safeApply", function(fileData, fileTransfer, $window, mediaStream, safeApply) { + return ["fileData", "fileTransfer", "$window", "mediaStream", "safeApply", "$timeout", function(fileData, fileTransfer, $window, mediaStream, safeApply, $timeout) { var downloads = 0; @@ -57,9 +57,14 @@ define(["jquery", "underscore"], function($, _) { $window.clearInterval(this.interval); this.interval = null; - // close all known xfers. + // Close all known xfers. _.each(this.xfer_all, function(xfer) { - xfer.cancel(); + // Implement own clean up message. + // NOTE(longsleep): See https://code.google.com/p/webrtc/issues/detail?id=1676 for reason. + xfer.send({m: "bye"}); + $timeout(function() { + xfer.cancel(); + }, 0); }); _.each(this.jobs, function(job) { job.stop = true; diff --git a/static/js/services/fileupload.js b/static/js/services/fileupload.js index cc44df91..262ffc4e 100644 --- a/static/js/services/fileupload.js +++ b/static/js/services/fileupload.js @@ -112,6 +112,10 @@ define(["jquery", "underscore", "webrtc.adapter"], function($, _) { }); }, this)); break; + case "bye": + // Close this xfer. + xfer.cancel(); + break; default: console.log("Unknown xfer control request", msg.m, msg); break;