@@ -19,7 +19,7 @@ export class TalkControlMaster {
1919 querySelectorAllDeep ( 'iframe' ) . forEach ( frame => this . frames . push ( frame ) ) ;
2020 this . focusFrame = this . frames . find ( frame => frame . getAttribute ( 'focus' ) !== null ) || this . frames [ 0 ] ;
2121
22- this . eventBus = new EventBusResolver ( {
22+ this . eventBusMaster = new EventBusResolver ( {
2323 client : true ,
2424 server,
2525 postMessage : {
@@ -50,56 +50,51 @@ export class TalkControlMaster {
5050 */
5151 afterInitialisation ( ) {
5252 // Forward initialization event to server
53- this . eventBus . on ( MASTER_SLAVE_CHANNEL , 'initialized' , data => this . eventBus . emit ( MASTER_SERVER_CHANNEL , 'init' , data ) ) ;
54- // Start listening on keys once the server is initialized
55- this . eventBus . on ( MASTER_SERVER_CHANNEL , 'initialized' , ( ) => this . eventBus . on ( MASTER_SLAVE_CHANNEL , 'keyboardEvent' , this . onKeyboardEvent . bind ( this ) ) ) ;
53+ this . eventBusMaster . on ( MASTER_SLAVE_CHANNEL , 'initialized' , data => this . eventBusMaster . emit ( MASTER_SERVER_CHANNEL , 'init' , data ) ) ;
5654 // Forward "gotoSlide" events to slave
57- this . eventBus . on ( MASTER_SERVER_CHANNEL , 'gotoSlide' , data => this . eventBus . emit ( MASTER_SLAVE_CHANNEL , 'gotoSlide' , data ) ) ;
55+ this . eventBusMaster . on ( MASTER_SERVER_CHANNEL , 'gotoSlide' , data => this . eventBusMaster . emit ( MASTER_SLAVE_CHANNEL , 'gotoSlide' , data ) ) ;
5856 // Forward "showNotes" events to slave
59- this . eventBus . on ( MASTER_SLAVE_CHANNEL , 'sendNotesToMaster' , data => this . eventBus . emit ( MASTER_SLAVE_CHANNEL , 'sendNotesToSlave' , data ) ) ;
57+ this . eventBusMaster . on ( MASTER_SLAVE_CHANNEL , 'sendNotesToMaster' , data => this . eventBusMaster . emit ( MASTER_SLAVE_CHANNEL , 'sendNotesToSlave' , data ) ) ;
58+ // Start listening on "keyboardEvent" on MASTER_SLAVE_CHANNEL
59+ this . eventBusMaster . on ( MASTER_SLAVE_CHANNEL , 'keyboardEvent' , this . onKeyboardEvent . bind ( this ) ) ;
6060 }
6161
6262 onKeyboardEvent ( event ) {
6363 let action = '' ;
6464 switch ( event . key ) {
6565 case 'Down' : // IE specific value
6666 case 'ArrowDown' :
67- // Do something for "down arrow" key press.
6867 action = 'arrowDown' ;
6968 break ;
7069 case 'Up' : // IE specific value
7170 case 'ArrowUp' :
72- // Do something for "up arrow" key press.
7371 action = 'arrowUp' ;
7472 break ;
7573 case 'Left' : // IE specific value
7674 case 'ArrowLeft' :
77- // Do something for "left arrow" key press.
7875 action = 'arrowLeft' ;
7976 break ;
8077 case 'Right' : // IE specific value
8178 case 'ArrowRight' :
82- // Do something for "right arrow" key press.
8379 action = 'arrowRight' ;
8480 break ;
8581 case ' ' :
86- // Do something for "space" key press
8782 action = 'space' ;
8883 break ;
8984 }
9085 if ( action ) {
91- this . eventBus . emit ( MASTER_SERVER_CHANNEL , 'keyboardEvent' , { key : action } ) ;
86+ this . eventBusMaster . emit ( MASTER_SERVER_CHANNEL , 'keyboardEvent' , { key : action } ) ;
9287 }
9388 }
9489
9590 forwardEvents ( ) {
96- const forward = ( key => data => this . eventBus . emit ( MASTER_SLAVE_CHANNEL , key , data ) ) . bind ( this ) ;
97- this . eventBus . on ( MASTER_SERVER_CHANNEL , 'slideNumber' , forward ( 'slideNumber' ) ) ;
98- this . eventBus . on ( MASTER_SERVER_CHANNEL , 'currentSlide' , forward ( 'currentSlide' ) ) ;
91+ const forward = ( key => data => this . eventBusMaster . emit ( MASTER_SLAVE_CHANNEL , key , data ) ) . bind ( this ) ;
92+ this . eventBusMaster . on ( MASTER_SERVER_CHANNEL , 'slideNumber' , forward ( 'slideNumber' ) ) ;
93+ this . eventBusMaster . on ( MASTER_SERVER_CHANNEL , 'currentSlide' , forward ( 'currentSlide' ) ) ;
9994 }
10095
10196 onFramesLoaded ( ) {
102- this . eventBus . emit ( MASTER_SLAVE_CHANNEL , 'init' ) ;
97+ this . eventBusMaster . emit ( MASTER_SLAVE_CHANNEL , 'init' ) ;
10398 this . focusFrame . focus ( ) ;
10499 document . addEventListener ( 'click' , ( ) => this . focusFrame . focus ( ) ) ;
105100 }
0 commit comments