0
我想創建一個Chrome應用程序,當某個藍牙設備正在發送數據時顯示該應用程序。具體來說,我有2個藍牙鼠標,我想確定哪一個正在特定的時間移動。 我跟着Chrome開發文檔,併成功,直到我試圖實現在接收添加一個偵聽器來查看來自設備的數據。我得到一個「無法讀取屬性」addListener「的未定義」錯誤。Chrome應用程序藍牙
這是當我開始收到此錯誤: Error message
這裏是我與
chrome.bluetooth.getDevices(function(devices) {
for (var i = 0; i < devices.length; i++) {
//Displaying device names
console.log(i+": "+devices[i].name);
}
//uuid for a specific device
var uuid = "00001200-0000-1000-8000-00805f9b34fb";
// var uuid = devices[4].uuid;
var onConnectedCallback = function() {
if (chrome.runtime.lastError) {
console.log("Connection failed: " + chrome.runtime.lastError.message);
} else {
// Profile implementation here.
}
};
chrome.bluetoothSocket.create(function(createInfo) {
chrome.bluetoothSocket.connect(createInfo.socketId,
devices[4].address, uuid, onConnectedCallback);
console.log(createInfo);
chrome.bluetoothSocket.onRecieve.addListener(function(receiveInfo) {
if (receiveInfo.socketId != socketId)
return;
console.log(receiveInfo);
});
});
});