提交 084509ad 编写于 作者: 雪洛's avatar 雪洛

fix: ble ArrayBuffer

上级 10279503
import {
invoke,
publish,
arrayBufferToBase64,
base64ToArrayBuffer
publish
} from '../../bridge'
/**
......@@ -53,16 +51,6 @@ function bluetoothOn (method, beforeSuccess) {
return true
}
function checkDevices (data) {
data.devices = data.devices.map(device => {
var advertisData = device.advertisData
if (advertisData && typeof advertisData !== 'string') {
device.advertisData = arrayBufferToBase64(advertisData)
}
return device
})
}
var onBluetoothAdapterStateChange
var onBluetoothDeviceFound
var onBLEConnectionStateChange
......@@ -83,7 +71,7 @@ export function getBluetoothAdapterState (data, callbackId) {
}
export function startBluetoothDevicesDiscovery (data, callbackId) {
onBluetoothDeviceFound = onBluetoothDeviceFound || bluetoothOn('onBluetoothDeviceFound', checkDevices)
onBluetoothDeviceFound = onBluetoothDeviceFound || bluetoothOn('onBluetoothDeviceFound')
bluetoothExec('startBluetoothDevicesDiscovery', callbackId, data)
}
......@@ -92,7 +80,7 @@ export function stopBluetoothDevicesDiscovery (data, callbackId) {
}
export function getBluetoothDevices (data, callbackId) {
bluetoothExec('getBluetoothDevices', callbackId, {}, checkDevices)
bluetoothExec('getBluetoothDevices', callbackId, {})
}
export function getConnectedBluetoothDevices (data, callbackId) {
......@@ -118,18 +106,12 @@ export function getBLEDeviceCharacteristics (data, callbackId) {
}
export function notifyBLECharacteristicValueChange (data, callbackId) {
onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange',
data => {
data.value = arrayBufferToBase64(data.value)
})
onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange')
bluetoothExec('notifyBLECharacteristicValueChange', callbackId, data)
}
export function notifyBLECharacteristicValueChanged (data, callbackId) {
onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange',
data => {
data.value = arrayBufferToBase64(data.value)
})
onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange')
bluetoothExec('notifyBLECharacteristicValueChanged', callbackId, data)
}
......@@ -139,8 +121,5 @@ export function readBLECharacteristicValue (data, callbackId) {
}
export function writeBLECharacteristicValue (data, callbackId) {
if (typeof data.value === 'string') {
data.value = base64ToArrayBuffer(data.value)
}
bluetoothExec('writeBLECharacteristicValue', callbackId, data)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册