Gamepad API not working on Firefox (Mac)

#1

Hey!

I use the GamepadManager to initialize the gamepad in my game and it works fine on Safari, Chrome and Opera but for some reason I get this error in the console when trying to connect it in Firefox (Mac ver. 66.0.3)

I should add that my gamepad is recognized just fine when I try it on https://html5gamepad.com/ using Firefox, this is why I suspect this to be a Babylon issue.

Any idea of what’s going on?

#2

Hey are you using es6 modules? I think so. So you need to import from Gamepad I guess
Pinging @sebavan for confirmation

#3

I do not understand why it would work on some browsers and not the others if it was module related ?

I am really wondering what it could be, @wwwonka would you happen to have a repro somewhere ?

#4

Hey @Deltakosh @sebavan

Yes I use ES6 modules. I do have a repo but I use it for stuff other than code, so it might be simpler for you to have a look by downloading this zip folder:

Basically the file where I handle the gamepad is in src/Inputs/Gamepad.js, this is where I import the GamepadManager. I then initialize the Gamepad in src/Core/Game.js

Just run
npm install
npm start and this should open Google Chrome Canary,
In case it doesnt work because of my SSL certificate or because you test this on a Windows machine, you should be able to access the build at this URL http://localhost:8080

Tell me if something else gets you in the way of having a look at this.

#5

it looks like your gamepad supports pose information in firefox, what kind of gamepad are you using ?

You could try to import our generic controller:
import “@babylonjs/core/Gamepads/Controllers/genericController”;

#6

I am using a PS4 Controller connected via bluetooth.

It’s a step in the good direction: When I import {GenericGamepad} , Firefox now detects the Gamepad but the buttons input become unrecognized and I get this error in the console:

Should I import another file?

#7

nope this is a bug where the controllers PS4 are recognized as WebVRControllers on firefox so you do not have the onButtonDownObservable on them.

They should not be and be recognized as a generic controller or 360 I guess.

Let me add @trevordev who can help addressing the issue.

#8

Hey @wwwonka I am trying to get my hands on a ps4 controller. I should have one sometime around ~a week from now and Ill try to repro and fix.

2 Likes
#9

Any advancements?

#10

pinging @trevordev

#11

@wwwonka Sorry my first request for a controller still hasn’t come through yet. Ill try getting one another way, sorry for the wait.

#12

No apologies!
Hey. This community is way too generous.
Take your time.

#13

Hey @wwwonka,

I managed to get a controller, sorry for the wait, I think I have a repro and am working on a fix.

2 Likes
#14

Here’s the PR, like Seb said it was being treated as a vr controller due to it having a pose and no other properties make something obviously not a vr controller. I excluded it by ID so it will be treated as a generic game controller. After this PR is merged and the playground is updated (~1 or 2 days) Ps4 controller, playground logo css, pointerBehavior public mesh by TrevorDev · Pull Request #6318 · BabylonJS/Babylon.js · GitHub feel free to give it a try and let me know if you still have issues.

#15

@trevordev ,

I’ll look into it when the playground gets updated and will keep you informed with the results. Is it something that you are going to push in the next ES6 release soon as well?

It sounds like lately the Gamepad API has been getting a bit of love to support a more advanced set of features. Lately for instance vibration has been added to Chromium. To your knowledge does this mean that Firefox is working on making the gyroscope/accelerometer contained in standard gamepads work in the browser as well? I’m just curious.

#16

I don’t know much around this but I remember seeing that chromium was better supporting controllers like the one for switch (It also might be to prep for Google’s stadia project). On the other hand webXR was moving away from the gamepad api last time I checked so likely any new gamepad apis are not driven by vr/ar hardware so it might be easier to avoid bugs like this one in the future.

#17

Alright so there is no issue anymore in the playground using firefox. :grinning:

I should mention that the playground works fine even with the stable version (4.0.3); which is the version of the npm package I am currently using in my project. I am guessing we will have to wait the next update on npm for the fix to take in effect outside the playground?

1 Like
#18

Yep:) that should happen soon btw

1 Like