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

fix: ble ArrayBuffer

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