Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add disconnect event handler #244

Closed
aircable opened this issue Jun 14, 2016 · 6 comments

Comments

@aircable
Copy link

commented Jun 14, 2016

I would like to get a disconnect event from the gatt server.

        navigator.bluetooth.requestDevice(options)
            .then(function ( device ) {
                console.log('Name: ' + device.name);
                server.addEventListener( 'gattserverdisconnected', handleDisconnect );
                return device.gatt.connect();
            })
            .then(function ( server ) {
                console.log('server ' + server );
                return server.getPrimaryService( MESH_SERVICE_UUID );
            })

The event listener add is accepted, but never executed. The BluetoothRemoteGATTServer object does not have a addEventListener function.
Am I doing something wrong? This is on Android Chrome 51.0.2704.81
Thanks

@beaufortfrancois

This comment has been minimized.

Copy link
Member

commented Jun 14, 2016

As shown in https://googlechrome.github.io/samples/web-bluetooth/device-disconnect.html, the gattserverdisconnected event must be registered on the BluetoothDevice, not the server.

@beaufortfrancois

This comment has been minimized.

Copy link
Member

commented Jun 14, 2016

In your code, here's how it should look like:

        navigator.bluetooth.requestDevice(options)
            .then(function ( device ) {
                console.log('Name: ' + device.name);
                device.addEventListener( 'gattserverdisconnected', handleDisconnect );
                return device.gatt.connect();
            })
            .then(function ( server ) {
                console.log('server ' + server );
                return server.getPrimaryService( MESH_SERVICE_UUID );
            })
@aircable

This comment has been minimized.

Copy link
Author

commented Jun 14, 2016

yes, sorry, that was a typo. I tried that and forgot to change it back.
this threw an error of course.

device.addEventListener is not being called. That was my error report.

@g-ortuno

This comment has been minimized.

Copy link
Contributor

commented Jun 14, 2016

As you can see from the Implementation Status, the disconnection event was added in m52. I recommend you download Chrome Dev to try it out.

@aircable

This comment has been minimized.

Copy link
Author

commented Jun 14, 2016

that explains it, thanks, will report

@aircable

This comment has been minimized.

Copy link
Author

commented Jun 14, 2016

closed, it does work, on Chrome DEV
Thanks

@aircable aircable closed this Jun 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.