Browse Source

Merge pull request #70 from fancycode/pdfjs_playground

PDF presentations
pull/71/head
Simon Eisenmann 11 years ago
parent
commit
780f47b0c4
  1. 2
      Makefile.am
  2. 17
      build/build.js
  3. 4
      html/main.html
  4. 118
      src/styles/components/_presentation.scss
  5. 1
      src/styles/main.scss
  6. 8
      static/js/directives/directives.js
  7. 346
      static/js/directives/pdfcanvas.js
  8. 444
      static/js/directives/presentation.js
  9. 559
      static/js/libs/pdf/compatibility.js
  10. 6533
      static/js/libs/pdf/pdf.js
  11. 44065
      static/js/libs/pdf/pdf.worker.js
  12. 7
      static/js/main.js
  13. 20
      static/js/mediastream/api.js
  14. 7
      static/js/services/filedownload.js
  15. 25
      static/partials/presentation.html

2
Makefile.am

@ -132,6 +132,7 @@ install:
$(INSTALL) -d $(SHARE)/www/static/fonts $(INSTALL) -d $(SHARE)/www/static/fonts
$(INSTALL) -d $(SHARE)/www/static/translation $(INSTALL) -d $(SHARE)/www/static/translation
$(INSTALL) -d $(SHARE)/www/static/css $(INSTALL) -d $(SHARE)/www/static/css
$(INSTALL) -d $(SHARE)/www/static/js/libs/pdf
$(INSTALL) $(DIST_BIN)/* $(BIN) $(INSTALL) $(DIST_BIN)/* $(BIN)
$(INSTALL) -m 644 server.conf.in $(CONFIG_DIR)/$(CONFIG_FILE) $(INSTALL) -m 644 server.conf.in $(CONFIG_DIR)/$(CONFIG_FILE)
$(INSTALL) html/* $(SHARE)/www/html $(INSTALL) html/* $(SHARE)/www/html
@ -142,6 +143,7 @@ install:
$(INSTALL) static/css/* $(SHARE)/www/static/css $(INSTALL) static/css/* $(SHARE)/www/static/css
$(INSTALL) -D static/js/libs/require/require.js $(SHARE)/www/static/js/libs/require/require.js $(INSTALL) -D static/js/libs/require/require.js $(SHARE)/www/static/js/libs/require/require.js
$(INSTALL) $(OUTPUT_JS)/*.js $(SHARE)/www/static/js $(INSTALL) $(OUTPUT_JS)/*.js $(SHARE)/www/static/js
$(INSTALL) $(OUTPUT_JS)/libs/pdf/*.js $(SHARE)/www/static/js/libs/pdf
clean: clean:
GOPATH=$(GOPATH) $(GO) clean -i $(PKG) GOPATH=$(GOPATH) $(GO) clean -i $(PKG)

17
build/build.js

@ -50,6 +50,9 @@
}, },
{ {
name: 'base', name: 'base',
include: [
'pdf.compatibility'
]
}, },
{ {
name: 'app', name: 'app',
@ -58,6 +61,20 @@
'base' 'base'
], ],
inlineText: true, inlineText: true,
},
{
name: 'pdf',
dir: './out/libs/pdf',
exclude: [
'base'
]
},
{
name: 'pdf.worker',
dir: './out/libs/pdf',
override: {
skipModuleInsertion: true
}
} }
] ]
}) })

4
html/main.html

@ -14,6 +14,7 @@
</div> </div>
<status-message></status-message> <status-message></status-message>
<div class="ng-cloak right"> <div class="ng-cloak right">
<button title="{{_('Presentation')}}" class="btn aenablebtn" ng-show="status=='connected' || status=='conference' || layout.presentation" ng-model="layout.presentation" btn-checkbox><i class="fa fa-file-pdf-o"></i></button>
<button title="{{_('Share your screen')}}" class="btn aenablebtn" ng-show="isChrome && webrtcDetectedVersion >= 32 && (status=='connected' || status=='conference' || layout.screenshare)" ng-model="layout.screenshare" btn-checkbox><i class="fa fa-desktop"></i></button> <button title="{{_('Share your screen')}}" class="btn aenablebtn" ng-show="isChrome && webrtcDetectedVersion >= 32 && (status=='connected' || status=='conference' || layout.screenshare)" ng-model="layout.screenshare" btn-checkbox><i class="fa fa-desktop"></i></button>
<button title="{{_('Chat')}}" class="btn" ng-class="{messagesunseen: chatMessagesUnseen>0}" ng-model="layout.chat" btn-checkbox btn-checkbox-true="true" btn-checkbox-false="false"><i class="fa fa-comments-o"></i><span class="badge" ng-show="chatMessagesUnseen">{{chatMessagesUnseen}}</span></button> <button title="{{_('Chat')}}" class="btn" ng-class="{messagesunseen: chatMessagesUnseen>0}" ng-model="layout.chat" btn-checkbox btn-checkbox-true="true" btn-checkbox-false="false"><i class="fa fa-comments-o"></i><span class="badge" ng-show="chatMessagesUnseen">{{chatMessagesUnseen}}</span></button>
<button title="{{_('Mute microphone')}}" class="btn amutebtn" ng-model="microphoneMute" btn-checkbox btn-checkbox-true="true" btn-checkbox-false="false"><i class="fa fa-microphone-slash"></i></button> <button title="{{_('Mute microphone')}}" class="btn amutebtn" ng-model="microphoneMute" btn-checkbox btn-checkbox-true="true" btn-checkbox-false="false"><i class="fa fa-microphone-slash"></i></button>
@ -34,6 +35,9 @@
<div id="screenshare" class="ng-cloak mainview"> <div id="screenshare" class="ng-cloak mainview">
<screenshare/> <screenshare/>
</div> </div>
<div id="presentation" class="ng-cloak mainview">
<presentation/>
</div>
<div class="ng-cloak" id="rightslide"> <div class="ng-cloak" id="rightslide">
<div class="rightslidepane"> <div class="rightslidepane">
<div id="buddylist"><buddy-list/></div> <div id="buddylist"><buddy-list/></div>

118
src/styles/components/_presentation.scss

@ -0,0 +1,118 @@
/*
* Spreed WebRTC.
* Copyright (C) 2013-2014 struktur AG
*
* This file is part of Spreed WebRTC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
.presentation {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
}
.presentation-target {
width: 100%;
font-size: 10em;
margin-top: 30px;
}
.presentationpane .welcome {
padding: 0 !important;
}
.presentationpane .welcome h1 {
white-space: normal;
}
.presentationpane .welcome div {
text-align: center;
}
.presentationpane .welcome button {
margin-top: 30px;
}
.presentationpane .welcome .progress span {
text-shadow: none;
}
.presentationpane .welcome .progress .download-info {
position: absolute;
left: 0;
width: 100%;
color: $text-color;
text-shadow: 1px 1px 1px white;
}
.mainPresentation #presentation {
display: block;
}
.presentationpane {
bottom: 0;
left: 0;
overflow: auto;
position: absolute;
right: 0;
top: 0;
}
.presentationpane {
.canvasContainer {
width: 100%;
height: 100%;
}
canvas {
position: relative;
display: block;
}
}
.presentation .overlaybar {
bottom: 0;
left: 0;
right: 0;
text-align: center;
}
.presentation .overlaybar a.btn {
position: absolute;
font-size: 20px;
padding: 4px 6px;
top: 0px;
line-height: 28px;
}
.presentation .overlaybar a.btn-prev {
left: 40px;
}
.presentation .overlaybar a.btn-next {
right: 0px;
}
.presentation .overlaybar span {
line-height: 30px;
}
.pageinfo input {
display: inline;
width: 70px;
}

1
src/styles/main.scss

@ -49,5 +49,6 @@
@import "components/roombar"; @import "components/roombar";
@import "components/social"; @import "components/social";
@import "components/contactsmanager"; @import "components/contactsmanager";
@import "components/presentation";
@import "shame"; @import "shame";

8
static/js/directives/directives.js

@ -37,7 +37,9 @@ define([
'directives/socialshare', 'directives/socialshare',
'directives/page', 'directives/page',
'directives/contactrequest', 'directives/contactrequest',
'directives/defaultdialog'], function(_, onEnter, onEscape, statusMessage, buddyList, buddyPicture, settings, chat, audioVideo, usability, audioLevel, fileInfo, screenshare, roomBar, socialShare, page, contactRequest, defaultDialog) { 'directives/defaultdialog',
'directives/pdfcanvas',
'directives/presentation'], function(_, onEnter, onEscape, statusMessage, buddyList, buddyPicture, settings, chat, audioVideo, usability, audioLevel, fileInfo, screenshare, roomBar, socialShare, page, contactRequest, defaultDialog, pdfcanvas, presentation) {
var directives = { var directives = {
onEnter: onEnter, onEnter: onEnter,
@ -56,7 +58,9 @@ define([
socialShare: socialShare, socialShare: socialShare,
page: page, page: page,
contactRequest: contactRequest, contactRequest: contactRequest,
defaultDialog: defaultDialog defaultDialog: defaultDialog,
pdfcanvas: pdfcanvas,
presentation: presentation
}; };
var initialize = function(angModule) { var initialize = function(angModule) {

346
static/js/directives/pdfcanvas.js

@ -0,0 +1,346 @@
/*
* Spreed WebRTC.
* Copyright (C) 2013-2014 struktur AG
*
* This file is part of Spreed WebRTC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
define(['require', 'underscore', 'jquery'], function(require, _, $) {
return ["$compile", "translation", function($compile, translation) {
var pdfjs = null;
var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
var container = $($element);
var PDFCanvas = function(scope, canvases) {
this.scope = scope;
this.canvases = canvases;
this.doc = null;
this.currentPage = null;
this.currentPageNumber = null;
this.pendingPageNumber = null;
this.renderTask = null;
};
PDFCanvas.prototype._close = function() {
this._stopRendering();
if (this.currentPage) {
this.currentPage.destroy();
this.currentPage = null;
}
if (this.doc) {
this.doc.cleanup();
this.doc.destroy();
this.doc = null;
}
this.pendingPageNumber = null;
this.currentPageNumber = -1;
this.scope.maxPageNumber = -1;
// clear visible canvas so it's empty when we show the next document
var canvas = this.canvases[this.scope.canvasIndex];
canvas.getContext("2d").clearRect(0, 0, canvas.width, canvas.height);
};
PDFCanvas.prototype.close = function() {
this._close();
this.scope.$emit("pdfClosed");
};
PDFCanvas.prototype.open = function(file) {
console.log("Loading PDF from", file);
this._close();
if (typeof file === "string") {
// got a url
this._openFile(file);
return;
}
var fp = file.file || file;
if (typeof URL !== "undefined" && URL.createObjectURL) {
var url = URL.createObjectURL(fp);
this._openFile(url);
} else {
var fileReader = new FileReader();
fileReader.onload = _.bind(function(evt) {
var buffer = evt.target.result;
var uint8Array = new Uint8Array(buffer);
this._openFile(uint8Array);
}, this);
fileReader.readAsArrayBuffer(fp);
}
};
PDFCanvas.prototype._pdfLoaded = function(source, doc) {
this.scope.$apply(_.bind(function(scope) {
this.doc = doc;
scope.maxPageNumber = doc.numPages;
this.currentPageNumber = -1;
console.log("PDF loaded", doc);
scope.$emit("pdfLoaded", source, doc);
}, this));
};
PDFCanvas.prototype._pdfLoadError = function(source, error, exception) {
var loadErrorMessage;
switch (error) {
case "InvalidPDFException":
loadErrorMessage = translation._("Could not load PDF: Please make sure to select a PDF document.");
break;
case "MissingPDFException":
loadErrorMessage = translation._("'Could not load PDF: Missing PDF file.");
break;
default:
if (error) {
loadErrorMessage = translation._("An error occurred while loading the PDF (%s).", error);
} else {
loadErrorMessage = translation._("An unknown error occurred while loading the PDF.");
}
break;
}
this.scope.$apply(_.bind(function(scope) {
scope.$emit("pdfLoadError", source, loadErrorMessage);
}, this));
};
PDFCanvas.prototype._doOpenFile = function(source) {
pdfjs.getDocument(source).then(_.bind(function(doc) {
this._pdfLoaded(source, doc);
}, this), _.bind(function(error, exception) {
this._pdfLoadError(source, error, exception);
}, this));
};
PDFCanvas.prototype._openFile = function(source) {
this.scope.$emit("pdfLoading", source);
if (pdfjs === null) {
// load pdf.js lazily
require(['pdf'], _.bind(function(pdf) {
pdf.workerSrc = require.toUrl('pdf.worker') + ".js";
console.log("Using pdf.js " + pdf.version + " (build " + pdf.build + ")");
pdfjs = pdf;
this._doOpenFile(source);
}, this));
} else {
this._doOpenFile(source);
}
};
PDFCanvas.prototype._pageLoaded = function(page, pageObject) {
console.log("Got page", pageObject);
this.scope.$emit("pdfPageLoaded", page, pageObject);
this.currentPage = pageObject;
this.drawPage(pageObject);
};
PDFCanvas.prototype._pageLoadError = function(page, error, exception) {
console.error("Could not load page", page, error, exception);
var loadErrorMessage;
if (error) {
loadErrorMessage = translation._("An error occurred while loading the PDF page (%s).", error);
} else {
loadErrorMessage = translation._("An unknown error occurred while loading the PDF page.");
}
this.scope.$emit("pdfPageLoadError", page, loadErrorMessage);
};
PDFCanvas.prototype._showPage = function(page) {
if (page === this.currentPageNumber) {
return;
}
console.log("Showing page", page, "/", this.scope.maxPageNumber);
if (this.currentPage) {
this.currentPage.destroy();
this.currentPage = null;
}
this.currentPageNumber = page;
this.scope.$emit("pdfPageLoading", page);
this.doc.getPage(page).then(_.bind(function(pageObject) {
this._pageLoaded(page, pageObject);
}, this), _.bind(function(error, exception) {
this._pageLoadError(page, error, exception);
}, this));
};
PDFCanvas.prototype._pageRendered = function(pageObject) {
this.renderTask = null;
this.scope.$apply(_.bind(function(scope) {
console.log("Rendered page", pageObject.pageNumber);
this.scope.$emit("pdfPageRendered", pageObject.pageNumber, scope.maxPageNumber);
// ...and flip the buffers...
scope.canvasIndex = 1 - scope.canvasIndex;
this.showQueuedPage();
}, this));
};
PDFCanvas.prototype._pageRenderError = function(pageObject, error, exception) {
if (error === "cancelled") {
return;
}
console.error("Could not render page", pageObject, error, exception);
this.renderTask = null;
var loadErrorMessage;
if (error) {
loadErrorMessage = translation._("An error occurred while rendering the PDF page (%s).", error);
} else {
loadErrorMessage = translation._("An unknown error occurred while rendering the PDF page.");
}
this.scope.$apply(_.bind(function(scope) {
this.scope.$emit("pdfPageRenderError", pageObject.pageNumber, scope.maxPageNumber, loadErrorMessage);
}, this));
};
PDFCanvas.prototype._stopRendering = function() {
if (this.renderTask) {
if (this.renderTask.internalRenderTask && this.renderTask.internalRenderTask.cancel) {
this.renderTask.internalRenderTask.cancel();
}
this.renderTask = null;
}
}
PDFCanvas.prototype.drawPage = function(pageObject) {
var pdfView = pageObject.view;
var pdfWidth = pdfView[2] - pdfView[0];
var pdfHeight = pdfView[3] - pdfView[1];
var w = container.width();
var h = container.height();
var scale = w / pdfWidth;
if (pdfHeight * scale > h) {
scale = container.height() / pdfHeight;
}
// use double-buffering to avoid flickering while
// the new page is rendered...
var canvas = this.canvases[1 - this.scope.canvasIndex];
var viewport = pageObject.getViewport(scale);
canvas.width = Math.round(viewport.width);
canvas.height = Math.round(viewport.height);
var renderContext = {
canvasContext: canvas.getContext("2d"),
viewport: viewport
};
console.log("Rendering page", pageObject);
this.scope.$emit("pdfPageRendering", pageObject.pageNumber);
// TODO(fancycode): also render images in different resolutions for subscribed peers and send to them when ready
this._stopRendering();
var renderTask = pageObject.render(renderContext);
this.renderTask = renderTask;
renderTask.promise.then(_.bind(function() {
this._pageRendered(pageObject);
}, this), _.bind(function(error, exception) {
this._pageRenderError(pageObject, error, exception);
}, this));
};
PDFCanvas.prototype.redrawPage = function() {
if (this.currentPage !== null) {
this.drawPage(this.currentPage);
}
};
PDFCanvas.prototype.showPage = function(page) {
if (page >= 1 && page <= this.scope.maxPageNumber) {
if (!this.doc) {
this.pendingPageNumber = page;
} else {
this._showPage(page);
}
}
};
PDFCanvas.prototype.prevPage = function() {
this.showPage(this.currentPageNumber - 1);
};
PDFCanvas.prototype.nextPage = function() {
this.showPage(this.currentPageNumber + 1);
};
PDFCanvas.prototype.showQueuedPage = function() {
if (this.pendingPageNumber !== null) {
this._showPage(this.pendingPageNumber);
this.pendingPageNumber = null;
}
};
$scope.maxPageNumber = -1;
$scope.canvasIndex = 0;
var canvases = container.find("canvas");
var pdfCanvas = new PDFCanvas($scope, canvases);
$scope.$on("openPdf", function(event, source) {
pdfCanvas.open(source);
});
$scope.$on("closePdf", function() {
pdfCanvas.close();
});
$scope.$on("$destroy", function() {
pdfCanvas.close();
pdfCanvas = null;
});
$scope.$on("showPdfPage", function(event, page) {
pdfCanvas.showPage(page);
});
$scope.$on("showQueuedPdfPage", function() {
pdfCanvas.showQueuedPage();
});
$scope.$on("redrawPdf", function() {
pdfCanvas.redrawPage();
});
$scope.$on("prevPage", function() {
pdfCanvas.prevPage();
});
$scope.$on("nextPage", function() {
pdfCanvas.nextPage();
});
$scope.prevPage = function() {
$scope.$emit("prevPage");
};
$scope.nextPage = function() {
$scope.$emit("nextPage");
};
}];
return {
restrict: 'E',
replace: true,
template: '<div class="canvasContainer"><canvas ng-hide="canvasIndex"></canvas><canvas ng-show="canvasIndex"></canvas></div>',
controller: controller
};
}];
});

444
static/js/directives/presentation.js

@ -0,0 +1,444 @@
/*
* Spreed WebRTC.
* Copyright (C) 2013-2014 struktur AG
*
* This file is part of Spreed WebRTC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
define(['jquery', 'underscore', 'text!partials/presentation.html'], function($, _, template) {
return ["$window", "mediaStream", "fileUpload", "fileDownload", "alertify", "translation", "randomGen", function($window, mediaStream, fileUpload, fileDownload, alertify, translation, randomGen) {
var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
var presentationsCount = 0;
var pane = $element.find(".presentationpane");
var downloadProgressBar = $element.find(".progress-bar")[0];
$scope.layout.presentation = false;
$scope.isPresenter = false;
$scope.hideControlsBar = true;
$scope.pendingPageRequest = null;
$scope.presentationLoaded = false;
$scope.currentFileInfo = null;
$scope.currentPage = null;
$scope.receivedPage = null;
$scope.downloading = false;
$scope.downloadSize = 0;
$scope.downloadProgress = 0;
$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.downloading = false;
$scope.hideControlsBar = !$scope.isPresenter;
$scope.currentPageNumber = -1;
if ($scope.isPresenter) {
$scope.$emit("showPdfPage", 1);
} else if ($scope.pendingPageRequest !== null) {
$scope.$emit("showPdfPage", $scope.pendingPageRequest);
$scope.pendingPageRequest = null;
} else {
$scope.$emit("showQueuedPdfPage");
}
$scope.presentationLoaded = true;
});
$scope.$on("pdfLoadError", function(event, source, errorMessage, moreInfo) {
$scope.downloading = false;
alertify.dialog.alert(errorMessage);
});
$scope.$watch("currentPageNumber", function(newval, oldval) {
$scope.$emit("showPdfPage", newval);
});
var downloadScope = $scope.$new();
downloadScope.$on("downloadedChunk", function(event, idx, byteLength, downloaded, total) {
var percentage = Math.ceil((downloaded / total) * 100);
$scope.downloadProgress = percentage;
downloadProgressBar.style.width = percentage + '%';
});
downloadScope.$on("downloadComplete", function(event) {
event.stopPropagation();
$scope.downloadProgress = 100;
downloadProgressBar.style.width = '100%';
finishDownloadPresentation();
});
downloadScope.$on("writeComplete", function(event, url, fileInfo) {
event.stopPropagation();
if (url.indexOf("blob:") === 0) {
$scope.$emit("openPdf", url);
} else {
fileInfo.file.file(function(fp) {
$scope.$emit("openPdf", fp);
});
}
});
var finishDownloadPresentation = function() {
if (downloadScope.info) {
mediaStream.tokens.off(downloadScope.info.id, downloadScope.handler);
downloadScope.info = null;
downloadScope.handler = null;
}
};
var downloadPresentation = function(fileInfo, from) {
finishDownloadPresentation();
var token = fileInfo.id;
$scope.presentationLoaded = false;
$scope.pendingPageRequest = null;
downloadProgressBar.style.width = '0%';
$scope.downloadProgress = 0;
$scope.downloadSize = fileInfo.size;
$scope.downloading = true;
downloadScope.info = fileInfo;
downloadScope.handler = mediaStream.tokens.on(token, function(event, currenttoken, to, data, type, to2, from, xfer) {
//console.log("Presentation token request", currenttoken, data, type);
fileDownload.handleRequest($scope, xfer, data);
}, "xfer");
fileDownload.startDownload(downloadScope, from, token);
};
var uploadScope = $scope.$new();
var finishUploadPresentation = function() {
if (uploadScope.info) {
uploadScope.$emit("cancelUpload");
mediaStream.tokens.off(uploadScope.info.id, uploadScope.handler);
uploadScope.info = null;
uploadScope.handler = null;
}
};
var uploadPresentation = function(fileInfo) {
finishUploadPresentation();
var token = fileInfo.id;
uploadScope.info = fileInfo;
var session = fileUpload.startUpload(uploadScope, token);
// This binds the token to transfer and ui.
uploadScope.handler = mediaStream.tokens.on(token, function(event, currenttoken, to, data, type, to2, from, xfer) {
//console.log("Presentation token request", currenttoken, data, type);
session.handleRequest(uploadScope, xfer, data);
}, "xfer");
};
mediaStream.api.e.on("received.presentation", function(event, id, from, data, p2p) {
if (!p2p) {
console.warn("Received presentation info without p2p. This should not happen!");
return;
}
if (data.Type) {
switch (data.Type) {
case "FileInfo":
console.log("Received presentation file request", data);
$scope.$apply(function(scope) {
scope.resetProperties();
downloadPresentation(data.FileInfo, from);
});
break;
case "Show":
console.log("Received presentation show request", data);
$scope.$apply(function(scope) {
if (!scope.layout.presentation) {
scope.resetProperties();
scope.layout.presentation = true;
}
});
break;
case "Hide":
console.log("Received presentation hide request", data);
$scope.$apply(function(scope) {
scope.layout.presentation = false;
});
break;
case "Page":
$scope.$apply(function(scope) {
scope.receivedPage = data.Page;
if (!scope.presentationLoaded) {
console.log("Queuing presentation page request, not loaded yet", data);
scope.pendingPageRequest = data.Page;
} else {
console.log("Received presentation page request", data);
scope.$emit("showPdfPage", data.Page);
}
});
break;
default:
console.log("Received unknown presentation event", data);
}
}
});
var peers = {};
var presentations = [];
var currentToken = null;
var tokenHandler = null;
var mediaStreamSendPresentation = function(peercall, token, params) {
mediaStream.api.apply("sendPresentation", {
send: function(type, data) {
if (!peercall.peerconnection.datachannelReady) {
return peercall.e.one("dataReady", function() {
peercall.peerconnection.send(data);
});
} else {
return peercall.peerconnection.send(data);
}
}
})(peercall.id, token, params);
};
var connector = function(token, peercall) {
console.log("XXX connector", token, peercall, peers);
if (peers.hasOwnProperty(peercall.id)) {
// Already got a connection.
return;
}
peers[peercall.id] = true;
mediaStreamSendPresentation(peercall, token, {
Type: "Show",
Show: true
});
if ($scope.currentFileInfo !== null) {
mediaStreamSendPresentation(peercall, token, {
Type: "FileInfo",
FileInfo: $scope.currentFileInfo
});
}
if ($scope.currentPage !== null) {
mediaStreamSendPresentation(peercall, token, {
Type: "Page",
Page: $scope.currentPage
});
}
};
// Updater function to bring in new calls.
var updater = function(event, state, currentcall) {
console.log("XXX updater", event, state, currentcall);
switch (state) {
case "completed":
case "connected":
connector(currentToken, currentcall);
break;
case "closed":
delete peers[currentcall.id];
if (_.isEmpty(peers)) {
console.log("All peers disconnected, stopping presentation");
$scope.$apply(function(scope) {
scope.hidePresentation();
});
}
break;
}
};
$scope.$on("pdfPageLoading", function(event, page) {
$scope.currentPageNumber = 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) {
mediaStreamSendPresentation(peercall, currentToken, {
Type: "Page",
Page: page
});
});
});
$scope.$on("pdfPageLoadError", function(event, page, errorMessage) {
alertify.dialog.alert(errorMessage);
});
$scope.$on("pdfPageRenderError", function(event, pageNumber, maxPageNumber, errorMessage) {
alertify.dialog.alert(errorMessage);
});
$scope.startPresentingFile = function(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
mediaStream.webrtc.callForEachCall(function(peercall) {
mediaStreamSendPresentation(peercall, currentToken, {
Type: "FileInfo",
FileInfo: fileInfo
});
});
uploadPresentation(fileInfo);
$scope.isPresenter = true;
$scope.currentFileInfo = fileInfo;
$scope.receivedPage = null;
$scope.$emit("openPdf", file);
};
var filesSelected = function(files) {
if (files.length > 1) {
alertify.dialog.alert(translation._("Only single PDF documents can be shared at this time."));
return;
}
_.each(files, function(f) {
var info = $.extend({
id: f.id
}, f.info);
if (info.type !== "application/pdf") {
console.log("Not sharing file", f, info);
alertify.dialog.alert(translation._("Only PDF documents can be shared at this time."));
return;
}
$scope.startPresentingFile(f, info);
});
};
// create drag-drop target
var namespace = "file_" + $scope.id;
var binder = fileUpload.bindDrop(namespace, $element, function(files) {
console.log("Files dragged", files);
filesSelected(files);
});
binder.namespace = function() {
// Inject own id into namespace.
return namespace + "_" + $scope.myid;
};
var clickBinder = fileUpload.bindClick(namespace, $element.find('.welcome button')[0], function(files) {
console.log("Files selected", files);
filesSelected(files);
});
clickBinder.namespace = function() {
// Inject own id into namespace.
return namespace + "_" + $scope.myid;
};
$scope.showPresentation = function() {
console.log("Presentation active");
$scope.layout.presentation = true;
$scope.$emit("mainview", "presentation", true);
if (currentToken) {
mediaStream.tokens.off(currentToken, tokenHandler);
}
// Create token to register with us and send token out to all peers.
// Peers when connect to us with the token and we answer.
currentToken = "presentation_" + $scope.id + "_" + (presentationsCount++);
// Create callbacks are called for each incoming connections.
tokenHandler = mediaStream.tokens.create(currentToken, function(event, currenttoken, to, data, type, to2, from, peerpresentation) {
console.log("Presentation create", currenttoken, data, type, peerpresentation);
presentations.push(peerpresentation);
//usermedia.addToPeerConnection(peerscreenshare.peerconnection);
}, "presentation");
// Connect all current calls.
mediaStream.webrtc.callForEachCall(function(peercall) {
connector(currentToken, peercall);
});
// Catch later calls too.
mediaStream.webrtc.e.on("statechange", updater);
};
$scope.hidePresentation = function() {
console.log("Presentation disabled");
if (currentToken) {
mediaStream.webrtc.callForEachCall(function(peercall) {
mediaStreamSendPresentation(peercall, currentToken, {
Type: "Hide",
Hide: true
});
});
mediaStream.tokens.off(currentToken, tokenHandler);
currentToken = null;
}
$scope.$emit("closePdf");
finishUploadPresentation();
finishDownloadPresentation();
$scope.resetProperties();
$scope.layout.presentation = false;
peers = {};
$scope.$emit("mainview", "presentation", false);
mediaStream.webrtc.e.off("statechange", updater);
};
$(document).on("keyup", function(event) {
if (!$scope.layout.presentation) {
return;
}
if ($(event.target).is("input,textarea,select")) {
return;
}
$scope.$apply(function() {
switch (event.keyCode) {
case 37:
// left arrow
$scope.$emit("prevPage");
event.preventDefault();
break;
case 39:
// right arrow
case 32:
// space
$scope.$emit("nextPage");
event.preventDefault();
break;
}
});
});
$scope.$watch("layout.presentation", function(newval, oldval) {
if (newval && !oldval) {
$scope.showPresentation();
} else if (!newval && oldval) {
$scope.hidePresentation();
}
});
$($window).on("resize", function() {
$scope.$emit("redrawPdf");
});
}];
return {
restrict: 'E',
replace: true,
scope: true,
template: template,
controller: controller
};
}];
});

559
static/js/libs/pdf/compatibility.js

@ -0,0 +1,559 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* Copyright 2012 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals VBArray, PDFJS */
'use strict';
// Initializing PDFJS global object here, it case if we need to change/disable
// some PDF.js features, e.g. range requests
if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
// Checking if the typed arrays are supported
// Support: iOS<6.0 (subarray), IE<10, Android<4.0
(function checkTypedArrayCompatibility() {
if (typeof Uint8Array !== 'undefined') {
// Support: iOS<6.0
if (typeof Uint8Array.prototype.subarray === 'undefined') {
Uint8Array.prototype.subarray = function subarray(start, end) {
return new Uint8Array(this.slice(start, end));
};
Float32Array.prototype.subarray = function subarray(start, end) {
return new Float32Array(this.slice(start, end));
};
}
// Support: Android<4.1
if (typeof Float64Array === 'undefined') {
window.Float64Array = Float32Array;
}
return;
}
function subarray(start, end) {
return new TypedArray(this.slice(start, end));
}
function setArrayOffset(array, offset) {
if (arguments.length < 2) {
offset = 0;
}
for (var i = 0, n = array.length; i < n; ++i, ++offset) {
this[offset] = array[i] & 0xFF;
}
}
function TypedArray(arg1) {
var result, i, n;
if (typeof arg1 === 'number') {
result = [];
for (i = 0; i < arg1; ++i) {
result[i] = 0;
}
} else if ('slice' in arg1) {
result = arg1.slice(0);
} else {
result = [];
for (i = 0, n = arg1.length; i < n; ++i) {
result[i] = arg1[i];
}
}
result.subarray = subarray;
result.buffer = result;
result.byteLength = result.length;
result.set = setArrayOffset;
if (typeof arg1 === 'object' && arg1.buffer) {
result.buffer = arg1.buffer;
}
return result;
}
window.Uint8Array = TypedArray;
window.Int8Array = TypedArray;
// we don't need support for set, byteLength for 32-bit array
// so we can use the TypedArray as well
window.Uint32Array = TypedArray;
window.Int32Array = TypedArray;
window.Uint16Array = TypedArray;
window.Float32Array = TypedArray;
window.Float64Array = TypedArray;
})();
// URL = URL || webkitURL
// Support: Safari<7, Android 4.2+
(function normalizeURLObject() {
if (!window.URL) {
window.URL = window.webkitURL;
}
})();
// Object.defineProperty()?
// Support: Android<4.0, Safari<5.1
(function checkObjectDefinePropertyCompatibility() {
if (typeof Object.defineProperty !== 'undefined') {
var definePropertyPossible = true;
try {
// some browsers (e.g. safari) cannot use defineProperty() on DOM objects
// and thus the native version is not sufficient
Object.defineProperty(new Image(), 'id', { value: 'test' });
// ... another test for android gb browser for non-DOM objects
var Test = function Test() {};
Test.prototype = { get id() { } };
Object.defineProperty(new Test(), 'id',
{ value: '', configurable: true, enumerable: true, writable: false });
} catch (e) {
definePropertyPossible = false;
}
if (definePropertyPossible) {
return;
}
}
Object.defineProperty = function objectDefineProperty(obj, name, def) {
delete obj[name];
if ('get' in def) {
obj.__defineGetter__(name, def['get']);
}
if ('set' in def) {
obj.__defineSetter__(name, def['set']);
}
if ('value' in def) {
obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
this.__defineGetter__(name, function objectDefinePropertyGetter() {
return value;
});
return value;
});
obj[name] = def.value;
}
};
})();
// No XMLHttpRequest#response?
// Support: IE<11, Android <4.0
(function checkXMLHttpRequestResponseCompatibility() {
var xhrPrototype = XMLHttpRequest.prototype;
var xhr = new XMLHttpRequest();
if (!('overrideMimeType' in xhr)) {
// IE10 might have response, but not overrideMimeType
// Support: IE10
Object.defineProperty(xhrPrototype, 'overrideMimeType', {
value: function xmlHttpRequestOverrideMimeType(mimeType) {}
});
}
if ('responseType' in xhr) {
return;
}
// The worker will be using XHR, so we can save time and disable worker.
PDFJS.disableWorker = true;
// Support: IE9
if (typeof VBArray !== 'undefined') {
Object.defineProperty(xhrPrototype, 'response', {
get: function xmlHttpRequestResponseGet() {
return new Uint8Array(new VBArray(this.responseBody).toArray());
}
});
return;
}
// other browsers
function responseTypeSetter() {
// will be only called to set "arraybuffer"
this.overrideMimeType('text/plain; charset=x-user-defined');
}
if (typeof xhr.overrideMimeType === 'function') {
Object.defineProperty(xhrPrototype, 'responseType',
{ set: responseTypeSetter });
}
function responseGetter() {
var text = this.responseText;
var i, n = text.length;
var result = new Uint8Array(n);
for (i = 0; i < n; ++i) {
result[i] = text.charCodeAt(i) & 0xFF;
}
return result.buffer;
}
Object.defineProperty(xhrPrototype, 'response', { get: responseGetter });
})();
// window.btoa (base64 encode function) ?
// Support: IE<10
(function checkWindowBtoaCompatibility() {
if ('btoa' in window) {
return;
}
var digits =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
window.btoa = function windowBtoa(chars) {
var buffer = '';
var i, n;
for (i = 0, n = chars.length; i < n; i += 3) {
var b1 = chars.charCodeAt(i) & 0xFF;
var b2 = chars.charCodeAt(i + 1) & 0xFF;
var b3 = chars.charCodeAt(i + 2) & 0xFF;
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
var d4 = i + 2 < n ? (b3 & 0x3F) : 64;
buffer += (digits.charAt(d1) + digits.charAt(d2) +
digits.charAt(d3) + digits.charAt(d4));
}
return buffer;
};
})();
// window.atob (base64 encode function)?
// Support: IE<10
(function checkWindowAtobCompatibility() {
if ('atob' in window) {
return;
}
// https://github.com/davidchambers/Base64.js
var digits =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
window.atob = function (input) {
input = input.replace(/=+$/, '');
if (input.length % 4 == 1) {
throw new Error('bad atob input');
}
for (
// initialize result and counters
var bc = 0, bs, buffer, idx = 0, output = '';
// get next character
buffer = input.charAt(idx++);
// character found in table?
// initialize bit storage and add its ascii value
~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
// and if not first of each 4 characters,
// convert the first 8 bits to one ascii character
bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
) {
// try to find character in table (0-63, not found => -1)
buffer = digits.indexOf(buffer);
}
return output;
};
})();
// Function.prototype.bind?
// Support: Android<4.0, iOS<6.0
(function checkFunctionPrototypeBindCompatibility() {
if (typeof Function.prototype.bind !== 'undefined') {
return;
}
Function.prototype.bind = function functionPrototypeBind(obj) {
var fn = this, headArgs = Array.prototype.slice.call(arguments, 1);
var bound = function functionPrototypeBindBound() {
var args = headArgs.concat(Array.prototype.slice.call(arguments));
return fn.apply(obj, args);
};
return bound;
};
})();
// HTMLElement dataset property
// Support: IE<11, Safari<5.1, Android<4.0
(function checkDatasetProperty() {
var div = document.createElement('div');
if ('dataset' in div) {
return; // dataset property exists
}
Object.defineProperty(HTMLElement.prototype, 'dataset', {
get: function() {
if (this._dataset) {
return this._dataset;
}
var dataset = {};
for (var j = 0, jj = this.attributes.length; j < jj; j++) {
var attribute = this.attributes[j];
if (attribute.name.substring(0, 5) != 'data-') {
continue;
}
var key = attribute.name.substring(5).replace(/\-([a-z])/g,
function(all, ch) {
return ch.toUpperCase();
});
dataset[key] = attribute.value;
}
Object.defineProperty(this, '_dataset', {
value: dataset,
writable: false,
enumerable: false
});
return dataset;
},
enumerable: true
});
})();
// HTMLElement classList property
// Support: IE<10, Android<4.0, iOS<5.0
(function checkClassListProperty() {
var div = document.createElement('div');
if ('classList' in div) {
return; // classList property exists
}
function changeList(element, itemName, add, remove) {
var s = element.className || '';
var list = s.split(/\s+/g);
if (list[0] === '') {
list.shift();
}
var index = list.indexOf(itemName);
if (index < 0 && add) {
list.push(itemName);
}
if (index >= 0 && remove) {
list.splice(index, 1);
}
element.className = list.join(' ');
return (index >= 0);
}
var classListPrototype = {
add: function(name) {
changeList(this.element, name, true, false);
},
contains: function(name) {
return changeList(this.element, name, false, false);
},
remove: function(name) {
changeList(this.element, name, false, true);
},
toggle: function(name) {
changeList(this.element, name, true, true);
}
};
Object.defineProperty(HTMLElement.prototype, 'classList', {
get: function() {
if (this._classList) {
return this._classList;
}
var classList = Object.create(classListPrototype, {
element: {
value: this,
writable: false,
enumerable: true
}
});
Object.defineProperty(this, '_classList', {
value: classList,
writable: false,
enumerable: false
});
return classList;
},
enumerable: true
});
})();
// Check console compatibility
// In older IE versions the console object is not available
// unless console is open.
// Support: IE<10
(function checkConsoleCompatibility() {
if (!('console' in window)) {
window.console = {
log: function() {},
error: function() {},
warn: function() {}
};
} else if (!('bind' in console.log)) {
// native functions in IE9 might not have bind
console.log = (function(fn) {
return function(msg) { return fn(msg); };
})(console.log);
console.error = (function(fn) {
return function(msg) { return fn(msg); };
})(console.error);
console.warn = (function(fn) {
return function(msg) { return fn(msg); };
})(console.warn);
}
})();
// Check onclick compatibility in Opera
// Support: Opera<15
(function checkOnClickCompatibility() {
// workaround for reported Opera bug DSK-354448:
// onclick fires on disabled buttons with opaque content
function ignoreIfTargetDisabled(event) {
if (isDisabled(event.target)) {
event.stopPropagation();
}
}
function isDisabled(node) {
return node.disabled || (node.parentNode && isDisabled(node.parentNode));
}
if (navigator.userAgent.indexOf('Opera') != -1) {
// use browser detection since we cannot feature-check this bug
document.addEventListener('click', ignoreIfTargetDisabled, true);
}
})();
// Checks if possible to use URL.createObjectURL()
// Support: IE
(function checkOnBlobSupport() {
// sometimes IE loosing the data created with createObjectURL(), see #3977
if (navigator.userAgent.indexOf('Trident') >= 0) {
PDFJS.disableCreateObjectURL = true;
}
})();
// Checks if navigator.language is supported
(function checkNavigatorLanguage() {
if ('language' in navigator &&
/^[a-z]+(-[A-Z]+)?$/.test(navigator.language)) {
return;
}
function formatLocale(locale) {
var split = locale.split(/[-_]/);
split[0] = split[0].toLowerCase();
if (split.length > 1) {
split[1] = split[1].toUpperCase();
}
return split.join('-');
}
var language = navigator.language || navigator.userLanguage || 'en-US';
PDFJS.locale = formatLocale(language);
})();
(function checkRangeRequests() {
// Safari has issues with cached range requests see:
// https://github.com/mozilla/pdf.js/issues/3260
// Last tested with version 6.0.4.
// Support: Safari 6.0+
var isSafari = Object.prototype.toString.call(
window.HTMLElement).indexOf('Constructor') > 0;
// Older versions of Android (pre 3.0) has issues with range requests, see:
// https://github.com/mozilla/pdf.js/issues/3381.
// Make sure that we only match webkit-based Android browsers,
// since Firefox/Fennec works as expected.
// Support: Android<3.0
var regex = /Android\s[0-2][^\d]/;
var isOldAndroid = regex.test(navigator.userAgent);
if (isSafari || isOldAndroid) {
PDFJS.disableRange = true;
}
})();
// Check if the browser supports manipulation of the history.
// Support: IE<10, Android<4.2
(function checkHistoryManipulation() {
// Android 2.x has so buggy pushState support that it was removed in
// Android 3.0 and restored as late as in Android 4.2.
// Support: Android 2.x
if (!history.pushState || navigator.userAgent.indexOf('Android 2.') >= 0) {
PDFJS.disableHistory = true;
}
})();
// Support: IE<11, Chrome<21, Android<4.4
(function checkSetPresenceInImageData() {
// IE < 11 will use window.CanvasPixelArray which lacks set function.
if (window.CanvasPixelArray) {
if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
window.CanvasPixelArray.prototype.set = function(arr) {
for (var i = 0, ii = this.length; i < ii; i++) {
this[i] = arr[i];
}
};
}
} else {
// Old Chrome and Android use an inaccessible CanvasPixelArray prototype.
// Because we cannot feature detect it, we rely on user agent parsing.
var polyfill = false;
if (navigator.userAgent.indexOf('Chrom') >= 0) {
var versionMatch = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
if (versionMatch && parseInt(versionMatch[2]) < 21) {
// Chrome < 21 lacks the set function.
polyfill = true;
}
} else if (navigator.userAgent.indexOf('Android') >= 0) {
// Android < 4.4 lacks the set function.
// Android >= 4.4 will contain Chrome in the user agent,
// thus pass the Chrome check above and not reach this block.
var isOldAndroid = /Android\s[0-4][^\d]/g.test(navigator.userAgent);
if (isOldAndroid) {
polyfill = true;
}
}
if (polyfill) {
var contextPrototype = window.CanvasRenderingContext2D.prototype;
contextPrototype._createImageData = contextPrototype.createImageData;
contextPrototype.createImageData = function(w, h) {
var imageData = this._createImageData(w, h);
imageData.data.set = function(arr) {
for (var i = 0, ii = this.length; i < ii; i++) {
this[i] = arr[i];
}
};
return imageData;
};
}
}
})();
// Support: IE<10, Android<4.0, iOS
(function checkRequestAnimationFrame() {
function fakeRequestAnimationFrame(callback) {
window.setTimeout(callback, 20);
}
var isIOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
if (isIOS) {
// requestAnimationFrame on iOS is broken, replacing with fake one.
window.requestAnimationFrame = fakeRequestAnimationFrame;
return;
}
if ('requestAnimationFrame' in window) {
return;
}
window.requestAnimationFrame =
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
fakeRequestAnimationFrame;
})();
(function checkCanvasSizeLimitation() {
var isIOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
var isAndroid = /Android/g.test(navigator.userAgent);
if (isIOS || isAndroid) {
// 5MP
PDFJS.maxCanvasPixels = 5242880;
}
})();

6533
static/js/libs/pdf/pdf.js

File diff suppressed because it is too large Load Diff

44065
static/js/libs/pdf/pdf.worker.js vendored

File diff suppressed because it is too large Load Diff

7
static/js/main.js

@ -49,6 +49,9 @@ require.config({
'humanize': 'libs/humanize', 'humanize': 'libs/humanize',
'sha': 'libs/sha', 'sha': 'libs/sha',
'sjcl': 'libs/sjcl', 'sjcl': 'libs/sjcl',
'pdf': 'libs/pdf/pdf',
'pdf.worker': 'libs/pdf/pdf.worker',
'pdf.compatibility': 'libs/pdf/compatibility',
'partials': '../partials', 'partials': '../partials',
'sounds': '../sounds', 'sounds': '../sounds',
@ -109,6 +112,10 @@ require.config({
}, },
'sjcl': { 'sjcl': {
exports: 'sjcl' exports: 'sjcl'
},
'pdf': {
deps: ['pdf.compatibility'],
exports: 'PDFJS'
} }
} }
}); });

20
static/js/mediastream/api.js

@ -189,6 +189,9 @@ define(['jquery', 'underscore'], function($, _) {
case "Screenshare": case "Screenshare":
this.e.triggerHandler("received.screenshare", [d.To, d.From, data.Screenshare, d.p2p]); this.e.triggerHandler("received.screenshare", [d.To, d.From, data.Screenshare, d.p2p]);
break; break;
case "Presentation":
this.e.triggerHandler("received.presentation", [d.To, d.From, data.Presentation, d.p2p]);
break;
case "Alive": case "Alive":
// Do nothing. // Do nothing.
//console.log("Alive response received."); //console.log("Alive response received.");
@ -340,6 +343,23 @@ define(['jquery', 'underscore'], function($, _) {
}; };
Api.prototype.sendPresentation = function(id, viewer_id, viewer_data) {
var data = {
Id: id,
Type: "Presentation",
Presentation: {
id: viewer_id
}
}
if (viewer_data) {
data.Presentation = _.extend(data.Presentation, viewer_data);
}
return this.send("Presentation", data);
};
Api.prototype.sendAlive = function(timestamp) { Api.prototype.sendAlive = function(timestamp) {
var data = { var data = {

7
static/js/services/filedownload.js

@ -40,6 +40,8 @@ define(["jquery", "underscore"], function($, _) {
this.end = scope.info.chunks - 1; this.end = scope.info.chunks - 1;
this.fragments = 100; this.fragments = 100;
this.concurrent = 5; this.concurrent = 5;
this.downloadedBytes = 0;
this.totalBytes = scope.info.size;
this.jobs = []; this.jobs = [];
this.xfer_all = []; this.xfer_all = [];
@ -90,7 +92,7 @@ define(["jquery", "underscore"], function($, _) {
safeApply(this.scope, function($scope) { safeApply(this.scope, function($scope) {
var url = file.toURL(); var url = file.toURL();
console.log("Generated URL", url); console.log("Generated URL", url);
$scope.$emit("writeComplete", url); $scope.$emit("writeComplete", url, file);
}); });
}, this)); }, this));
file.e.bind("error writerror failed", _.bind(function(event, e) { file.e.bind("error writerror failed", _.bind(function(event, e) {
@ -212,7 +214,8 @@ define(["jquery", "underscore"], function($, _) {
var byte_position = file.scope.chunk_size * idx; var byte_position = file.scope.chunk_size * idx;
file.setChunk(idx, byte_position, data); file.setChunk(idx, byte_position, data);
safeApply(this.scope, _.bind(function($scope) { safeApply(this.scope, _.bind(function($scope) {
$scope.$emit("downloadedChunk", idx, data.byteLength); this.downloadedBytes += data.byteLength;
$scope.$emit("downloadedChunk", idx, data.byteLength, this.downloadedBytes, this.totalBytes);
job.next(); job.next();
}, this)); }, this));
}, this)); }, this));

25
static/partials/presentation.html

@ -0,0 +1,25 @@
<div class="presentation">
<div class="presentationpane nicescroll">
<div class="welcome container-fluid" ng-show="downloading">
<h1>{{_('Downloading presentation...')}}</h1>
<div class="progress">
<span class="download-info">{{downloadSize|humanizeFilesize}} <span ng-show="downloading">/ {{downloadProgress}}%</span></span>
<div class="progress-bar progress-bar-success"></div>
</div>
</div>
<div class="welcome container-fluid" ng-hide="maxPageNumber !== -1 || downloading">
<h1>{{_('Please drop a PDF document here to present it to the other participants.')}}</h1>
<div class="presentation-target fa fa-file-pdf-o"></div>
<button class="btn btn-lg btn-primary center-block">Upload</button>
</div>
<pdfcanvas ng-hide="maxPageNumber === -1 || downloading" />
</div>
<div class="overlaybar form-horizontal" ng-class="{notvisible: hideControlsBar}">
<a class="overlaybar-button" ng-model="hideControlsBar" btn-checkbox btn-checkbox btn-checkbox-true="0" btn-checkbox-false="1" title="{{_('Presentation controls')}}"><i class="fa fa-cogs"></i></a>
<form class="overlaybar-content form-group" ng-show="maxPageNumber !== -1 && !downloading">
<a class="btn btn-prev" ng-click="prevPage()" ng-show="currentPageNumber &gt; 1" title="{{_('Prev')}}"><i class="fa fa-backward"></i></a>
<span class="pageinfo"><input class="form-control input-sm" type="number" ng-model="currentPageNumber" /> / {{ maxPageNumber }}</span>
<a class="btn btn-next" ng-click="nextPage()" ng-show="currentPageNumber &lt; maxPageNumber" title="{{_('Next')}}"><i class="fa fa-forward"></i></a>
</form>
</div>
</div>
Loading…
Cancel
Save