Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/web-bluetooth

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/web-bluetooth

TypeScript definitions for web-bluetooth

  • 0.0.20
  • ts4.5
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5M
decreased by-3.47%
Maintainers
1
Weekly downloads
 
Created

What is @types/web-bluetooth?

@types/web-bluetooth provides TypeScript definitions for the Web Bluetooth API, allowing developers to interact with Bluetooth devices from web applications with type safety and autocompletion.

What are @types/web-bluetooth's main functionalities?

Requesting a Bluetooth Device

This feature allows you to request a Bluetooth device that offers a specific service, in this case, the 'battery_service'. The code demonstrates how to request the device and handle the response or any errors.

navigator.bluetooth.requestDevice({ filters: [{ services: ['battery_service'] }] })
  .then(device => console.log(device.name))
  .catch(error => console.error(error));

Connecting to a GATT Server

This feature allows you to connect to the GATT (Generic Attribute Profile) server of a Bluetooth device. The code demonstrates how to request a device and then connect to its GATT server.

navigator.bluetooth.requestDevice({ filters: [{ services: ['battery_service'] }] })
  .then(device => device.gatt.connect())
  .then(server => console.log('Connected to GATT Server'))
  .catch(error => console.error(error));

Reading a Characteristic Value

This feature allows you to read a characteristic value from a Bluetooth device. The code demonstrates how to request a device, connect to its GATT server, get the primary service, get the characteristic, and read its value.

navigator.bluetooth.requestDevice({ filters: [{ services: ['battery_service'] }] })
  .then(device => device.gatt.connect())
  .then(server => server.getPrimaryService('battery_service'))
  .then(service => service.getCharacteristic('battery_level'))
  .then(characteristic => characteristic.readValue())
  .then(value => console.log('Battery level is ' + value.getUint8(0) + '%'))
  .catch(error => console.error(error));

Other packages similar to @types/web-bluetooth

FAQs

Package last updated on 07 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc