react-native-webrtc / react-native-incall-manager

Handling media-routes/sensors/events during a audio/video chat on React Native
ISC License
555 stars 193 forks source link

How to check if Bluetooth Headset is connected #177

Open amirito opened 2 years ago

amirito commented 2 years ago

I want to do sth when headset plugged in We have getIsWiredHeadsetPluggedIn() here for wired headset But what about bluetooth headset?

basilbai commented 2 years ago

I have the same problem, does anyone know how to solve it? Thanks

cruzlutor commented 2 years ago

Any news about this?

aryan-dwivedi commented 2 years ago

@basilbai @cruzlutor @amirito were you able to solve it?

cruzlutor commented 2 years ago

@aryan-dwivedi Not with this library, I ended up using react-native-headphone-detection wrapping the logic in a hook like this

import { useState, useEffect } from 'react'
import HeadphoneDetection from 'react-native-headphone-detection'

export default function useHeadphone() {
  const [isHeadphoneConnected, setIsHeadphoneConnected] = useState<
    boolean | undefined
  >(false)

  useEffect(() => {
    HeadphoneDetection.addListener((result) => {
      setIsHeadphoneConnected(result.audioJack || result.bluetooth)
    })
    return () => {
      //@ts-ignore
      if (HeadphoneDetection.remove) HeadphoneDetection.remove()
    }
  }, [])

  return { isHeadphoneConnected }
}

It works for a wired headsets, but I haven't tried Bluetooth devices yet