Skip to content

Commit

Permalink
Merge pull request #90 from Genymobile/dev/player-35-change-addEventL…
Browse files Browse the repository at this point in the history
…istener-in-apimanager

[PLAYER-35] change add event listener in apimanager
  • Loading branch information
jparez authored Aug 6, 2024
2 parents e9eca0a + 60698ca commit d126b25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/APIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = class APIManager {
name: 'addEventListener',
category: 'VM_communication',
fn: (event, fn) => {
return this.instance.addEventListener(event, fn);
return this.instance.registerEventCallback(event, fn);
},
description:
// eslint-disable-next-line max-len
Expand All @@ -34,7 +34,7 @@ module.exports = class APIManager {
name: 'disconnect',
category: 'VM_communication',
fn: () => {
this.instance.disconnect();
this.instance.destroy();
},
description: 'Disconnect from the current instance, ending the WebSocket communication.',
});
Expand Down
8 changes: 6 additions & 2 deletions src/DeviceRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,13 @@ module.exports = class DeviceRenderer {
* This will poll the WebRTC sequence until the WebSocket stops throwing the onclose event (unexpected quit).
*/
onConnectionClosed() {
// closure to expose the right video and store context to onclose event
const video = this.video;
const store = this.store;

this.webRTCWebsocket.onclose = (event) => {
this.store.dispatch({type: 'WEBRTC_CONNECTION_READY', payload: false});
this.video.style.background = this.videoBackupStyleBackground;
store.dispatch({type: 'WEBRTC_CONNECTION_READY', payload: false});
video.style.background = this.videoBackupStyleBackground;
this.initialized = false;
log.debug('Error! Maybe your VM is not available yet? (' + event.code + ') ' + event.reason);

Expand Down
7 changes: 0 additions & 7 deletions src/plugins/GamepadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,6 @@ module.exports = class GamepadManager {
* @param {GamepadEvent} event raw event coming from the browser Gamepad API
*/
onGamepadDisconnected(event) {
this.instance.store.dispatch({
type: 'ADD_TRACKED_EVENT',
payload: {
category: 'gamepad',
action: 'unplugged',
},
});
const customEvent = new CustomEvent('gm-gamepadDisconnected', {detail: this.parseGamepad(event.gamepad)});
window.dispatchEvent(customEvent);
this.stopListeningInputs(event.gamepad.index);
Expand Down

0 comments on commit d126b25

Please sign in to comment.