speaker notes work with socket.io 1.0 #1375
parent
5117048a5b
commit
b16bc6fc2e
|
@ -41,7 +41,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a new notes window connects, post our current state
|
// When a new notes window connects, post our current state
|
||||||
socket.on( 'connect', function( data ) {
|
socket.on( 'new-subscriber', function( data ) {
|
||||||
post();
|
post();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
|
var http = require('http');
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var io = require('socket.io');
|
var io = require('socket.io');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var Mustache = require('mustache');
|
var Mustache = require('mustache');
|
||||||
|
|
||||||
var app = express.createServer();
|
var app = express();
|
||||||
var staticDir = express.static;
|
var staticDir = express.static;
|
||||||
|
var server = http.createServer(app);
|
||||||
|
|
||||||
io = io.listen(app);
|
io = io(server);
|
||||||
|
|
||||||
var opts = {
|
var opts = {
|
||||||
port : 1947,
|
port : 1947,
|
||||||
baseDir : __dirname + '/../../'
|
baseDir : __dirname + '/../../'
|
||||||
};
|
};
|
||||||
|
|
||||||
io.sockets.on( 'connection', function( socket ) {
|
io.on( 'connection', function( socket ) {
|
||||||
|
|
||||||
socket.on( 'connect', function( data ) {
|
socket.on( 'new-subscriber', function( data ) {
|
||||||
socket.broadcast.emit( 'connect', data );
|
socket.broadcast.emit( 'new-subscriber', data );
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on( 'statechanged', function( data ) {
|
socket.on( 'statechanged', function( data ) {
|
||||||
|
@ -26,14 +28,10 @@ io.sockets.on( 'connection', function( socket ) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.configure( function() {
|
|
||||||
|
|
||||||
[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
|
[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
|
||||||
app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
|
app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/', function( req, res ) {
|
app.get('/', function( req, res ) {
|
||||||
|
|
||||||
res.writeHead( 200, { 'Content-Type': 'text/html' } );
|
res.writeHead( 200, { 'Content-Type': 'text/html' } );
|
||||||
|
@ -52,7 +50,7 @@ app.get( '/notes/:socketId', function( req, res ) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Actually listen
|
// Actually listen
|
||||||
app.listen( opts.port || null );
|
server.listen( opts.port || null );
|
||||||
|
|
||||||
var brown = '\033[33m',
|
var brown = '\033[33m',
|
||||||
green = '\033[32m',
|
green = '\033[32m',
|
||||||
|
|
|
@ -195,7 +195,6 @@
|
||||||
if( connected === false ) {
|
if( connected === false ) {
|
||||||
connected = true;
|
connected = true;
|
||||||
|
|
||||||
setupIframes( data );
|
|
||||||
setupKeyboard();
|
setupKeyboard();
|
||||||
setupNotes();
|
setupNotes();
|
||||||
setupTimer();
|
setupTimer();
|
||||||
|
@ -206,13 +205,19 @@
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// Load our presentation iframes
|
||||||
|
setupIframes();
|
||||||
|
|
||||||
|
// Once the iframes have loaded, emit a signal saying there's
|
||||||
|
// a new subscriber which will trigger a 'statechanged'
|
||||||
|
// message to be sent back
|
||||||
window.addEventListener( 'message', function( event ) {
|
window.addEventListener( 'message', function( event ) {
|
||||||
|
|
||||||
var data = JSON.parse( event.data );
|
var data = JSON.parse( event.data );
|
||||||
|
|
||||||
if( data && data.namespace === 'reveal' ) {
|
if( data && data.namespace === 'reveal' ) {
|
||||||
if( /ready/.test( data.eventName ) ) {
|
if( /ready/.test( data.eventName ) ) {
|
||||||
socket.emit( 'connect', { socketId: socketId } );
|
socket.emit( 'new-subscriber', { socketId: socketId } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +272,7 @@
|
||||||
/**
|
/**
|
||||||
* Creates the preview iframes.
|
* Creates the preview iframes.
|
||||||
*/
|
*/
|
||||||
function setupIframes( data ) {
|
function setupIframes() {
|
||||||
|
|
||||||
var params = [
|
var params = [
|
||||||
'receiver',
|
'receiver',
|
||||||
|
@ -277,9 +282,8 @@
|
||||||
'backgroundTransition=none'
|
'backgroundTransition=none'
|
||||||
].join( '&' );
|
].join( '&' );
|
||||||
|
|
||||||
var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
|
var currentURL = '/?' + params + '&postMessageEvents=true';
|
||||||
var currentURL = '/?' + params + '&postMessageEvents=true' + hash;
|
var upcomingURL = '/?' + params + '&controls=false';
|
||||||
var upcomingURL = '/?' + params + '&controls=false' + hash;
|
|
||||||
|
|
||||||
currentSlide = document.createElement( 'iframe' );
|
currentSlide = document.createElement( 'iframe' );
|
||||||
currentSlide.setAttribute( 'width', 1280 );
|
currentSlide.setAttribute( 'width', 1280 );
|
||||||
|
|
Loading…
Reference in New Issue