npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-advance-bluetooth-audio-manager

v0.1.5

Published

advance bluetooth and audio

Downloads

10

Readme

react-native-advance-bluetooth-audio-manager

A React Native library for advanced Bluetooth audio management, allowing you to scan for Bluetooth devices, connect to them, and route audio to connected devices.

Features

  • Scan for nearby Bluetooth devices.
  • Connect to Bluetooth devices.
  • Route audio output to connected Bluetooth devices.
  • Full control of Bluetooth audio playback.

Installation

To install the library, use npm or yarn:

npm install react-native-advance-bluetooth-audio-manager

or

yarn add react-native-advance-bluetooth-audio-manager

Linking

If you are not using auto-linking (React Native 0.60 and above), link the package manually:

react-native link react-native-advance-bluetooth-audio-manager

Note: For Expo users, this package requires a custom development build because Expo Go does not support native code. You can create a custom build using EAS:

eas build --profile development --platform android

Permissions

Ensure that your AndroidManifest.xml file contains the necessary permissions for Bluetooth usage:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Usage

Import the package and utilize its Bluetooth audio management features:

import BluetoothAudioManager from 'react-native-advance-bluetooth-audio-manager';

// Initialize Bluetooth Manager
await BluetoothAudioManager.initialize();

// Scan for Bluetooth devices
const devices = await BluetoothAudioManager.startScanning();

// Connect to a specific device
await BluetoothAudioManager.connectToDevice(devices[0]);

// Route audio to the connected device
await BluetoothAudioManager.routeAudioToDevice(devices[0].id);

// Destroy the Bluetooth Manager when done
await BluetoothAudioManager.destroy();

Example

import React, { useState, useEffect } from 'react';
import { View, Button, Text, Alert } from 'react-native';
import BluetoothAudioManager from 'react-native-advance-bluetooth-audio-manager';

const BluetoothAudioExample = () => {
  const [devices, setDevices] = useState([]);

  useEffect(() => {
    // Initialize Bluetooth on mount
    const initializeBluetooth = async () => {
      try {
        await BluetoothAudioManager.initialize();
      } catch (error) {
        Alert.alert('Error', 'Failed to initialize Bluetooth manager.');
      }
    };

    initializeBluetooth();
    
    return () => {
      BluetoothAudioManager.destroy(); // Clean up on unmount
    };
  }, []);

  const scanDevices = async () => {
    try {
      const foundDevices = await BluetoothAudioManager.startScanning();
      setDevices(foundDevices);
    } catch (error) {
      Alert.alert('Error', 'Failed to scan for devices.');
    }
  };

  const connectToDevice = async device => {
    try {
      await BluetoothAudioManager.connectToDevice(device);
      Alert.alert('Connected', `Connected to ${device.name}`);
    } catch (error) {
      Alert.alert('Error', `Failed to connect to ${device.name}`);
    }
  };

  return (
    <View>
      <Button title="Scan for Devices" onPress={scanDevices} />
      {devices.map(device => (
        <Text key={device.id} onPress={() => connectToDevice(device)}>
          {device.name}
        </Text>
      ))}
    </View>
  );
};

export default BluetoothAudioExample;

Troubleshooting

Common Issues

  • Cannot read property 'initialize' of undefined: Ensure the native module is properly linked. If using Expo, remember that Expo Go doesn't support custom native code. You will need to build a custom development build using EAS.

  • No devices found: Make sure your Bluetooth device is in pairing mode and that the necessary permissions (like BLUETOOTH_CONNECT and BLUETOOTH_SCAN) are granted.

Contributing

We welcome contributions! Please read the contributing guide to learn how to contribute to this project.

License

MIT License


Created with create-react-native-library