투케이2K

375. (javaScript) [간단 소스] 자바스크립트 navigator.bluetooth.getAvailability 사용해 블루투스 사용가능 및 지원 기기 여부 확인 본문

JavaScript

375. (javaScript) [간단 소스] 자바스크립트 navigator.bluetooth.getAvailability 사용해 블루투스 사용가능 및 지원 기기 여부 확인

투케이2K 2025. 3. 1. 10:04

[개발 환경 설정]

개발 툴 : Edit++

개발 언어 : JavaScript

 

[소스 코드]

 

-----------------------------------------------------------------------------------------
[사전 설명 및 설정 사항]
-----------------------------------------------------------------------------------------

- 개발 환경 : Web

- 개발 기술 : JavaScript (자바스크립트) / bluetooth / getAvailability

-----------------------------------------------------------------------------------------





-----------------------------------------------------------------------------------------
[소스 코드]
-----------------------------------------------------------------------------------------

  <script>

    // [html 최초 로드 및 이벤트 상시 대기 실시] 
    window.onload = async function() {
        console.log("");
        console.log("======================================================");
        console.log("[window onload] : [start]");
        console.log("======================================================");
        console.log("");

        try {

            await navigator.bluetooth.getAvailability().then((available) => {
                if (available) {
                    console.log("");
                    console.log("======================================================");
                    console.log("[bluetooth.getAvailability] : 블루투스를 지원하는 기기입니다.");                        
                    console.log("======================================================");
                    console.log("");
                } else {
                    console.log("");
                    console.log("======================================================");
                    console.log("[bluetooth.getAvailability] : 블루투스를 지원하지 않는 기기입니다.");                        
                    console.log("======================================================");
                    console.log("");
                }
            });
            
        }
        catch (exception) {
            console.error("");
            console.error("======================================================");
            console.error("[window onload] : [Exception] : 예외 상황 발생");
            console.error("------------------------------------------------");
            console.error("[ERROR] : ", exception);
            console.error("======================================================");
            console.error("");        
        }

    }; 

    
</script>

-----------------------------------------------------------------------------------------





-----------------------------------------------------------------------------------------
[결과 출력]
-----------------------------------------------------------------------------------------

======================================================
[window onload] : [start]
======================================================


======================================================
[bluetooth.getAvailability] : 블루투스를 지원하는 기기입니다.
======================================================

-----------------------------------------------------------------------------------------





-----------------------------------------------------------------------------------------
[참고 사이트]
-----------------------------------------------------------------------------------------

https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getAvailability

-----------------------------------------------------------------------------------------
 
반응형
Comments