3.18 患者端

This commit is contained in:
zoujiandong
2024-03-18 16:43:38 +08:00
parent faa8070ec3
commit 43153c15a7
102 changed files with 4477 additions and 357 deletions
@@ -0,0 +1,34 @@
import { NAME } from '../../const/index';
/**
* 装饰器:阻止函数重复调用
* @export
* @param {Object} options 入参
* @param {Function} options.fn 函数
* @param {Object} options.context 上下文对象
* @param {String} options.name 函数名
* @returns {Function} 封装后的函数
*/
export function avoidRepeatedCall() {
return function (target: any, name: string, descriptor: any) {
const oldFn = descriptor.value;
const isCallingSet = new Set();
descriptor.value = async function (...args: any[]) {
if (isCallingSet.has(this)) {
console.warn((`${NAME.PREFIX}previous ${name}() is ongoing, please avoid repeated calls`));
// throw new Error(`previous ${name}() is ongoing, please avoid repeated calls`);
return;
}
try {
isCallingSet.add(this);
const result = await oldFn.apply(this, args);
isCallingSet.delete(this);
return result;
} catch (error) {
isCallingSet.delete(this);
throw error;
}
};
return descriptor;
};
}
@@ -0,0 +1,11 @@
import { avoidRepeatedCall } from './avoidRepeatedCall';
import { paramValidate } from './validateParams';
import { VALIDATE_PARAMS } from './validateConfig';
// import { apiCallQueue } from "./apiCallQueue";
export {
VALIDATE_PARAMS,
paramValidate,
avoidRepeatedCall,
// apiCallQueue,
};
@@ -0,0 +1,188 @@
import { NAME, MAX_NUMBER_ROOM_ID, VideoResolution, VideoDisplayMode } from "../../const/index";
export const VALIDATE_PARAMS = {
init: {
SDKAppID: {
required: true,
rules: [NAME.NUMBER],
allowEmpty: false,
},
userID: {
required: true,
rules: [NAME.STRING],
allowEmpty: false,
},
userSig: {
required: true,
rules: [NAME.STRING],
allowEmpty: false,
},
tim: {
required: false,
rules: [NAME.OBJECT],
},
},
call: {
userID: {
required: true,
rules: [NAME.STRING],
allowEmpty: false
},
type: {
required: true,
rules: [NAME.NUMBER],
range: [1, 2],
allowEmpty: false
},
roomID: {
required: false,
rules: [NAME.NUMBER], // 仅支持数字房间号, 后续会支持字符串房间号
range: `1~${MAX_NUMBER_ROOM_ID}`,
allowEmpty: false,
},
userData: {
required: false,
rules: [NAME.STRING],
allowEmpty: false,
},
timeout: {
required: false,
rules: [NAME.NUMBER],
allowEmpty: false
}
},
groupCall: {
userIDList: {
required: true,
rules: [NAME.ARRAY],
allowEmpty: false
},
type: {
required: true,
rules: [NAME.NUMBER],
range: [1, 2],
allowEmpty: false
},
groupID: {
required: true,
rules: [NAME.STRING],
allowEmpty: false
},
roomID: {
required: false,
rules: [NAME.NUMBER], // 仅支持数字房间号, 后续会支持字符串房间号
range: `1~${MAX_NUMBER_ROOM_ID}`,
allowEmpty: false
},
timeout: {
required: false,
rules: [NAME.NUMBER],
allowEmpty: false
},
userData: {
required: false,
rules: [NAME.STRING],
allowEmpty: false,
},
offlinePushInfo: {
required: false,
rules: [NAME.OBJECT],
allowEmpty: false,
},
},
joinInGroupCall: {
type: {
required: true,
rules: [NAME.NUMBER],
range: [1, 2],
allowEmpty: false
},
groupID: {
required: true,
rules: [NAME.STRING],
allowEmpty: false
},
roomID: {
required: true,
rules: [NAME.NUMBER],
allowEmpty: false,
},
},
inviteUser: {
userIDList: {
required: true,
rules: [NAME.ARRAY],
allowEmpty: false
},
},
setSelfInfo: {
nickName: {
required: false,
rules: [NAME.STRING],
allowEmpty: false,
},
avatar: {
required: false,
rules: [NAME.STRING],
allowEmpty: false,
}
},
enableFloatWindow: [
{
key: "enable",
required: false,
rules: [NAME.BOOLEAN],
allowEmpty: false,
}
],
enableAIVoice: [
{
key: "enable",
required: true,
rules: [NAME.BOOLEAN],
allowEmpty: false,
}
],
enableMuteMode: [
{
key: "enable",
required: true,
rules: [NAME.BOOLEAN],
allowEmpty: false,
}
],
setCallingBell: [
{
key: "filePath",
required: false,
rules: [NAME.STRING],
allowEmpty: true,
}
],
setLanguage: [
{
key: "language",
required: true,
rules: [NAME.STRING],
allowEmpty: false
}
],
setVideoDisplayMode: [
{
key: "displayMode",
required: true,
rules: [NAME.STRING],
range: [VideoDisplayMode.CONTAIN, VideoDisplayMode.COVER, VideoDisplayMode.FILL],
allowEmpty: false
}
],
setVideoResolution: [
{
key: "resolution",
required: true,
rules: [NAME.STRING],
range: [VideoResolution.RESOLUTION_1080P, VideoResolution.RESOLUTION_480P, VideoResolution.RESOLUTION_720P],
allowEmpty: false
}
]
};
@@ -0,0 +1,88 @@
import { getType, isArray, isString, isUndefined, isNumber, modifyObjectKey } from "../common-utils";
import { NAME } from "../../const/index";
const PREFIX = NAME.PREFIX + "API";
export function paramValidate (config: any) {
return function (target, propertyName: string, descriptor: PropertyDescriptor) {
let method = descriptor.value;
descriptor.value = function (...args) {
doValidate.call(this, config, args, propertyName);
return method.apply(this, args);
};
return descriptor;
};
}
function doValidate(config, args, name) {
try {
// 兼容 init 方法中: SDKAppID sdkAppID 两种写法的参数校验判断
if (!args[0].SDKAppID) {
config = modifyObjectKey(config, "SDKAppID", "sdkAppID");
}
if (isArray(config)) {
for (let i = 0; i < config.length; i++) {
check.call(this, {
...config[i],
value: args[i],
name,
});
}
} else {
for (const key in config) {
if (config.hasOwnProperty(key)) {
check.call(this, {
...config[key],
value: args[0][key],
name,
key,
});
}
}
}
} catch (error) {
console.error(error);
throw error;
}
}
function check({ required, rules, range, value, allowEmpty, name, key }) {
// 用户没传指定参数
if (isUndefined(value)) {
// 检查必填参数, 若配置是必填则报错
if (required) {
throw new Error(`${PREFIX}<${name}>: ${key} is required.`);
} else {
return;
}
}
// 判断参数类型是否正确
const result = rules.some((item)=>item === getType(value));
let type = '';
if (!result) {
for (let i = 0; i < rules.length; i++) {
let str = rules[i];
str = str.replace(str[0], str[0].toUpperCase());
type += `${str}/`;
}
type = type.substring(0, type.length - 1);
throw new Error(`${PREFIX}<${name}>: ${key} must be ${type}, current ${key} is ${typeof value}.`);
}
// 不允许传空值, 例如: '', ' '
if (allowEmpty === false) {
const isEmptyString = isString(value) && value.trim() === '';
if (isEmptyString) {
throw new Error(`${PREFIX}<${name}>: ${key} is blank.`);
}
}
// 判断是否符合限制条件
if (isArray(range)) {
if (range && range.indexOf(value) === -1) {
throw new Error(`${PREFIX}<${name}>: ${key} error, only be ${range}, current ${key} is ${value}.`);
}
}
// 取值范围, 前闭后闭
if (isString(range) && range.indexOf('~') !== -1) {
const valueList = range.split('~');
if (value < +valueList[0] || value > +valueList[1] || (isNumber(value) && Number.isNaN(value))) {
throw new Error(`${PREFIX}<${name}>: ${key} error, only be ${range}, current ${key} is ${value}.`);
}
}
}