Browse Source

Added support to cancel pending getScreen calls.

pull/77/head
Simon Eisenmann 11 years ago
parent
commit
aed4b62acc
  1. 9
      static/js/directives/screenshare.js
  2. 16
      static/js/services/chromeextension.js
  3. 31
      static/js/services/screensharing.js

9
static/js/directives/screenshare.js

@ -281,7 +281,10 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials @@ -281,7 +281,10 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials
console.log("Screen share stopped.");
}
$scope.layout.screenshare = false;
if ($scope.layout.screenshare) {
screensharing.cancelGetScreen();
$scope.layout.screenshare = false;
}
};
@ -297,6 +300,10 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials @@ -297,6 +300,10 @@ define(['jquery', 'underscore', 'text!partials/screenshare.html', 'text!partials
};
mediaStream.webrtc.e.on("done", function() {
$scope.stopScreenshare();
});
$scope.$watch("layout.screenshare", function(newval, oldval) {
if (newval && !oldval) {
$scope.doScreenshare();

16
static/js/services/chromeextension.js

@ -54,14 +54,22 @@ define(["underscore"], function(_) { @@ -54,14 +54,22 @@ define(["underscore"], function(_) {
case "Call":
var deferred = this.registry[data.n];
if (deferred) {
delete this.registry[data.n];
var call = data.Call;
if (call.Type === "Result") {
switch (call.Type) {
case "Result":
delete this.registry[data.n];
//console.log("Call complete with result", call);
deferred.resolve(call.Result);
} else {
break;
case "Notify":
//console.log("Notify", call);
deferred.notify(call.Notify);
break;
case "Error":
delete this.registry[data.n];
//console.log("Call failed with error", call);
deferred.reject(call.Error);
break
}
} else {
console.warn("Unknown call reference received", data, this.registry, this);
@ -80,7 +88,7 @@ define(["underscore"], function(_) { @@ -80,7 +88,7 @@ define(["underscore"], function(_) {
$window.addEventListener("message", function(event) {
//console.log("message", event.origin, event.source === window, event);
if (event.source === window && event.data.answer) {
// Only let through our own messages marked as answer.
// Only process answers to avoid loops.
extension.onMessage(event);
}
});

31
static/js/services/screensharing.js

@ -25,7 +25,12 @@ define(['underscore', 'webrtc.adapter'], function(_) { @@ -25,7 +25,12 @@ define(['underscore', 'webrtc.adapter'], function(_) {
// Check if we can do screensharing.
var supported = false;
// Define our helpers.
var prepare = null;
var cancel = null;
// Chrome support.
if ($window.webrtcDetectedBrowser === "chrome") {
if ($window.webrtcDetectedVersion >= 32 &&
$window.webrtcDetectedVersion < 37) {
@ -52,6 +57,7 @@ define(['underscore', 'webrtc.adapter'], function(_) { @@ -52,6 +57,7 @@ define(['underscore', 'webrtc.adapter'], function(_) {
if (chromeExtension.available) {
supported = true;
var pending = null;
prepare = function(options) {
var select = chromeExtension.call({
Type: "Action",
@ -59,7 +65,8 @@ define(['underscore', 'webrtc.adapter'], function(_) { @@ -59,7 +65,8 @@ define(['underscore', 'webrtc.adapter'], function(_) {
});
var d = $q.defer();
select.then(function(id) {
//console.log("Prepare screensharing success", id);
// Success with id.
pending = null;
if (id) {
var opts = _.extend({
chromeMediaSource: "desktop",
@ -70,15 +77,30 @@ define(['underscore', 'webrtc.adapter'], function(_) { @@ -70,15 +77,30 @@ define(['underscore', 'webrtc.adapter'], function(_) {
d.resolve(null);
}
}, function(err) {
// Error.
pending = null;
console.log("Failed to prepare screensharing", err);
d.reject(err);
}, function(data) {
// Notify.
pending = data;
});
return d.promise;
};
cancel = function() {
if (pending !== null) {
chromeExtension.call({
Type: "Action",
Action: "cancelChooseDesktopMedia",
Args: pending
});
pending = null;
}
};
}
} else {
// Currently Chrome only.
// Currently Chrome only - sorry.
}
// public API.
@ -92,6 +114,11 @@ define(['underscore', 'webrtc.adapter'], function(_) { @@ -92,6 +114,11 @@ define(['underscore', 'webrtc.adapter'], function(_) {
d.reject("No implementation to get screen.");
return d.promise;
}
},
cancelGetScreen: function() {
if (cancel) {
cancel();
}
}
}

Loading…
Cancel
Save