foreign-country-utils
v1.16.0
Published
// 初始化 const camera = new Camera({ containerCanvas: canvas, customVideoConfig: {}, // 自定义视频配置 customAudioConfig: {}, // 自定义声音配置 callBack: (e:Blob) => { // todo something } })
Downloads
329
Maintainers
Readme
如何使用?
安装、npm i foreign-country-utils / yarn add foreign-country-utils / pnpm add foreign-country-utils
Camera类可以使用摄像头(google内核),可以截图,录像,视频旋转,视频放大缩小等功能(放大缩小目前只支持容器为canvas)
Camera使用方法介绍
// 初始化
const camera = new Camera({
containerCanvas: canvas,
customVideoConfig: {}, // 自定义视频配置
customAudioConfig: {}, // 自定义声音配置
callBack: (e:Blob) => {
// todo something
}
})
camera.startVideoStream(); // 开启视频流
camera.startAudioStream(); // 开启语音流
camera.close(); // 停止画面但不停止录像
camera.show(); // 开始/继续展示画面
camera.startRecord(option:{}); // option:MediaRecorderOptions , 开始录制
camera.pauseRecord(isPause); // isPause:boolean(是否停止播放) , 暂停录制
camera.resumeRecord(); // 继续录制
camera.stopRecord(isClose); //isClose:boolean(是否关闭视频), 停止录制,可以关闭视频
camera.scale(ratio); //ratio:number = 1.1(和上一次相比放大倍数), 放大
camera.spin(angle); //angle:number = 45(和上一次旋转角度), 旋转
base64ToBuffer方法是将base64格式的文件转为buffer格式
base64ToBuffer介绍
const buffer = base64ToBuffer(base64String); base64String: string, base64字符串
createColor 随机生成16位的颜色
createColor 介绍
const color = createColor(); 16位颜色,如: #ff5645
Http 发送ajax请求类
Http 介绍
const http = new Http(baseURL,timeout);
// isUrlencoded为是否使用content-type为application/x-www-form-urlencoded,默认为false
const promiseObj = http.get<T>(url,data,{自定义配置},isUrlencoded) // get请求
const promiseObj = http.post<T>(url,data,{自定义配置},isUrlencoded) // post请求
const promiseObj = http.delete<T>(url,data,{自定义配置},isUrlencoded) // delete请求
const promiseObj = http.put<T>(url,data,{自定义配置},isUrlencoded) // put请求
const promiseObj = http.patch<T>(url,data,{自定义配置},isUrlencoded) // patch请求
const promiseObj = http.upload<T>(url,data:FormData,{自定义配置}) // post请求,发送文件(formdata类型)
const promiseObj = http.cancel((key?:string) // key为取消的是哪一次请求,不传则取消全部请求,并清空map
storage 方法是本地存储相关,可配置保存在session里面还是local里面
storage 介绍
const {get,set} = storage();
key: 取出的键名, toJson是否需要转成JSON对象,默认是,fromSession:是否从session取值,默认是
const obj: Record<string, T> | string | null = get<T>(key: string, toJson = true, fromSession = true);
key: 需要保存的键名, value要保存的值,toSession:是否存入session,默认是
const result: boolean = set(key: string, value: string | boolean | number | null | Record<string, unknown>, toSession = true);