Browse Source

Handle conference cases where participants join/leave existing presentation.

pull/70/head
Joachim Bauch 12 years ago
parent
commit
7b0f599ec2
  1. 90
      static/js/directives/presentation.js

90
static/js/directives/presentation.js

@ -32,6 +32,17 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
$scope.hideControlsBar = true; $scope.hideControlsBar = true;
$scope.pendingPageRequest = null; $scope.pendingPageRequest = null;
$scope.presentationLoaded = false; $scope.presentationLoaded = false;
$scope.currentFileInfo = null;
$scope.currentPage = null;
$scope.receivedPage = null;
$scope.resetProperties = function() {
$scope.isPresenter = false;
$scope.hideControlsBar = true;
$scope.currentFileInfo = null;
$scope.currentPage = null;
$scope.receivedPage = null;
};
$scope.$on("pdfLoaded", function(event, source, doc) { $scope.$on("pdfLoaded", function(event, source, doc) {
if ($scope.isPresenter) { if ($scope.isPresenter) {
@ -120,8 +131,7 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
case "FileInfo": case "FileInfo":
console.log("Received presentation file request", data); console.log("Received presentation file request", data);
$scope.$apply(function(scope) { $scope.$apply(function(scope) {
scope.isPresenter = false; scope.resetProperties();
scope.hideControlsBar = true;
downloadPresentation(data.FileInfo, from); downloadPresentation(data.FileInfo, from);
}); });
break; break;
@ -129,9 +139,10 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
case "Show": case "Show":
console.log("Received presentation show request", data); console.log("Received presentation show request", data);
$scope.$apply(function(scope) { $scope.$apply(function(scope) {
scope.isPresenter = false; if (!scope.layout.presentation) {
scope.hideControlsBar = true; scope.resetProperties();
scope.layout.presentation = true; scope.layout.presentation = true;
}
}); });
break; break;
@ -144,6 +155,7 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
case "Page": case "Page":
$scope.$apply(function(scope) { $scope.$apply(function(scope) {
scope.receivedPage = data.Page;
if (!scope.presentationLoaded) { if (!scope.presentationLoaded) {
console.log("Queuing presentation page request, not loaded yet", data); console.log("Queuing presentation page request, not loaded yet", data);
scope.pendingPageRequest = data.Page; scope.pendingPageRequest = data.Page;
@ -174,12 +186,38 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
peers[peercall.id] = true; peers[peercall.id] = true;
mediaStream.api.apply("sendPresentation", { mediaStream.api.apply("sendPresentation", {
send: function(type, data) { send: function(type, data) {
return peercall.peerconnection.send(data); if (!peercall.peerconnection.datachannelReady) {
return peercall.e.one("dataReady", function() {
peercall.peerconnection.send(data);
});
} else {
return peercall.peerconnection.send(data);
}
} }
})(peercall.from, token, { })(peercall.id, token, {
Type: "Show", Type: "Show",
Show: true Show: true
}); });
if ($scope.currentFileInfo !== null) {
mediaStream.api.apply("sendPresentation", {
send: function(type, data) {
return peercall.peerconnection.send(data);
}
})(peercall.id, token, {
Type: "FileInfo",
FileInfo: $scope.currentFileInfo
});
}
if ($scope.currentPage !== null) {
mediaStream.api.apply("sendPresentation", {
send: function(type, data) {
return peercall.peerconnection.send(data);
}
})(peercall.id, token, {
Type: "Page",
Page: $scope.currentPage
});
}
}; };
// Updater function to bring in new calls. // Updater function to bring in new calls.
@ -192,7 +230,7 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
break; break;
case "closed": case "closed":
delete peers[currentcall.id]; delete peers[currentcall.id];
if (!peers.length) { if (_.isEmpty(peers)) {
console.log("All peers disconnected, stopping presentation"); console.log("All peers disconnected, stopping presentation");
$scope.$apply(function(scope) { $scope.$apply(function(scope) {
scope.hidePresentation(); scope.hidePresentation();
@ -203,6 +241,13 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
}; };
$scope.$on("pdfPageLoading", function(event, page) { $scope.$on("pdfPageLoading", function(event, page) {
if ($scope.receivedPage === page) {
// we received this page request, don't publish to others
$scope.receivedPage = null;
return;
}
$scope.currentPage = page;
mediaStream.webrtc.callForEachCall(function(peercall) { mediaStream.webrtc.callForEachCall(function(peercall) {
mediaStream.api.apply("sendPresentation", { mediaStream.api.apply("sendPresentation", {
send: function(type, data) { send: function(type, data) {
@ -215,10 +260,6 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
}); });
}); });
mediaStream.webrtc.e.on("done", function() {
$scope.hidePresentation();
});
$scope.startPresentingFile = function(file, fileInfo) { $scope.startPresentingFile = function(file, fileInfo) {
console.log("Advertising file", file, fileInfo); console.log("Advertising file", file, fileInfo);
// TODO(fancycode): other peers should either request the file or subscribe rendered images (e.g. for mobile app), for now we send the whole file // TODO(fancycode): other peers should either request the file or subscribe rendered images (e.g. for mobile app), for now we send the whole file
@ -235,6 +276,8 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
uploadPresentation(fileInfo); uploadPresentation(fileInfo);
$scope.isPresenter = true; $scope.isPresenter = true;
$scope.hideControlsBar = false; $scope.hideControlsBar = false;
$scope.currentFileInfo = fileInfo;
$scope.receivedPage = null;
$scope.$emit("openPdf", file); $scope.$emit("openPdf", file);
}; };
@ -264,11 +307,7 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
return namespace + "_" + $scope.myid; return namespace + "_" + $scope.myid;
}; };
$scope.showPresentation = function(force) { $scope.showPresentation = function() {
if (!force && $scope.layout.presentation) {
return;
}
console.log("Presentation active"); console.log("Presentation active");
$scope.layout.presentation = true; $scope.layout.presentation = true;
$scope.$emit("mainview", "presentation", true); $scope.$emit("mainview", "presentation", true);
@ -296,11 +335,7 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
mediaStream.webrtc.e.on("statechange", updater); mediaStream.webrtc.e.on("statechange", updater);
}; };
$scope.hidePresentation = function(force) { $scope.hidePresentation = function() {
if (!force && !$scope.layout.presentation) {
return;
}
console.log("Presentation disabled"); console.log("Presentation disabled");
if (currentToken) { if (currentToken) {
mediaStream.webrtc.callForEachCall(function(peercall) { mediaStream.webrtc.callForEachCall(function(peercall) {
@ -319,9 +354,8 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
$scope.$emit("closePdf"); $scope.$emit("closePdf");
finishUploadPresentation(); finishUploadPresentation();
finishDownloadPresentation(); finishDownloadPresentation();
$scope.resetProperties();
$scope.layout.presentation = false; $scope.layout.presentation = false;
$scope.isPresenter = false;
$scope.hideControlsBar = true;
peers = {}; peers = {};
$scope.$emit("mainview", "presentation", false); $scope.$emit("mainview", "presentation", false);
mediaStream.webrtc.e.off("statechange", updater); mediaStream.webrtc.e.off("statechange", updater);
@ -329,9 +363,9 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
$scope.$watch("layout.presentation", function(newval, oldval) { $scope.$watch("layout.presentation", function(newval, oldval) {
if (newval && !oldval) { if (newval && !oldval) {
$scope.showPresentation(true); $scope.showPresentation();
} else if (!newval && oldval) { } else if (!newval && oldval) {
$scope.hidePresentation(true); $scope.hidePresentation();
} }
}); });

Loading…
Cancel
Save