Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/js/gamepad-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GamepadHelper {
XBOX: 'xbox',
PLAYSTATION: 'playstation',
SWITCH: 'switch',
STANDARD: 'standard'
STANDARD: 'standard',
};

/**
Expand Down Expand Up @@ -92,13 +92,15 @@ class GamepadHelper {
gamepad_api_ids: [
"Xbox 360 Controller (XInput STANDARD GAMEPAD)",
],
vendor_product_ids: ["045e:028e"],
type: this.CONTROLLER_TYPES.XBOX
},
6: {
name: "Xbox One/Series",
gamepad_api_ids: [
"HID-compliant game controller (STANDARD GAMEPAD Vendor: 045e Product: 0b13)",
],
vendor_product_ids: ["045e:02ea", "045e:0b12", "045e:0b13", "045e:0b20"],
type: this.CONTROLLER_TYPES.XBOX
},
7: {
Expand Down Expand Up @@ -177,12 +179,13 @@ class GamepadHelper {
14: 'DLeft',
15: 'DRight',
16: 'Home',
17: 'Share',
},
axisMap: {
0: 'Left Stick X',
1: 'Left Stick Y',
2: 'Right Stick X',
3: 'Right Stick Y'
3: 'Right Stick Y',
}
},

Expand Down Expand Up @@ -212,7 +215,7 @@ class GamepadHelper {
0: 'Left Stick X',
1: 'Left Stick Y',
2: 'Right Stick X',
3: 'Right Stick Y'
3: 'Right Stick Y',
}
},

Expand Down Expand Up @@ -242,7 +245,7 @@ class GamepadHelper {
0: 'Left Stick X',
1: 'Left Stick Y',
2: 'Right Stick X',
3: 'Right Stick Y'
3: 'Right Stick Y',
}
},

Expand All @@ -253,7 +256,7 @@ class GamepadHelper {
0: 'Axis 0',
1: 'Axis 1',
2: 'Axis 2',
3: 'Axis 3'
3: 'Axis 3',
}
}
};
Expand Down Expand Up @@ -307,7 +310,8 @@ class GamepadHelper {
13: 'D-Pad Down.svg',
14: 'D-Pad Left.svg',
15: 'D-Pad Right.svg',
16: 'Home.svg'
16: 'Home.svg',
17: 'Share.svg',
}
},
[this.CONTROLLER_TYPES.PLAYSTATION]: {
Expand All @@ -330,7 +334,7 @@ class GamepadHelper {
14: 'D-Pad Left.svg',
15: 'D-Pad Right.svg',
16: 'Home.svg',
17: 'Touch Pad Press.svg'
17: 'Touch Pad Press.svg',
}
},
[this.CONTROLLER_TYPES.SWITCH]: {
Expand All @@ -353,7 +357,7 @@ class GamepadHelper {
14: 'Pro D-Pad Left.svg',
15: 'Pro D-Pad Right.svg',
16: 'Home.svg',
17: 'Capture.svg'
17: 'Capture.svg',
}
}
};
Expand Down
42 changes: 42 additions & 0 deletions tests/gamepad-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ describe('GamepadHelper', () => {
expect(helper.vendorProductLookup['054c:0ce6'].name).toBe('Sony DualSense (PS5)');
expect(helper.vendorProductLookup['057e:2009'].name).toBe('Nintendo Switch Pro Controller');
expect(helper.vendorProductLookup['1209:0001'].name).toBe('Generic Gamepad');
expect(helper.vendorProductLookup['045e:028e'].name).toBe('Xbox 360');
expect(helper.vendorProductLookup['045e:02ea'].name).toBe('Xbox One/Series');
expect(helper.vendorProductLookup['045e:0b12'].name).toBe('Xbox One/Series');
expect(helper.vendorProductLookup['045e:0b13'].name).toBe('Xbox One/Series');
expect(helper.vendorProductLookup['045e:0b20'].name).toBe('Xbox One/Series');
});

test('initializes controller mappings correctly', () => {
Expand Down Expand Up @@ -130,6 +135,18 @@ describe('GamepadHelper', () => {
type: 'standard',
name: 'Generic Gamepad'
},
{
browserController: 'Firefox Xbox 360',
gamepadId: '045e-028e-Sunshine (libvirtualhid) X-Box 360 Controller',
type: 'xbox',
name: 'Xbox 360'
},
{
browserController: 'Firefox Xbox Series',
gamepadId: '045e-0b13-Sunshine (libvirtualhid) X-Box Series Controller',
type: 'xbox',
name: 'Xbox One/Series'
},
{
browserController: 'Chrome DualShock 4',
gamepadId: 'HID VHF Driver (STANDARD GAMEPAD Vendor: 054c Product: 05c4)',
Expand All @@ -154,6 +171,24 @@ describe('GamepadHelper', () => {
type: 'standard',
name: 'Generic Gamepad'
},
{
browserController: 'Chrome Xbox 360',
gamepadId: 'Sunshine (libvirtualhid) X-Box 360 Controller (STANDARD GAMEPAD Vendor: 045e Product: 028e)',
type: 'xbox',
name: 'Xbox 360'
},
{
browserController: 'Chrome Xbox One',
gamepadId: 'Sunshine (libvirtualhid) X-Box One Controller (STANDARD GAMEPAD Vendor: 045e Product: 0b20)',
type: 'xbox',
name: 'Xbox One/Series'
},
{
browserController: 'Chrome Xbox Series',
gamepadId: 'Sunshine (libvirtualhid) X-Box Series Controller (STANDARD GAMEPAD Vendor: 045e Product: 0b13)',
type: 'xbox',
name: 'Xbox One/Series'
},
])('returns a VID/PID match for $browserController', ({ gamepadId, type, name }) => {
expect(helper.getGamepadInfo(gamepadId)).toEqual({ type, name });
});
Expand Down Expand Up @@ -201,6 +236,8 @@ describe('GamepadHelper', () => {
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 0)).toBe('A');
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 4)).toBe('LB');
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 12)).toBe('DUp');
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 17)).toBe('Share');
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 18)).toBe('B18');
});

test('returns correct button names for PlayStation controller', () => {
Expand Down Expand Up @@ -393,6 +430,11 @@ describe('GamepadHelper', () => {
expect(path).toBe('/assets/img/gamepads/xbox/Buttons Outline/White/SVG/A.svg');
});

test('returns the Share icon for Xbox button 17', () => {
const path = helper.getButtonImagePath(helper.CONTROLLER_TYPES.XBOX, 17);
expect(path).toBe('/assets/img/gamepads/xbox/Buttons Outline/White/SVG/Share.svg');
});

test('returns correct path for PlayStation controller buttons', () => {
const path = helper.getButtonImagePath(helper.CONTROLLER_TYPES.PLAYSTATION, 3);
expect(path).toBe('/assets/img/gamepads/playstation/Buttons Outline/White/SVG/Triangle.svg');
Expand Down