提交 4ce655e2 编写于 作者: 杜庆泉's avatar 杜庆泉

wifi 适配 uni error.

上级 dcfa32bb
declare namespace UniNamespace {
type UniWifiComplete = any
type WifiSuccessCallback = (res : UniWifiResult) => void
type WifiFailCallback = (err : UniWifiFail) => void
type WifiCompleteCallback = (res : UniWifiComplete) => void
type UniWifiCallback = () => void
type WifiErrorCode = 1300002
interface UniWifiInfo {
SSID : string;
BSSID ?: string;
secure ?: boolean;
signalStrength ?: number;
frequency ?: number;
}
interface UniWifiResult {
errCode : number,
errSubject : string,
errMsg : string,
wifi : UniWifiInfo | null
}
interface UniWifiFail {
errCode : WifiErrorCode
}
interface WifiConnectOption{
SSID : string | null;
BSSID : string | null;
password : string | null;
maunal : boolean | null;
partialInfo : boolean | null; //ios不生效
success ?: WifiSuccessCallback | null;
fail ?: WifiFailCallback | null;
complete ?: WifiCompleteCallback | null;
}
interface GetConnectedWifiOptions {
partialInfo : boolean | null;
success ?: WifiSuccessCallback | null;
fail ?: WifiFailCallback | null;
complete ?: WifiCompleteCallback | null;
}
interface WifiOption {
success ?: WifiSuccessCallback | null,
fail ?: WifiFailCallback | null,
complete ?: InstallApkCompleteCallback | null
}
}
declare interface Uni {
/**
* 初始化Wi-Fi模块
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#startwifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { after: 'stopWifi' }
*/
startWifi(option : UniNamespace.WifiOption): void,
/**
* 关闭 Wi-Fi 模块
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#stopwifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi' }
*/
stopWifi(option : UniNamespace.WifiOption) : void,
/**
* @param {WifiConnectOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": ">=4.4 && <10.0",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest {
generated: false,
pollution: false,
cases:[
{
before: 'startWifi',
after: 'stopWifi',
input: [{
maunal:false,
SSID:"Xiaomi_20D0",
password:"streamApp!2016",
}],
output:{
callbackType: 'success',
value: { errCode: 12013 ,errMsg: "connectWifi:wifi config may be expired",errSubject: "uni-connectWifi"}
}
}
]
}
*/
connectWifi(option : UniNamespace.WifiConnectOption) : void,
/**
* 请求获取 Wi-Fi 列表。wifiList 数据会在 onGetWifiList 注册的回调中返回。
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getWifiList
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi', after: 'stopWifi' }
*/
getWifiList(option : UniNamespace.WifiOption) : void,
/**
* 监听获取到 Wi-Fi 列表数据事件。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onGetWifiList
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
* @autotest {
generated: false,
pollution: false,
expectCallback: true,
before: 'startWifi',
after: 'onGetWifiListAfter',
cases: [
{
output: {
value: 0,
returnKey: '.wifiList.length',
jestExpectSyntax: 'toBeGreaterThan'
},
}
]
}
*/
onGetWifiList(callback : UniNamespace.UniWifiCallback) : void,
/**
* 移除获取到 Wi-Fi 列表数据事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offGetWifiList
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offGetWifiList(callback : UniNamespace.UniWifiCallback) : void,
/**
* 获取已连接的 Wi-Fi 信息
*
* @param {GetConnectedWifiOptions} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getConnectedWifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi', after: 'stopWifi' }
*/
getConnectedWifi(option : UniNamespace.GetConnectedWifiOptions) : void,
/**
* 监听连接上 Wi-Fi 的事件
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnected
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onWifiConnected(callback : UniNamespace.UniWifiCallback) : void,
/**
* 监听连接上 Wi-Fi 的事件。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onWifiConnectedWithPartialInfo(callback : UniNamespace.UniWifiCallback) : void,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnected
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offWifiConnected(callback ?: UniNamespace.UniWifiCallback) : void,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onOffWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onOffWifiConnectedWithPartialInfo(callback ?: UniNamespace.UniWifiCallback) : void,
/**
* SetWifiList 暂未实现
*
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* }
*/
setWifiList(option : UniNamespace.WifiOption) : void,
}
......@@ -8,7 +8,7 @@ export type WifiOption = {
};
/**
* Wifi 链接参数封装
* Wifi 链接参数封装
*/
export type WifiConnectOption = {
SSID ?: string;
......@@ -31,7 +31,7 @@ export type GetConnectedWifiOptions = {
complete ?: (res : any) => void
}
/*
/*
* 对外暴露的wifi信息
*/
export type UniWifiInfo = {
......@@ -42,6 +42,10 @@ export type UniWifiInfo = {
frequency ?: number;
}
export type UniWifiInfoWithPartialInfo = {
SSID : string;
}
export type UniWifiResult = {
errCode : number,
......@@ -52,6 +56,12 @@ export type UniWifiResult = {
export type UniWifiCallback = () => void
export type UniGetWifiListCallback = (wifiInfo:UTSJSONObject) => void
export type UniWifiResultCallback = (wifiInfo:UniWifiResult) => void
export type UniWifiResultCallbackWithPartialInfo = (wifiInfo:UniWifiInfoWithPartialInfo) => void
export type StartWifi = (option : WifiOption) => void
......@@ -77,11 +87,30 @@ export type OnOffWifiConnectedWithPartialInfo = (callback : UniWifiCallback | nu
export type SetWifiList = (option : WifiOption) => void
/**
* 错误码
* - 12000 尚未初始化
* - 12001 当前系统不支持相关能力
* - 12002 密码错误
* - 12005 Android 特有,未打开 Wi-Fi 开关
* - 12007 用户拒绝授权链接 Wi-Fi
* - 12010 系统其他错误
* - 12013 系统保存的 Wi-Fi 配置过期,建议忘记 Wi-Fi 后重试,仅 Android 支持
*/
export type WifiErrorCode = 12000 |12001 | 12002 | 12005 | 12007 | 12010 | 12013;
export interface WifiFail extends IUniError{
errCode: WifiErrorCode
};
interface Uni {
/**
* 初始化Wi-Fi模块
*
* @param {WifiOption} option
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#startwifi
* @uniPlatform {
* "app": {
......@@ -104,8 +133,8 @@ interface Uni {
startWifi(option : WifiOption): void,
/**
* 关闭 Wi-Fi 模块
*
* @param {WifiOption} option
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#stopwifi
* @uniPlatform {
* "app": {
......@@ -127,7 +156,7 @@ interface Uni {
*/
stopWifi(option : WifiOption) : void,
/**
* @param {WifiConnectOption} option
* @param {WifiConnectOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi
* @uniPlatform {
* "app": {
......@@ -191,8 +220,8 @@ interface Uni {
getWifiList(option : WifiOption) : void,
/**
* 监听获取到 Wi-Fi 列表数据事件。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onGetWifiList
* @uniPlatform {
* "app": {
......@@ -231,8 +260,8 @@ interface Uni {
onGetWifiList(callback : UniWifiCallback) : void,
/**
* 移除获取到 Wi-Fi 列表数据事件的监听函数。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offGetWifiList
* @uniPlatform {
* "app": {
......@@ -255,8 +284,8 @@ interface Uni {
offGetWifiList(callback : UniWifiCallback) : void,
/**
* 获取已连接的 Wi-Fi 信息
*
* @param {GetConnectedWifiOptions} option
*
* @param {GetConnectedWifiOptions} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getConnectedWifi
* @uniPlatform {
* "app": {
......@@ -279,8 +308,8 @@ interface Uni {
getConnectedWifi(option : GetConnectedWifiOptions) : void,
/**
* 监听连接上 Wi-Fi 的事件
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnected
* @uniPlatform {
* "app": {
......@@ -303,8 +332,8 @@ interface Uni {
onWifiConnected(callback : UniWifiCallback) : void,
/**
* 监听连接上 Wi-Fi 的事件。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
......@@ -327,8 +356,8 @@ interface Uni {
onWifiConnectedWithPartialInfo(callback : UniWifiCallback) : void,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnected
* @uniPlatform {
* "app": {
......@@ -351,8 +380,8 @@ interface Uni {
offWifiConnected(callback : UniWifiCallback | null) : void,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onOffWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
......@@ -375,7 +404,7 @@ interface Uni {
onOffWifiConnectedWithPartialInfo(callback : UniWifiCallback | null) : void,
/**
* SetWifiList 暂未实现
*
*
* @uniPlatform {
* "app": {
* "android": {
......@@ -392,4 +421,4 @@ interface Uni {
* }
*/
setWifiList(option : WifiOption) : void,
}
\ No newline at end of file
}
import { WifiErrorCode, WifiFail} from "./interface.uts"
/**
* 错误主题
*/
export const UniErrorSubject = 'uni-wifi';
/**
* 错误码
* @UniError
*/
export const WifiUniErrors : Map<WifiErrorCode, string> = new Map([
/**
* 未先调用 startWifi 接口
*/
[12000, 'not init.'],
/**
* 当前系统不支持相关能力
*/
[12001, 'system not support'],
/**
* 密码错误
*/
[12002, 'password error Wi-Fi'],
/**
* Android 特有,未打开 Wi-Fi 开关
*/
[12005, 'wifi not turned on'],
/**
* 用户拒绝授权链接 Wi-Fi
*/
[12007, 'user denied'],
/**
* 系统其他错误,需要在 errmsg 打印具体的错误原因
*/
[12010, 'unknown error'],
/**
* 系统保存的 Wi-Fi 配置过期,建议忘记 Wi-Fi 后重试,仅 Android 支持
*/
[12013, 'wifi config may be expired'],
]);
export function getErrcode(errCode : number) : WifiErrorCode {
const res = WifiUniErrors[errCode];
return res == null ? 12000 : errCode;
}
export class WifiFailImpl extends UniError implements WifiFail {
constructor(errCode : WifiErrorCode) {
super();
this.errSubject = UniErrorSubject;
this.errCode = errCode;
this.errMsg = WifiUniErrors[errCode] ?? "";
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册