p2p.connectDevice
建立 P2P 连接
需引入
P2PKit
,且在>=2.0.3
版本才可使用
Use in Ray
// @ray-js/ray >=1.3.15
import { p2p } from '@ray-js/ray';
const { connectDevice } = p2p;
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
deviceId | string | 是 | 设备 id | |
mode | number | 否 | 连接模式,0:INTERNET 1:LAN | |
timeout | number | 否 | 超时时长,单位:ms,设置 0 会设置成默认值,Internet:15000ms, Lan:3000ms | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
函数定义示例
/**
* 建立P2P连接
*/
export function connectDevice(params: {
/** 设备id */
deviceId: string;
/** 连接模式,0:INTERNET 1:LAN */
mode?: number;
/** 超时时长,单位:ms,设置0会设置成默认值,Internet:15000ms, Lan:3000ms */
timeout?: number;
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: () => void;
/** 接口调用成功的回调函数 */
success?: (params: null) => void;
/** 接口调用失败的回调函数 */
fail?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。
p2p.disconnectDevice
和设备断开连接
需引入
P2PKit
,且在>=2.0.3
版本才可使用
Use in Ray
// @ray-js/ray >=1.3.15
import { p2p } from '@ray-js/ray';
const { disconnectDevice } = p2p;
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
deviceId | string | 是 | 设备 id | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
函数定义示例
/**
* 和设备断开连接
*/
export function disconnectDevice(params: {
/** 设备id */
deviceId: string;
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: () => void;
/** 接口调用成功的回调函数 */
success?: (params: null) => void;
/** 接口调用失败的回调函数 */
fail?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
p2p.uploadFile
P2P 上传文件
需引入
P2PKit
,且在>=2.0.3
版本才可使用
Use in Ray
// @ray-js/ray >=1.3.15
import { p2p } from '@ray-js/ray';
const { uploadFile } = p2p;
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
deviceId | string | 是 | 设备 id | |
albumName | string | 是 | albumName 和设备端约定字段 | |
filePath | string | 是 | 文件本地路径 | |
extData | string | 否 | 扩展字段 | |
extDataLength | number | 否 | 扩展字段长度 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
函数定义示例
/**
* P2P上传文件
*/
export function uploadFile(params: {
/** 设备id */
deviceId: string;
/** albumName 和设备端约定字段 */
albumName: string;
/** 文件本地路径 */
filePath: string;
/** 扩展字段 */
extData?: string;
/** 扩展字段长度 */
extDataLength?: number;
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: () => void;
/** 接口调用成功的回调函数 */
success?: (params: null) => void;
/** 接口调用失败的回调函数 */
fail?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。