summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-04-12 10:49:44 +0100
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2013-04-12 10:50:24 +0100
commit520f4d45e9cd592381af66a8ed357de3e346734b (patch)
tree87fe44e0fa487a931388d278bbd792d2643e0267
parentfd8324adb1e8024a0bb37bf096cf5988be1ead62 (diff)
Image/Notes storage and basic preview.
Change-Id: I466b5e2232811af3fad2266c28e8c4475b77eb71
-rw-r--r--firefoxos/sdremote/index.html9
-rw-r--r--firefoxos/sdremote/js/client.js7
-rw-r--r--firefoxos/sdremote/js/receiver.js46
-rw-r--r--firefoxos/sdremote/js/slideshow.js33
-rw-r--r--firefoxos/sdremote/js/ui.js9
5 files changed, 97 insertions, 7 deletions
diff --git a/firefoxos/sdremote/index.html b/firefoxos/sdremote/index.html
index eaf82f9a81be..4752239a33cc 100644
--- a/firefoxos/sdremote/index.html
+++ b/firefoxos/sdremote/index.html
@@ -20,7 +20,12 @@
var mClient;
var mTransmitter;
</script>
+
+ <script src="js/ui.js"></script>
+
<script src="js/client.js"></script>
+ <script src="js/receiver.js"></script>
+ <script src="js/slideshow.js"></script>
<script src="js/transmitter.js"></script>
</head>
<body onLoad="init();">
@@ -39,8 +44,8 @@
<button id="blank" onclick="mTransmitter.blankScreen()">Blank Screen</button>
<button id="resume" onclick="mTransmitter.resume()">Resume</button>
<br/>
+ <img id="preview"></img>
-
- <p>Current slide: <span id="current slide">---</span></p>
+ <p>Current slide: <span id="current_slide">---</span></p>
</body>
</html>
diff --git a/firefoxos/sdremote/js/client.js b/firefoxos/sdremote/js/client.js
index f9ad71b8b250..77025063ee8b 100644
--- a/firefoxos/sdremote/js/client.js
+++ b/firefoxos/sdremote/js/client.js
@@ -11,6 +11,7 @@ function Client( aServerAddress ) {
var mReceiveBuffer = "";
var mCurrentMessage = [];
var mSocket;
+ var mReceiver = new Receiver();
// PUBLIC
this.sendMessage = function( aMessage ) {
@@ -18,10 +19,6 @@ function Client( aServerAddress ) {
}
// PRIVATE
- function processMessage( aMessage ) {
- console.log( "Received message " + aMessage );
- }
-
function dataReceived( aEvent ) {
mReceiveBuffer += aEvent.data;
var i;
@@ -31,7 +28,7 @@ function Client( aServerAddress ) {
if ( aLine.length > 0 ) {
mCurrentMessage.push( aLine );
} else {
- processMessage( mCurrentMessage );
+ mReceiver.parseMessage( mCurrentMessage );
mCurrentMessage = [];
}
aLine = "";
diff --git a/firefoxos/sdremote/js/receiver.js b/firefoxos/sdremote/js/receiver.js
new file mode 100644
index 000000000000..8cecaa473683
--- /dev/null
+++ b/firefoxos/sdremote/js/receiver.js
@@ -0,0 +1,46 @@
+function Receiver() {
+
+ var mSlideshow;
+
+ this.parseMessage = function( aMessage ) {
+ console.log( "Received message " + aMessage[0] );
+ switch ( aMessage[0] ) {
+ case "slideshow_started":
+ mSlideshow = new Slideshow();
+ var aSlideShowlength = aMessage[1];
+ var aCurrentSlide = aMessage[2];
+ mSlideshow.setLength( aSlideShowlength );
+ mSlideshow.setCurrentSlide( aCurrentSlide );
+ // TODO: notify listeners
+ break;
+ case "slideshow_finished":
+ // TODO: notify listeners
+ mSlideshow = '';
+ break;
+ default:
+ if ( !mSlideshow ) {
+ break;
+ }
+ var mSlide = aMessage[1];
+ // TODO: notify listeners
+ switch ( aMessage[0] ) {
+ case "slide_updated":
+ mSlideshow.setCurrentSlide( mSlide );
+ updatePreview( mSlideshow );
+ case "slide_notes":
+ mSlideshow.putNotes( mSlide, aMessage[2] );
+ break;
+ case "slide_preview":
+ mSlideshow.putPreview( mSlide, aMessage[2] );
+ break;
+ }
+ break;
+ }
+ }
+
+ this.getSlideshow = function() {
+ return mSlideshow;
+ }
+
+
+} \ No newline at end of file
diff --git a/firefoxos/sdremote/js/slideshow.js b/firefoxos/sdremote/js/slideshow.js
new file mode 100644
index 000000000000..0940ab53dba3
--- /dev/null
+++ b/firefoxos/sdremote/js/slideshow.js
@@ -0,0 +1,33 @@
+function Slideshow() {
+
+ var mSlides = 0;
+ var mCurrentSlide;
+
+ var mNotes = [];
+ var mPreviews = [];
+
+ this.setLength = function( aLength ) {
+ mSlides = aLength;
+ }
+
+ this.setCurrentSlide = function( aSlide ) {
+ mCurrentSlide = aSlide;
+ }
+
+ this.getCurrentSlide = function() {
+ return mCurrentSlide;
+ }
+
+ this.putPreview = function( aSlide, aImage ) {
+ mPreviews[ aSlide ] = aImage;
+ }
+
+ this.putNotes = function( aSlide, aNotes ) {
+ mNotes[ aSlide ] = aNotes;
+ }
+
+ this.getPreview = function( aSlide ) {
+ return mPreviews[ aSlide ];
+ }
+
+} \ No newline at end of file
diff --git a/firefoxos/sdremote/js/ui.js b/firefoxos/sdremote/js/ui.js
new file mode 100644
index 000000000000..a8c7d6b746bd
--- /dev/null
+++ b/firefoxos/sdremote/js/ui.js
@@ -0,0 +1,9 @@
+function updatePreview( aSlideshow ) {
+ var aOutputImage = document.getElementById('preview');
+ var aPreview = aSlideshow.getPreview( aSlideshow.getCurrentSlide() );
+
+ aOutputImage.src = "data:image/png;base64," + aPreview;
+ console.log( "Set image : " + aPreview );
+
+ document.getElementById('current_slide').innerHTML = aSlideshow.getCurrentSlide();
+} \ No newline at end of file