-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multiplexing work with socket.io 1.0+ #1281 #1276
- Loading branch information
Showing
3 changed files
with
37 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,31 @@ | ||
(function() { | ||
|
||
// Don't emit events from inside of notes windows | ||
if ( window.location.search.match( /receiver/gi ) ) { return; } | ||
|
||
var multiplex = Reveal.getConfig().multiplex; | ||
|
||
var socket = io.connect(multiplex.url); | ||
|
||
var notify = function( slideElement, indexh, indexv, origin ) { | ||
if( typeof origin === 'undefined' && origin !== 'remote' ) { | ||
var nextindexh; | ||
var nextindexv; | ||
|
||
var fragmentindex = Reveal.getIndices().f; | ||
if (typeof fragmentindex == 'undefined') { | ||
fragmentindex = 0; | ||
} | ||
|
||
if (slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION') { | ||
nextindexh = indexh; | ||
nextindexv = indexv + 1; | ||
} else { | ||
nextindexh = indexh + 1; | ||
nextindexv = 0; | ||
} | ||
|
||
var slideData = { | ||
indexh : indexh, | ||
indexv : indexv, | ||
indexf : fragmentindex, | ||
nextindexh : nextindexh, | ||
nextindexv : nextindexv, | ||
secret: multiplex.secret, | ||
socketId : multiplex.id | ||
}; | ||
|
||
socket.emit('slidechanged', slideData); | ||
} | ||
} | ||
|
||
Reveal.addEventListener( 'slidechanged', function( event ) { | ||
notify( event.currentSlide, event.indexh, event.indexv, event.origin ); | ||
} ); | ||
|
||
var fragmentNotify = function( event ) { | ||
notify( Reveal.getCurrentSlide(), Reveal.getIndices().h, Reveal.getIndices().v, event.origin ); | ||
var socket = io.connect( multiplex.url ); | ||
|
||
function post() { | ||
|
||
var messageData = { | ||
state: Reveal.getState(), | ||
secret: multiplex.secret, | ||
socketId: multiplex.id | ||
}; | ||
|
||
socket.emit( 'multiplex-statechanged', messageData ); | ||
|
||
}; | ||
|
||
Reveal.addEventListener( 'fragmentshown', fragmentNotify ); | ||
Reveal.addEventListener( 'fragmenthidden', fragmentNotify ); | ||
// Monitor events that trigger a change in state | ||
Reveal.addEventListener( 'slidechanged', post ); | ||
Reveal.addEventListener( 'fragmentshown', post ); | ||
Reveal.addEventListener( 'fragmenthidden', post ); | ||
Reveal.addEventListener( 'overviewhidden', post ); | ||
Reveal.addEventListener( 'overviewshown', post ); | ||
Reveal.addEventListener( 'paused', post ); | ||
Reveal.addEventListener( 'resumed', post ); | ||
|
||
}()); |