diff --git a/packages/uni-app-plus-nvue/dist/index.js b/packages/uni-app-plus-nvue/dist/index.js index 97db0f43182d6704e7f8e5bfa3fc2ccbb4df4119..5b787a20ab8f8e9a99a4021f101aa72c8e15b7e0 100644 --- a/packages/uni-app-plus-nvue/dist/index.js +++ b/packages/uni-app-plus-nvue/dist/index.js @@ -101,10 +101,6 @@ var serviceContext = (function () { var base64Arraybuffer_1 = base64Arraybuffer.encode; var base64Arraybuffer_2 = base64Arraybuffer.decode; - function pack (args) { - return args - } - function unpack (args) { return args } @@ -4387,7 +4383,7 @@ var serviceContext = (function () { /** * 执行蓝牙相关方法 */ - function bluetoothExec (method, callbackId, data = {}) { + function bluetoothExec (method, callbackId, data = {}, beforeSuccess) { var deviceId = data.deviceId; if (deviceId) { data.deviceId = deviceId.toUpperCase(); @@ -4399,7 +4395,10 @@ var serviceContext = (function () { plus.bluetooth[method.replace('Changed', 'Change')](Object.assign(data, { success (data) { - invoke(callbackId, Object.assign({}, pack(data), { + if (typeof beforeSuccess === 'function') { + beforeSuccess(data); + } + invoke(callbackId, Object.assign({}, data, { errMsg: `${method}:ok`, code: undefined, message: undefined @@ -4416,9 +4415,12 @@ var serviceContext = (function () { /** * 监听蓝牙相关事件 */ - function bluetoothOn (method) { + function bluetoothOn (method, beforeSuccess) { plus.bluetooth[method.replace('Changed', 'Change')](function (data) { - publish(method, Object.assign({}, pack(data), { + if (typeof beforeSuccess === 'function') { + beforeSuccess(data); + } + publish(method, Object.assign({}, data, { code: undefined, message: undefined })); @@ -4426,6 +4428,16 @@ var serviceContext = (function () { 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; @@ -4446,7 +4458,7 @@ var serviceContext = (function () { } function startBluetoothDevicesDiscovery (data, callbackId) { - onBluetoothDeviceFound = onBluetoothDeviceFound || bluetoothOn('onBluetoothDeviceFound'); + onBluetoothDeviceFound = onBluetoothDeviceFound || bluetoothOn('onBluetoothDeviceFound', checkDevices); bluetoothExec('startBluetoothDevicesDiscovery', callbackId, data); } @@ -4455,7 +4467,7 @@ var serviceContext = (function () { } function getBluetoothDevices (data, callbackId) { - bluetoothExec('getBluetoothDevices', callbackId, {}); + bluetoothExec('getBluetoothDevices', callbackId, {}, checkDevices); } function getConnectedBluetoothDevices (data, callbackId) { @@ -4481,12 +4493,18 @@ var serviceContext = (function () { } function notifyBLECharacteristicValueChange (data, callbackId) { - onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange'); + onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange', + data => { + data.value = arrayBufferToBase64(data.value); + }); bluetoothExec('notifyBLECharacteristicValueChange', callbackId, data); } function notifyBLECharacteristicValueChanged (data, callbackId) { - onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange'); + onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange', + data => { + data.value = arrayBufferToBase64(data.value); + }); bluetoothExec('notifyBLECharacteristicValueChanged', callbackId, data); } @@ -4495,7 +4513,8 @@ var serviceContext = (function () { } function writeBLECharacteristicValue (data, callbackId) { - bluetoothExec('writeBLECharacteristicValue', callbackId, unpack(data)); + data.value = base64ToArrayBuffer(data.value); + bluetoothExec('writeBLECharacteristicValue', callbackId, data); } function getScreenBrightness () {