@@ -244,9 +244,16 @@ module.exports = class DeviceRenderer {
244244 // closure to expose the right video and store context to onclose event
245245 const video = this . video ;
246246 const store = this . store ;
247+ const keyboardPlugin = this . keyboardEvents ;
248+ const mousePlugin = this . mouseEvents ;
249+ const keymappingPlugin = this . keyboardMapping ;
247250
248251 this . webRTCWebsocket . onclose = ( event ) => {
249252 store . dispatch ( { type : 'WEBRTC_CONNECTION_READY' , payload : false } ) ;
253+ // remove callbacks for clean deletion, but do not update the store
254+ keyboardPlugin ?. removeKeyboardCallbacks ( ) ;
255+ mousePlugin ?. removeMouseCallbacks ( ) ;
256+ keymappingPlugin ?. removeKeyboardCallbacks ( ) ;
250257 video . style . background = this . videoBackupStyleBackground ;
251258 this . initialized = false ;
252259 log . debug ( 'Error! Maybe your VM is not available yet? (' + event . code + ') ' + event . reason ) ;
@@ -478,6 +485,17 @@ module.exports = class DeviceRenderer {
478485 this . gamepadManager . addGamepadCallbacks ( ) ;
479486 }
480487
488+ // in case this is a re-start, we want to add the callbacks again depending on the state
489+ if ( this . store . get ( 'KEYBOARD_EVENTS_ENABLED' ) ) {
490+ this . keyboardEvents . addKeyboardCallbacks ( ) ;
491+ }
492+ if ( this . store . get ( 'MOUSE_EVENTS_ENABLED' ) ) {
493+ this . mouseEvents . addMouseCallbacks ( ) ;
494+ }
495+ if ( ! this . store . get ( 'KEYBOARD_EVENTS_ENABLED' ) && ! this . store . get ( 'MOUSE_EVENTS_ENABLED' ) ) {
496+ this . keyboardMapping . addKeyboardCallbacks ( ) ;
497+ }
498+
481499 const playWithSound = this . video . play ( ) ; // needed on Safari (web & iOs)
482500 if ( ! playWithSound ) {
483501 return ;
0 commit comments