Skip to content

Commit b16bc6f

Browse files
committed
speaker notes work with socket.io 1.0 hakimel#1375
1 parent 5117048 commit b16bc6f

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

plugin/notes-server/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
}
4242

4343
// When a new notes window connects, post our current state
44-
socket.on( 'connect', function( data ) {
44+
socket.on( 'new-subscriber', function( data ) {
4545
post();
4646
} );
4747

plugin/notes-server/index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
var http = require('http');
12
var express = require('express');
23
var fs = require('fs');
34
var io = require('socket.io');
45
var _ = require('underscore');
56
var Mustache = require('mustache');
67

7-
var app = express.createServer();
8+
var app = express();
89
var staticDir = express.static;
10+
var server = http.createServer(app);
911

10-
io = io.listen(app);
12+
io = io(server);
1113

1214
var opts = {
1315
port : 1947,
1416
baseDir : __dirname + '/../../'
1517
};
1618

17-
io.sockets.on( 'connection', function( socket ) {
19+
io.on( 'connection', function( socket ) {
1820

19-
socket.on( 'connect', function( data ) {
20-
socket.broadcast.emit( 'connect', data );
21+
socket.on( 'new-subscriber', function( data ) {
22+
socket.broadcast.emit( 'new-subscriber', data );
2123
});
2224

2325
socket.on( 'statechanged', function( data ) {
@@ -26,12 +28,8 @@ io.sockets.on( 'connection', function( socket ) {
2628

2729
});
2830

29-
app.configure( function() {
30-
31-
[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
32-
app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
33-
});
34-
31+
[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
32+
app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
3533
});
3634

3735
app.get('/', function( req, res ) {
@@ -52,7 +50,7 @@ app.get( '/notes/:socketId', function( req, res ) {
5250
});
5351

5452
// Actually listen
55-
app.listen( opts.port || null );
53+
server.listen( opts.port || null );
5654

5755
var brown = '\033[33m',
5856
green = '\033[32m',

plugin/notes-server/notes.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ <h4 class="label">Notes</h4>
195195
if( connected === false ) {
196196
connected = true;
197197

198-
setupIframes( data );
199198
setupKeyboard();
200199
setupNotes();
201200
setupTimer();
@@ -206,13 +205,19 @@ <h4 class="label">Notes</h4>
206205

207206
} );
208207

208+
// Load our presentation iframes
209+
setupIframes();
210+
211+
// Once the iframes have loaded, emit a signal saying there's
212+
// a new subscriber which will trigger a 'statechanged'
213+
// message to be sent back
209214
window.addEventListener( 'message', function( event ) {
210215

211216
var data = JSON.parse( event.data );
212217

213218
if( data && data.namespace === 'reveal' ) {
214219
if( /ready/.test( data.eventName ) ) {
215-
socket.emit( 'connect', { socketId: socketId } );
220+
socket.emit( 'new-subscriber', { socketId: socketId } );
216221
}
217222
}
218223

@@ -267,7 +272,7 @@ <h4 class="label">Notes</h4>
267272
/**
268273
* Creates the preview iframes.
269274
*/
270-
function setupIframes( data ) {
275+
function setupIframes() {
271276

272277
var params = [
273278
'receiver',
@@ -277,9 +282,8 @@ <h4 class="label">Notes</h4>
277282
'backgroundTransition=none'
278283
].join( '&' );
279284

280-
var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
281-
var currentURL = '/?' + params + '&postMessageEvents=true' + hash;
282-
var upcomingURL = '/?' + params + '&controls=false' + hash;
285+
var currentURL = '/?' + params + '&postMessageEvents=true';
286+
var upcomingURL = '/?' + params + '&controls=false';
283287

284288
currentSlide = document.createElement( 'iframe' );
285289
currentSlide.setAttribute( 'width', 1280 );

0 commit comments

Comments
 (0)