Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
09db687b
U
uni-app
项目概览
MuGuiLin
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
09db687b
编写于
6月 23, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(App): bluetooth-BLE
上级
d9bd4cd2
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
383 addition
and
5 deletion
+383
-5
packages/uni-api/src/index.ts
packages/uni-api/src/index.ts
+1
-0
packages/uni-api/src/protocols/device/bluetooth.ts
packages/uni-api/src/protocols/device/bluetooth.ts
+172
-0
packages/uni-app-plus/src/helpers/plus.ts
packages/uni-app-plus/src/helpers/plus.ts
+36
-5
packages/uni-app-plus/src/service/api/device/bluetooth.ts
packages/uni-app-plus/src/service/api/device/bluetooth.ts
+173
-0
packages/uni-app-plus/src/service/api/index.ts
packages/uni-app-plus/src/service/api/index.ts
+1
-0
未找到文件。
packages/uni-api/src/index.ts
浏览文件 @
09db687b
...
...
@@ -27,6 +27,7 @@ export * from './protocols/device/setClipboardData'
export
*
from
'
./protocols/device/accelerometer
'
export
*
from
'
./protocols/device/compass
'
export
*
from
'
./protocols/device/vibrate
'
export
*
from
'
./protocols/device/bluetooth
'
export
*
from
'
./protocols/storage/storage
'
...
...
packages/uni-api/src/protocols/device/bluetooth.ts
0 → 100644
浏览文件 @
09db687b
export
const
API_ON_BLUETOOTH_DEVICE_FOUND
=
'
onBluetoothDeviceFound
'
export
type
API_TYPE_ON_BLUETOOTH_DEVICE_FOUND
=
typeof
uni
.
onBluetoothDeviceFound
export
const
API_ON_BLUETOOTH_ADAPTER_STATE_CHANGE
=
'
onBluetoothAdapterStateChange
'
export
type
API_TYPE_ON_BLUETOOTH_ADAPTER_STATE_CHANGE
=
typeof
uni
.
onBluetoothAdapterStateChange
export
const
API_ON_BLE_CONNECTION_STATE_CHANGE
=
'
onBLEConnectionStateChange
'
export
type
API_TYPE_ON_BLE_CONNECTION_STATE_CHANGE
=
typeof
uni
.
onBLEConnectionStateChange
export
const
API_ON_BLE_CHARACTERISTIC_VALUE_CHANGE
=
'
onBLECharacteristicValueChange
'
export
type
API_TYPE_ON_BLE_CHARACTERISTIC_VALUE_CHANGE
=
typeof
uni
.
onBLECharacteristicValueChange
export
const
API_START_BLUETOOTH_DEVICES_DISCOVERY
=
'
startBluetoothDevicesDiscovery
'
export
type
API_TYPE_START_BLUETOOTH_DEVICES_DISCOVERY
=
typeof
uni
.
startBluetoothDevicesDiscovery
export
const
StartBluetoothDevicesDiscoveryProtocol
:
ApiProtocol
<
API_TYPE_START_BLUETOOTH_DEVICES_DISCOVERY
>
=
{
services
:
Array
,
allowDuplicatesKey
:
Boolean
,
interval
:
Number
,
}
export
const
API_GET_CONNECTED_BLUETOOTH_DEVICES
=
'
getConnectedBluetoothDevices
'
export
type
API_TYPE_GET_CONNECTED_BLUETOOTH_DEVICES
=
typeof
uni
.
getConnectedBluetoothDevices
export
const
GetConnectedBluetoothDevicesProtocol
:
ApiProtocol
<
API_TYPE_GET_CONNECTED_BLUETOOTH_DEVICES
>
=
{
services
:
{
type
:
Array
,
required
:
true
,
},
}
export
const
API_CREATE_BLE_CONNECTION
=
'
createBLEConnection
'
export
type
API_TYPE_CREATE_BLE_CONNECTION
=
typeof
uni
.
createBLEConnection
export
const
CreateBLEConnectionProtocol
:
ApiProtocol
<
API_TYPE_CREATE_BLE_CONNECTION
>
=
{
deviceId
:
{
type
:
String
,
required
:
true
,
},
}
export
const
API_CLOSE_BLE_CONNECTION
=
'
closeBLEConnection
'
export
type
API_TYPE_CLOSE_BLE_CONNECTION
=
typeof
uni
.
closeBLEConnection
export
const
CloseBLEConnectionProtocol
:
ApiProtocol
<
API_TYPE_CLOSE_BLE_CONNECTION
>
=
{
deviceId
:
{
type
:
String
,
required
:
true
,
},
}
export
const
API_GET_BLE_DEVICE_SERVICES
=
'
getBLEDeviceServices
'
export
type
API_TYPE_GET_BLE_DEVICE_SERVICES
=
typeof
uni
.
getBLEDeviceServices
export
const
GetBLEDeviceServicesProtocol
:
ApiProtocol
<
API_TYPE_GET_BLE_DEVICE_SERVICES
>
=
{
deviceId
:
{
type
:
String
,
required
:
true
,
},
}
export
const
API_GET_BLE_DEVICE_CHARACTERISTICS
=
'
getBLEDeviceCharacteristics
'
export
type
API_TYPE_GET_BLE_DEVICE_CHARACTERISTICS
=
typeof
uni
.
getBLEDeviceCharacteristics
export
const
GetBLEDeviceCharacteristicsProtocol
:
ApiProtocol
<
API_TYPE_GET_BLE_DEVICE_CHARACTERISTICS
>
=
{
deviceId
:
{
type
:
String
,
required
:
true
,
},
serviceId
:
{
type
:
String
,
required
:
true
,
},
}
export
const
API_NOTIFY_BLE_CHARACTERISTIC_VALUE_CHANGE
=
'
notifyBLECharacteristicValueChange
'
export
type
API_TYPE_NOTIFY_BLE_CHARACTERISTIC_VALUE_CHANGE
=
typeof
uni
.
notifyBLECharacteristicValueChange
export
const
NotifyBLECharacteristicValueChangeProtocol
:
ApiProtocol
<
API_TYPE_NOTIFY_BLE_CHARACTERISTIC_VALUE_CHANGE
>
=
{
deviceId
:
{
type
:
String
,
required
:
true
,
},
serviceId
:
{
type
:
String
,
required
:
true
,
},
characteristicId
:
{
type
:
String
,
required
:
true
,
},
state
:
{
type
:
Boolean
,
required
:
true
,
},
}
export
const
API_READ_BLE_CHARACTERISTIC_VALUE
=
'
readBLECharacteristicValue
'
export
type
API_TYPE_READ_BLE_CHARACTERISTIC_VALUE
=
typeof
uni
.
readBLECharacteristicValue
export
const
ReadBLECharacteristicValueProtocol
:
ApiProtocol
<
API_TYPE_READ_BLE_CHARACTERISTIC_VALUE
>
=
{
deviceId
:
{
type
:
String
,
required
:
true
,
},
serviceId
:
{
type
:
String
,
required
:
true
,
},
characteristicId
:
{
type
:
String
,
required
:
true
,
},
}
export
const
API_WRITE_BLE_CHARACTERISTIC_VALUE
=
'
writeBLECharacteristicValue
'
export
type
API_TYPE_WRITE_BLE_CHARACTERISTIC_VALUE
=
typeof
uni
.
writeBLECharacteristicValue
export
const
WriteBLECharacteristicValueProtocol
:
ApiProtocol
<
API_TYPE_WRITE_BLE_CHARACTERISTIC_VALUE
>
=
{
deviceId
:
{
type
:
String
,
required
:
true
,
},
serviceId
:
{
type
:
String
,
required
:
true
,
},
characteristicId
:
{
type
:
String
,
required
:
true
,
},
value
:
{
type
:
Array
,
required
:
true
,
},
}
export
const
API_SET_BLE_MTU
=
'
setBLEMTU
'
export
type
API_TYPE_SET_BLE_MTU
=
typeof
uni
.
setBLEMTU
export
const
SetBLEMTUProtocol
:
ApiProtocol
<
API_TYPE_SET_BLE_MTU
>
=
{
deviceId
:
{
type
:
String
,
required
:
true
,
},
mtu
:
{
type
:
Number
,
required
:
true
,
},
}
export
const
API_GET_BLE_DEVICE_RSSI
=
'
getBLEDeviceRSSI
'
export
type
API_TYPE_GET_BLE_DEVICE_RSSI
=
typeof
uni
.
getBLEDeviceRSSI
export
const
GetBLEDeviceRSSIProtocol
:
ApiProtocol
<
API_TYPE_GET_BLE_DEVICE_RSSI
>
=
{
deviceId
:
{
type
:
String
,
required
:
true
,
},
}
packages/uni-app-plus/src/helpers/plus.ts
浏览文件 @
09db687b
...
...
@@ -5,9 +5,11 @@ interface PlusResult extends Record<string, any> {
}
type
PlusError
=
PlusResult
type
Resolve
=
(
res
:
any
)
=>
void
type
Reject
=
(
errMsg
:
string
,
errRes
?:
any
)
=>
void
export
function
warpPlusSuccessCallback
(
resolve
:
(
res
:
any
)
=>
void
,
resolve
:
Resolve
,
after
?:
(
res
:
any
)
=>
any
)
{
return
function
successCallback
(
data
:
PlusResult
)
{
...
...
@@ -20,10 +22,7 @@ export function warpPlusSuccessCallback(
}
}
export
function
warpPlusErrorCallback
(
reject
:
(
errMsg
:
string
,
errRes
?:
any
)
=>
void
,
errMsg
?:
string
)
{
export
function
warpPlusErrorCallback
(
reject
:
Reject
,
errMsg
?:
string
)
{
return
function
errorCallback
(
error
?:
PlusError
)
{
error
=
error
||
{}
// 一键登录errorCallback新增 appid、metadata、uid 参数返回
...
...
@@ -32,3 +31,35 @@ export function warpPlusErrorCallback(
reject
(
errMsg
,
extend
({
code
:
0
},
error
))
}
}
export
function
warpPlusEvent
(
plusObject
:
()
=>
any
,
event
:
string
)
{
return
function
()
{
const
object
=
plusObject
()
object
(
function
(
data
?:
Record
<
string
,
any
>
)
{
if
(
data
)
{
delete
data
.
code
delete
data
.
message
}
UniServiceJSBridge
.
invokeOnCallback
(
event
,
data
)
})
}
}
export
function
warpPlusMethod
(
plusObject
:
()
=>
any
,
before
?:
(
options
:
any
)
=>
any
,
after
?:
(
res
:
any
)
=>
any
)
{
return
function
(
options
:
any
,
{
resolve
,
reject
}:
{
resolve
:
Resolve
;
reject
:
Reject
}
)
{
const
object
=
plusObject
()
object
(
extend
({},
typeof
before
===
'
function
'
?
before
(
options
)
:
options
,
{
success
:
warpPlusSuccessCallback
(
resolve
,
after
),
fail
:
warpPlusErrorCallback
(
reject
),
})
)
}
}
packages/uni-app-plus/src/service/api/device/bluetooth.ts
0 → 100644
浏览文件 @
09db687b
import
{
defineOnApi
,
API_ON_BLUETOOTH_DEVICE_FOUND
,
API_TYPE_ON_BLUETOOTH_DEVICE_FOUND
,
API_ON_BLUETOOTH_ADAPTER_STATE_CHANGE
,
API_TYPE_ON_BLUETOOTH_ADAPTER_STATE_CHANGE
,
API_ON_BLE_CONNECTION_STATE_CHANGE
,
API_TYPE_ON_BLE_CONNECTION_STATE_CHANGE
,
API_ON_BLE_CHARACTERISTIC_VALUE_CHANGE
,
API_TYPE_ON_BLE_CHARACTERISTIC_VALUE_CHANGE
,
defineAsyncApi
,
API_START_BLUETOOTH_DEVICES_DISCOVERY
,
API_TYPE_START_BLUETOOTH_DEVICES_DISCOVERY
,
StartBluetoothDevicesDiscoveryProtocol
,
API_GET_CONNECTED_BLUETOOTH_DEVICES
,
API_TYPE_GET_CONNECTED_BLUETOOTH_DEVICES
,
GetConnectedBluetoothDevicesProtocol
,
API_CREATE_BLE_CONNECTION
,
API_TYPE_CREATE_BLE_CONNECTION
,
CreateBLEConnectionProtocol
,
API_CLOSE_BLE_CONNECTION
,
API_TYPE_CLOSE_BLE_CONNECTION
,
CloseBLEConnectionProtocol
,
API_GET_BLE_DEVICE_SERVICES
,
API_TYPE_GET_BLE_DEVICE_SERVICES
,
GetBLEDeviceServicesProtocol
,
API_GET_BLE_DEVICE_CHARACTERISTICS
,
API_TYPE_GET_BLE_DEVICE_CHARACTERISTICS
,
GetBLEDeviceCharacteristicsProtocol
,
API_NOTIFY_BLE_CHARACTERISTIC_VALUE_CHANGE
,
API_TYPE_NOTIFY_BLE_CHARACTERISTIC_VALUE_CHANGE
,
NotifyBLECharacteristicValueChangeProtocol
,
API_READ_BLE_CHARACTERISTIC_VALUE
,
API_TYPE_READ_BLE_CHARACTERISTIC_VALUE
,
ReadBLECharacteristicValueProtocol
,
API_WRITE_BLE_CHARACTERISTIC_VALUE
,
API_TYPE_WRITE_BLE_CHARACTERISTIC_VALUE
,
WriteBLECharacteristicValueProtocol
,
API_SET_BLE_MTU
,
API_TYPE_SET_BLE_MTU
,
SetBLEMTUProtocol
,
API_GET_BLE_DEVICE_RSSI
,
API_TYPE_GET_BLE_DEVICE_RSSI
,
GetBLEDeviceRSSIProtocol
,
}
from
'
@dcloudio/uni-api
'
import
{
warpPlusEvent
,
warpPlusMethod
}
from
'
../../../helpers/plus
'
export
const
onBluetoothDeviceFound
=
defineOnApi
<
API_TYPE_ON_BLUETOOTH_DEVICE_FOUND
>
(
API_ON_BLUETOOTH_DEVICE_FOUND
,
warpPlusEvent
(
()
=>
plus
.
bluetooth
.
onBluetoothDeviceFound
,
API_ON_BLUETOOTH_DEVICE_FOUND
)
)
export
const
onBluetoothAdapterStateChange
=
defineOnApi
<
API_TYPE_ON_BLUETOOTH_ADAPTER_STATE_CHANGE
>
(
API_ON_BLUETOOTH_ADAPTER_STATE_CHANGE
,
warpPlusEvent
(
()
=>
plus
.
bluetooth
.
onBluetoothAdapterStateChange
,
API_ON_BLUETOOTH_ADAPTER_STATE_CHANGE
)
)
export
const
onBLEConnectionStateChange
=
defineOnApi
<
API_TYPE_ON_BLE_CONNECTION_STATE_CHANGE
>
(
API_ON_BLE_CONNECTION_STATE_CHANGE
,
warpPlusEvent
(
()
=>
plus
.
bluetooth
.
onBLEConnectionStateChange
,
API_ON_BLE_CONNECTION_STATE_CHANGE
)
)
export
const
onBLECharacteristicValueChange
=
defineOnApi
<
API_TYPE_ON_BLE_CHARACTERISTIC_VALUE_CHANGE
>
(
API_ON_BLE_CHARACTERISTIC_VALUE_CHANGE
,
warpPlusEvent
(
()
=>
plus
.
bluetooth
.
onBLECharacteristicValueChange
,
API_ON_BLE_CHARACTERISTIC_VALUE_CHANGE
)
)
export
const
openBluetoothAdapter
=
defineAsyncApi
<
typeof
uni
.
openBluetoothAdapter
>
(
'
openBluetoothAdapter
'
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
openBluetoothAdapter
)
)
export
const
closeBluetoothAdapter
=
defineAsyncApi
<
typeof
uni
.
closeBluetoothAdapter
>
(
'
closeBluetoothAdapter
'
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
closeBluetoothAdapter
)
)
export
const
getBluetoothAdapterState
=
defineAsyncApi
<
typeof
uni
.
getBluetoothAdapterState
>
(
'
getBluetoothAdapterState
'
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
getBluetoothAdapterState
)
)
export
const
startBluetoothDevicesDiscovery
=
defineAsyncApi
<
API_TYPE_START_BLUETOOTH_DEVICES_DISCOVERY
>
(
API_START_BLUETOOTH_DEVICES_DISCOVERY
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
startBluetoothDevicesDiscovery
),
StartBluetoothDevicesDiscoveryProtocol
)
export
const
stopBluetoothDevicesDiscovery
=
defineAsyncApi
<
typeof
uni
.
stopBluetoothDevicesDiscovery
>
(
'
stopBluetoothDevicesDiscovery
'
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
stopBluetoothDevicesDiscovery
)
)
export
const
getBluetoothDevices
=
defineAsyncApi
<
typeof
uni
.
getBluetoothDevices
>
(
'
getBluetoothDevices
'
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
getBluetoothDevices
)
)
export
const
getConnectedBluetoothDevices
=
defineAsyncApi
<
API_TYPE_GET_CONNECTED_BLUETOOTH_DEVICES
>
(
API_GET_CONNECTED_BLUETOOTH_DEVICES
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
getConnectedBluetoothDevices
),
GetConnectedBluetoothDevicesProtocol
)
export
const
createBLEConnection
=
defineAsyncApi
<
API_TYPE_CREATE_BLE_CONNECTION
>
(
API_CREATE_BLE_CONNECTION
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
createBLEConnection
),
CreateBLEConnectionProtocol
)
export
const
closeBLEConnection
=
defineAsyncApi
<
API_TYPE_CLOSE_BLE_CONNECTION
>
(
API_CLOSE_BLE_CONNECTION
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
closeBLEConnection
),
CloseBLEConnectionProtocol
)
export
const
getBLEDeviceServices
=
defineAsyncApi
<
API_TYPE_GET_BLE_DEVICE_SERVICES
>
(
API_GET_BLE_DEVICE_SERVICES
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
getBLEDeviceServices
),
GetBLEDeviceServicesProtocol
)
export
const
getBLEDeviceCharacteristics
=
defineAsyncApi
<
API_TYPE_GET_BLE_DEVICE_CHARACTERISTICS
>
(
API_GET_BLE_DEVICE_CHARACTERISTICS
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
getBLEDeviceCharacteristics
),
GetBLEDeviceCharacteristicsProtocol
)
export
const
notifyBLECharacteristicValueChange
=
defineAsyncApi
<
API_TYPE_NOTIFY_BLE_CHARACTERISTIC_VALUE_CHANGE
>
(
API_NOTIFY_BLE_CHARACTERISTIC_VALUE_CHANGE
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
notifyBLECharacteristicValueChange
),
NotifyBLECharacteristicValueChangeProtocol
)
export
const
readBLECharacteristicValue
=
defineAsyncApi
<
API_TYPE_READ_BLE_CHARACTERISTIC_VALUE
>
(
API_READ_BLE_CHARACTERISTIC_VALUE
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
readBLECharacteristicValue
),
ReadBLECharacteristicValueProtocol
)
export
const
writeBLECharacteristicValue
=
defineAsyncApi
<
API_TYPE_WRITE_BLE_CHARACTERISTIC_VALUE
>
(
API_WRITE_BLE_CHARACTERISTIC_VALUE
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
writeBLECharacteristicValue
),
WriteBLECharacteristicValueProtocol
)
export
const
setBLEMTU
=
defineAsyncApi
<
API_TYPE_SET_BLE_MTU
>
(
API_SET_BLE_MTU
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
setBLEMTU
),
SetBLEMTUProtocol
)
export
const
getBLEDeviceRSSI
=
defineAsyncApi
<
API_TYPE_GET_BLE_DEVICE_RSSI
>
(
API_GET_BLE_DEVICE_RSSI
,
warpPlusMethod
(()
=>
plus
.
bluetooth
.
getBLEDeviceRSSI
),
GetBLEDeviceRSSIProtocol
)
packages/uni-app-plus/src/service/api/index.ts
浏览文件 @
09db687b
...
...
@@ -4,6 +4,7 @@ export * from './file/getFileInfo'
export
*
from
'
./device/compass
'
export
*
from
'
./device/vibrate
'
export
*
from
'
./device/accelerometer
'
export
*
from
'
./device/bluetooth
'
export
*
from
'
./media/getImageInfo
'
export
*
from
'
./media/getVideoInfo
'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录