aboutsummaryrefslogtreecommitdiff
path: root/plugin/multiplex/master.js
blob: deb39cd88f6446e2440bca1ce4e5fcd8804f6d2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(function() {
	// don't emit events from inside the previews themselves
	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 );
	};

	Reveal.addEventListener( 'fragmentshown', fragmentNotify );
	Reveal.addEventListener( 'fragmenthidden', fragmentNotify );
}());