Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/api-proxy/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,36 @@ export const offError: WechatMiniprogram.Wx['offError']
export const createInnerAudioContext: WechatMiniprogram.Wx['createInnerAudioContext']
export const base64ToArrayBuffer: WechatMiniprogram.Wx['base64ToArrayBuffer']
export const arrayBufferToBase64: WechatMiniprogram.Wx['arrayBufferToBase64']
export const openBluetoothAdapter: WechatMiniprogram.Wx['openBluetoothAdapter']
export const closeBluetoothAdapter: WechatMiniprogram.Wx['closeBluetoothAdapter']
export const startBluetoothDevicesDiscovery: WechatMiniprogram.Wx['startBluetoothDevicesDiscovery']
export const stopBluetoothDevicesDiscovery: WechatMiniprogram.Wx['stopBluetoothDevicesDiscovery']
export const onBluetoothDeviceFound: WechatMiniprogram.Wx['onBluetoothDeviceFound']
export const offBluetoothDeviceFound: WechatMiniprogram.Wx['offBluetoothDeviceFound']
export const getConnectedBluetoothDevices: WechatMiniprogram.Wx['getConnectedBluetoothDevices']
export const getBluetoothAdapterState: WechatMiniprogram.Wx['getBluetoothAdapterState']
export const onBluetoothAdapterStateChange: WechatMiniprogram.Wx['onBluetoothAdapterStateChange']
export const offBluetoothAdapterStateChange: WechatMiniprogram.Wx['offBluetoothAdapterStateChange']
export const getBluetoothDevices: WechatMiniprogram.Wx['getBluetoothDevices']
export const writeBLECharacteristicValue: WechatMiniprogram.Wx['writeBLECharacteristicValue']
export const readBLECharacteristicValue: WechatMiniprogram.Wx['readBLECharacteristicValue']
export const notifyBLECharacteristicValueChange: WechatMiniprogram.Wx['notifyBLECharacteristicValueChange']
export const onBLECharacteristicValueChange: WechatMiniprogram.Wx['onBLECharacteristicValueChange']
export const offBLECharacteristicValueChange: WechatMiniprogram.Wx['offBLECharacteristicValueChange']
export const setBLEMTU: WechatMiniprogram.Wx['setBLEMTU']
export const getBLEDeviceRSSI: WechatMiniprogram.Wx['getBLEDeviceRSSI']
export const getBLEDeviceServices: WechatMiniprogram.Wx['getBLEDeviceServices']
export const getBLEDeviceCharacteristics: WechatMiniprogram.Wx['getBLEDeviceCharacteristics']
export const closeBLEConnection: WechatMiniprogram.Wx['closeBLEConnection']
export const createBLEConnection: WechatMiniprogram.Wx['createBLEConnection']
export const onBLEConnectionStateChange: WechatMiniprogram.Wx['onBLEConnectionStateChange']
export const offBLEConnectionStateChange: WechatMiniprogram.Wx['offBLEConnectionStateChange']
export const startWifi: WechatMiniprogram.Wx['startWifi']
export const stopWifi: WechatMiniprogram.Wx['stopWifi']
export const getWifiList: WechatMiniprogram.Wx['getWifiList']
export const onGetWifiList: WechatMiniprogram.Wx['onGetWifiList']
export const offGetWifiList: WechatMiniprogram.Wx['offGetWifiList']
export const getConnectedWifi: WechatMiniprogram.Wx['getConnectedWifi']
export const createCanvasContext: WechatMiniprogram.Wx['createCanvasContext']
export const canvasToTempFilePath: WechatMiniprogram.Wx['canvasToTempFilePath']
export const canvasGetImageData: WechatMiniprogram.Wx['canvasGetImageData']
Expand Down
10 changes: 9 additions & 1 deletion packages/api-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
"react-native-device-info": "*",
"react-native-get-location": "*",
"react-native-haptic-feedback": "*",
"react-native-safe-area-context": "*"
"react-native-safe-area-context": "*",
"react-native-ble-manager": "*",
"react-native-wifi-reborn": "*"
},
"peerDependenciesMeta": {
"@react-native-async-storage/async-storage": {
Expand All @@ -66,6 +68,12 @@
},
"react-native-haptic-feedback": {
"optional": true
},
"react-native-ble-manager": {
"optional": true
},
"react-native-wifi-reborn": {
"optional": true
}
}
}
5 changes: 1 addition & 4 deletions packages/api-proxy/src/platform/api/base/index.web.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { fromByteArray, toByteArray } from './base64'

function base64ToArrayBuffer (base64) {
if (__mpx_mode__ === 'web') {
return toByteArray(base64)?.buffer
}
return toByteArray(base64)
return toByteArray(base64)?.buffer // 判断了一下,RN下也是要.buffer才是buffer类型
}

function arrayBufferToBase64 (arrayBuffer) {
Expand Down
69 changes: 67 additions & 2 deletions packages/api-proxy/src/platform/api/ble-connection/index.ali.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ENV_OBJ } from '../../../common/js'
import { ENV_OBJ, envError } from '../../../common/js'

function closeBLEConnection (options = {}) {
return ENV_OBJ.disconnectBLEDevice(options)
Expand All @@ -12,8 +12,73 @@ function onBLEConnectionStateChange (callback) {
return ENV_OBJ.onBLEConnectionStateChanged(callback)
}

function offBLEConnectionStateChange (callback) {
return ENV_OBJ.offBLEConnectionStateChanged(callback)
}

const openBluetoothAdapter = ENV_OBJ.openBluetoothAdapter || envError('openBluetoothAdapter')

const closeBluetoothAdapter = ENV_OBJ.closeBluetoothAdapter || envError('closeBluetoothAdapter')

const startBluetoothDevicesDiscovery = ENV_OBJ.startBluetoothDevicesDiscovery || envError('startBluetoothDevicesDiscovery')

const stopBluetoothDevicesDiscovery = ENV_OBJ.stopBluetoothDevicesDiscovery || envError('stopBluetoothDevicesDiscovery')

const onBluetoothDeviceFound = ENV_OBJ.onBluetoothDeviceFound || envError('onBluetoothDeviceFound')

const offBluetoothDeviceFound = ENV_OBJ.offBluetoothDeviceFound || envError('offBluetoothDeviceFound')

const getConnectedBluetoothDevices = ENV_OBJ.getConnectedBluetoothDevices || envError('getConnectedBluetoothDevices')

const getBluetoothAdapterState = ENV_OBJ.getBluetoothAdapterState || envError('getBluetoothAdapterState')

const onBluetoothAdapterStateChange = ENV_OBJ.onBluetoothAdapterStateChange || envError('onBluetoothAdapterStateChange')

const offBluetoothAdapterStateChange = ENV_OBJ.offBluetoothAdapterStateChange || envError('offBluetoothAdapterStateChange')

const getBluetoothDevices = ENV_OBJ.getBluetoothDevices || envError('getBluetoothDevices')

const writeBLECharacteristicValue = ENV_OBJ.writeBLECharacteristicValue || envError('writeBLECharacteristicValue')

const readBLECharacteristicValue = ENV_OBJ.readBLECharacteristicValue || envError('readBLECharacteristicValue')

const notifyBLECharacteristicValueChange = ENV_OBJ.notifyBLECharacteristicValueChange || envError('notifyBLECharacteristicValueChange')

const onBLECharacteristicValueChange = ENV_OBJ.onBLECharacteristicValueChange || envError('onBLECharacteristicValueChange')

const offBLECharacteristicValueChange = ENV_OBJ.offBLECharacteristicValueChange || envError('offBLECharacteristicValueChange')

const setBLEMTU = ENV_OBJ.setBLEMTU || envError('setBLEMTU')

const getBLEDeviceRSSI = ENV_OBJ.getBLEDeviceRSSI || envError('getBLEDeviceRSSI')

const getBLEDeviceServices = ENV_OBJ.getBLEDeviceServices || envError('getBLEDeviceServices')

const getBLEDeviceCharacteristics = ENV_OBJ.getBLEDeviceCharacteristics || envError('getBLEDeviceCharacteristics')

export {
closeBLEConnection,
createBLEConnection,
onBLEConnectionStateChange
onBLEConnectionStateChange,
offBLEConnectionStateChange,
openBluetoothAdapter,
closeBluetoothAdapter,
startBluetoothDevicesDiscovery,
stopBluetoothDevicesDiscovery,
onBluetoothDeviceFound,
offBluetoothDeviceFound,
getConnectedBluetoothDevices,
getBluetoothAdapterState,
onBluetoothAdapterStateChange,
offBluetoothAdapterStateChange,
getBluetoothDevices,
writeBLECharacteristicValue,
readBLECharacteristicValue,
notifyBLECharacteristicValueChange,
onBLECharacteristicValueChange,
offBLECharacteristicValueChange,
setBLEMTU,
getBLEDeviceRSSI,
getBLEDeviceServices,
getBLEDeviceCharacteristics
}
Loading