2013-07-14 38 views
1

是否可以使用藍牙JavaScript擴展API來實現藍牙服務器(換句話說,監聽套接字),它可以允許設備(藍牙客戶端)連接?Chrome中的藍牙API可以用作服務器嗎?

根據目前的文檔和很少的例子,我發現它不清楚這是否是一種可能性。

謝謝。

回答

2

是:https://developer.chrome.com/apps/app_bluetooth#listening

var uuid = '1105'; 
chrome.bluetoothSocket.create(function(createInfo) { 
    chrome.bluetoothSocket.onAccept.addListener(function(acceptInfo) { 
     if (info.socketId != createInfo.socketId) return; 

     // Say hello... 
     chrome.bluetoothSocket.send(acceptInfo.clientSocketId, 
      data, onSendCallback); 

     // Accepted sockets are initially paused, 
     // set the onReceive listener first. 
     chrome.bluetoothSocket.onReceive.addListener(onReceive); 
     chrome.bluetoothSocket.setPaused(acceptInfo.clientSocketId, false); 
    }); 

    chrome.bluetoothSocket.listenUsingRfcomm(
     createInfo.socketId, uuid, function() { 
      // check chrome.runtime.lastError 
     }); 
});