Skip to content

Commit

Permalink
Merge pull request #97 from Genymobile/dev/PLAYER-36-clean-up-old-red…
Browse files Browse the repository at this point in the history
…is-events

[PLAYER-36] clean up old redis events
  • Loading branch information
jparez authored Sep 6, 2024
2 parents 85c2be7 + 19d869b commit ce11fdf
Show file tree
Hide file tree
Showing 14 changed files with 1 addition and 246 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ The Player API provides functionality for managing plugin options and websocket

- Parameters:

- event (string): The name of the event to listen for. Example events include 'fingerprint', 'gps', and 'BATTERY_LEVEL'...
- event (string): The name of the event to listen for. Example events include 'fingerprint', 'gps'...
- callback (function): The function to call when the event is emitted. The message from the VM will be passed as an argument to the callback function.

- Example Usage
Expand Down
9 changes: 0 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,15 @@ type DeviceRendererKeyMapping = {
};

type VmEvent =
| 'ANDROID_ID'
| 'baseband'
| 'BATTERY_LEVEL'
| 'BATTERY_STATUS'
| 'battery'
| 'beforeunload'
| 'BLK'
| 'CLIPBOARD'
| 'diskio'
| 'fingerprint'
| 'framework'
| 'gps'
| 'IMEI'
| 'network_profile'
| 'NETWORK'
| 'settings'
| 'SYSTEM_PATCHER_LAST_RESULT'
| 'SYSTEM_PATCHER_STATUS'
| 'systempatcher'
| 'vinput'
| string; // This list is not exhaustive and should be completed
Expand Down
8 changes: 0 additions & 8 deletions src/plugins/Battery.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,10 @@ module.exports = class Battery extends OverlayPlugin {
// Register plugin
this.instance.battery = this;

// Listen for initial battery charging status
this.instance.registerEventCallback('BATTERY_STATUS', (value) => {
this.updateUIBatteryChargingState(value !== 'false');
});

// Display widget
this.renderToolbarButton();
this.renderWidget();

// Listen for initial battery level
this.instance.registerEventCallback('BATTERY_LEVEL', this.onBatteryLevelChange.bind(this));

// Listen for battery messages: "state mode <discharging/charging/full> <value>"
this.instance.registerEventCallback('battery', (message) => {
const values = message.split(' ').splice(-2);
Expand Down
5 changes: 0 additions & 5 deletions src/plugins/Clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ module.exports = class Clipboard extends OverlayPlugin {
log.warn('Malformed clipboard content');
}
});

// Listen for initial clipboard status
this.instance.registerEventCallback('CLIPBOARD', (text) => {
this.clipboard = text;
});
}

/**
Expand Down
7 changes: 0 additions & 7 deletions src/plugins/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ module.exports = class FileUpload extends OverlayPlugin {
this.renderToolbarButton();
this.renderWidget();

// Listen for events
this.instance.registerEventCallback('SYSTEM_PATCHER_STATUS', this.onSystemPatcherStatusEvent.bind(this));
this.instance.registerEventCallback(
'SYSTEM_PATCHER_LAST_RESULT',
this.onSystemPatcherLastResultEvent.bind(this),
);

/*
* Listen for systempatcher messages: "status <ready/downloading/installing> <opengapps>"
* or "last_result <success/cancelled/unavailable/network_error/corrupted_archive/install>_error <error message>"
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/IOThrottling.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ module.exports = class IOThrottling extends OverlayPlugin {
this.renderToolbarButton();
this.renderWidget();

// Listen for initial diskio
this.instance.registerEventCallback('BLK', this.setActive.bind(this));

// Listen for diskio messages: "readbyterate <value>" (or "cachecleared")
this.instance.registerEventCallback('diskio', (message) => {
const values = message.split(' ');
Expand Down
8 changes: 0 additions & 8 deletions src/plugins/Identifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ module.exports = class Identifiers extends OverlayPlugin {
this.renderToolbarButton();
this.renderWidget();

// Listen for IDs from renderer
this.instance.registerEventCallback('ANDROID_ID', (payload) => {
this.androidInput.value = payload;
});
this.instance.registerEventCallback('IMEI', (payload) => {
this.deviceInput.value = payload;
});

// Listen for settings messages: "parameter <device_id/android_id>:<id>"
this.instance.registerEventCallback('settings', (message) => {
const values = message.split(' ');
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ module.exports = class Network extends OverlayPlugin {
// Listen for settings messages: "if wifi:on|off mobile:on|off"
this.instance.registerEventCallback('settings', this.handleSettings.bind(this));

// Listen for initial network
this.instance.registerEventCallback('NETWORK', this.setActiveProfile.bind(this));

/*
* Listen for network messages:
* state wifi up_rate:<enabled/disabled>:<value>
Expand Down
29 changes: 0 additions & 29 deletions tests/unit/battery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,6 @@ describe('Battery Plugin', () => {
levelMock.mockRestore();
});

test('BATTERY_STATUS', () => {
instance.emit('BATTERY_STATUS', 'jean-michel'); // Invalid value (=== charging)
expect(battery.chargingInput.checked).toBeTruthy();

instance.emit('BATTERY_STATUS', 'false'); // Discharging
expect(battery.chargingInput.checked).toBeFalsy();

instance.emit('BATTERY_STATUS', 'true'); // Charging
expect(battery.chargingInput.checked).toBeTruthy();
});

test('BATTERY_LEVEL', () => {
instance.emit('BATTERY_LEVEL', 'jean-michel'); // Invalid value
expect(Number(battery.chargeSlider.value)).toBe(50);
expect(Number(battery.chargeInput.value)).toBe(50);

instance.emit('BATTERY_LEVEL', '69'); // Nice
expect(Number(battery.chargeSlider.value)).toBe(69);
expect(Number(battery.chargeInput.value)).toBe(69);

instance.emit('BATTERY_LEVEL', '666'); // Overflow
expect(Number(battery.chargeSlider.value)).toBe(100);
expect(Number(battery.chargeInput.value)).toBe(100);

instance.emit('BATTERY_LEVEL', '-420'); // Underflow
expect(Number(battery.chargeSlider.value)).toBe(0);
expect(Number(battery.chargeInput.value)).toBe(0);
});

test('battery', () => {
instance.emit('battery', 'jean-michel'); // Bad format
expect(levelMock).not.toHaveBeenCalled();
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/clipboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ describe('Clipboard Plugin', () => {
});

describe('incoming events', () => {
test('CLIPBOARD', () => {
instance.emit('CLIPBOARD', 'test value');
expect(clipboard.clipboard).toBe('test value');
});

test('framework', () => {
instance.emit('framework', 'clipboard too many arguments');
expect(clipboard.clipboard).toBe('');
Expand Down
103 changes: 0 additions & 103 deletions tests/unit/fileupload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,112 +115,9 @@ describe('FileUpload Plugin', () => {
uploader.toggleWidget();
expect(uploader.currentStep).toEqual('homeScreen');
});

test('Dont force show on success', () => {
uploader.flashing = false;
uploader.displayStep('uploadScreen');
expect(document.getElementsByClassName('gm-hidden').length).toEqual(1);
instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'success');
expect(document.getElementsByClassName('gm-hidden').length).toEqual(1);
});

test('dont force show on error', () => {
uploader.flashing = false;
uploader.displayStep('uploadScreen');
expect(document.getElementsByClassName('gm-hidden').length).toEqual(1);
instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'install_error');
expect(document.getElementsByClassName('gm-hidden').length).toEqual(1);
});

test('force show on opengapps success', () => {
uploader.flashing = true;
uploader.displayStep('uploadScreen');
expect(document.getElementsByClassName('gm-hidden').length).toEqual(1);
instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'success');
expect(document.getElementsByClassName('gm-hidden').length).toEqual(0);
});

test('force show on opengapps error', () => {
uploader.flashing = true;
uploader.displayStep('uploadScreen');
expect(document.getElementsByClassName('gm-hidden').length).toEqual(1);
instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'install_error');
expect(document.getElementsByClassName('gm-hidden').length).toEqual(0);
});
});

describe('incoming events', () => {
describe('SYSTEM_PATCHER_STATUS', () => {
test('downloading', () => {
uploader.displayStep('uploadScreen');
const textProgress = document.getElementsByClassName('gm-upload-in-progress-txt-percent')[0];

instance.emit('SYSTEM_PATCHER_STATUS', 'downloading something'); // Not enough parameters
expect(textProgress.innerHTML).toBe('');

instance.emit('SYSTEM_PATCHER_STATUS', 'downloading 69 100');
expect(textProgress.innerHTML).toBe('69%'); // Nice
});

test('installing', () => {
uploader.displayStep('uploadScreen');
const textProgress = document.getElementsByClassName('gm-upload-in-progress-txt-progress')[0];

instance.emit('SYSTEM_PATCHER_STATUS', 'installing');
expect(textProgress.innerHTML).toBe('TEST UPLOADER PLUGIN INSTALLING...');
});

test('ready', () => {
const updateOpenGAppsStatus = jest.spyOn(uploader, 'updateOpenGAppsStatus');
const sendEventSpy = jest.spyOn(instance, 'sendEvent');

instance.emit('SYSTEM_PATCHER_STATUS', 'ready'); // Not enough parameters
expect(updateOpenGAppsStatus).toHaveBeenCalledTimes(0);

instance.emit('SYSTEM_PATCHER_STATUS', 'ready something');
expect(updateOpenGAppsStatus).toHaveBeenCalledTimes(0);

// Asumes uploader.flashing = false, default
instance.emit('SYSTEM_PATCHER_STATUS', 'ready opengapps');
expect(updateOpenGAppsStatus).toHaveBeenCalledTimes(1);
expect(sendEventSpy).toHaveBeenCalledTimes(0);

uploader.flashing = true;
instance.emit('SYSTEM_PATCHER_STATUS', 'ready opengapps');
expect(updateOpenGAppsStatus).toHaveBeenCalledTimes(2);
expect(sendEventSpy).toHaveBeenCalledTimes(1);
expect(instance.outgoingMessages[0]).toEqual({
channel: 'systempatcher',
messages: ['notify last_result'],
});
});
});

test('SYSTEM_PATCHER_LAST_RESULT', () => {
const displayStep = jest.spyOn(uploader, 'displayStep');

instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'success');
expect(displayStep).toHaveBeenNthCalledWith(1, 'successScreen');

instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'unavailable');
expect(displayStep).toHaveBeenNthCalledWith(2, 'errorScreen');

instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'network_error');
expect(displayStep).toHaveBeenNthCalledWith(3, 'errorScreen');

instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'corrupted_archive');
expect(displayStep).toHaveBeenNthCalledWith(4, 'errorScreen');

instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'install_error');
expect(displayStep).toHaveBeenNthCalledWith(5, 'errorScreen');

instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'something');
expect(displayStep).toHaveBeenCalledTimes(5);

instance.emit('SYSTEM_PATCHER_LAST_RESULT', '');
expect(displayStep).toHaveBeenCalledTimes(5);
});

test('systempatcher', () => {
const onSystemPatcherStatusEvent = jest.spyOn(uploader, 'onSystemPatcherStatusEvent');
const onSystemPatcherLastResultEvent = jest.spyOn(uploader, 'onSystemPatcherLastResultEvent');
Expand Down
28 changes: 0 additions & 28 deletions tests/unit/identifiers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,6 @@ describe('Identifiers Plugin', () => {
});

describe('incoming events', () => {
test('ANDROID_ID', () => {
['jean-michel', '123', '0123456789abcdef0', ''].forEach((invalidValue) => {
instance.emit('ANDROID_ID', invalidValue);
identifiers.validateAndroidId();
expect(identifiers.invalidAndroidId).toBeTruthy();
});

['0123456789abcdef'].forEach((validValue) => {
instance.emit('ANDROID_ID', validValue);
identifiers.validateAndroidId();
expect(identifiers.invalidAndroidId).toBeFalsy();
});
});

test('IMEI', () => {
['jean-michel', '123', '', '0123456789abcdef'].forEach((invalidValue) => {
instance.emit('IMEI', invalidValue);
identifiers.validateDeviceId();
expect(identifiers.invalidDeviceId).toBeTruthy();
});

['0123456789abcd', '0123456789abcde'].forEach((validValue) => {
instance.emit('IMEI', validValue);
identifiers.validateDeviceId();
expect(identifiers.invalidDeviceId).toBeFalsy();
});
});

describe('settings', () => {
test('unrelevant topics', () => {
['unrelevant', 'parameters unrelevant:value', ''].forEach((invalidValue) => {
Expand Down
23 changes: 0 additions & 23 deletions tests/unit/iothrottling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,6 @@ describe('IOThrottling Plugin', () => {
});

describe('incoming events', () => {
test('BLK', () => {
['jean-michel', '-123', ''].forEach((invalidValue) => {
instance.emit('BLK', invalidValue);
expect(diskio.select.value).toBe('None');
});

[69, 420].forEach((customValue) => {
instance.emit('BLK', customValue * 1024);
expect(diskio.select.value).toBe('Custom');
expect(Number(diskio.readByteRate.value)).toBe(customValue);
});

IOThrottlingProfiles.forEach((profile) => {
if (!profile.readByteRate) {
return;
}

instance.emit('BLK', profile.readByteRate * 1024);
expect(diskio.select.value).toBe(profile.name);
expect(Number(diskio.readByteRate.value)).toBe(profile.readByteRate);
});
});

test('diskio', () => {
['jean-michel', 'readbyterate -123', '', 'readbyterate invalid'].forEach((invalidValue) => {
instance.emit('diskio', invalidValue);
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ describe('Network Plugin', () => {
// render default widget
network.disableMobileThrottling();
});
test('NETWORK', () => {
const loadDetails = jest.spyOn(network, 'loadDetails');

['jean-michel', '-123', '', '9'].forEach((invalidValue) => {
instance.emit('NETWORK', invalidValue);
expect(loadDetails).not.toHaveBeenCalled();
});

NetworkProfiles.forEach((profile) => {
instance.emit('NETWORK', profile.id);
expect(loadDetails).toHaveBeenCalledWith(NetworkProfiles[NetworkProfiles.length - 1 - profile.id]);
loadDetails.mockReset();
});
});

test('network_profile', () => {
const loadDetails = jest.spyOn(network, 'loadDetails');
Expand Down

0 comments on commit ce11fdf

Please sign in to comment.