UNPKG

zby-live-sdk

Version:

This is a live SDK for weclassroom.

165 lines (152 loc) 4.72 kB
/* * @Author: your name * @Date: 2020-07-31 14:53:37 * @LastEditTime: 2020-08-04 15:55:11 * @LastEditors: why * @Description: In User Settings Edit * @FilePath: \xinxiaoban_zego\zby_live_sdk\src\zby-av-sdk\device.js */ import { utilitiesExt } from '../config/config'; import defaultApi from '../default'; // 扩展标识 const extensionId = 'utilities_ext'; // rtc小班课=0;rtc大班课=1 const classType = 0; /** * @function 调用端提供的回调方法 * @param name:String 回调方法名 * @param args 回调参数 * @return Promise | void */ const callMethod = (name, args) => { // EM 是寄宿于端的,浏览器中并不存在,为防止报错需要先进行能力检测 if (EM) { return new Promise((resolve, reject) => { EM.CallMethod( extensionId, name, JSON.stringify({...args, classType}), (code, msg) => { defaultApi.writeLog(`${name} Code: ${code}\nMessage: ${msg}\nParams: ${JSON.stringify({...args, classType})}`); resolve({ code, msg }); } ); }); } }; /** * @function 加载 Zego 扩展 * @param extensionVersion:String 扩展版本号,必选 * @return Promise | void */ (function loadUtils() { // EM 是寄宿于端的,浏览器中并不存在,为防止报错需要先进行能力检测 if (EM) { // return new Promise((resolve, reject) => { EM.Load( extensionId, utilitiesExt.version, false, (code, msg) => { defaultApi.writeLog(`loadUtils Code: ${code}\nMessage: ${msg}`); console.log('loadExt :zby_utilsExt ......'); // resolve({ // code, // msg // }); } ); // }); } })(); /** * @function 卸载 Zego 扩展 * @return Promise | void */ const unloadUtils = () => { // EM 是寄宿于端的,浏览器中并不存在,为防止报错需要先进行能力检测 if (EM) { return new Promise((resolve, reject) => { EM.UnLoad( extensionId, (code, msg) => { defaultApi.writeLog(`unloadUtils Code: ${code}\nMessage: ${msg}`); resolve({ code, msg }); } ); }); } }; export const isAppleM1 = () => { defaultApi.writeLog(`获取设备是否是M1设备: isAppleM1 --start`); return new Promise((resolve,reject) => { EM.system.IsAppleSilicon((code, msg) => { defaultApi.writeLog(`获取设备是否是M1设备: isAppleM1 code:${code} msg:${msg}`); let data = JSON.parse(msg); resolve({ code, data }); }); }) }; export const isWinX64 = () => { console.log('获取设备是否是WinX64设备: --start'); return new Promise((resolve,reject) => { if (!window.EM.GetClientArch) { resolve(false); return; } window.EM.GetClientArch((ec, content) => { if (String(ec) === '0') { const statusObj = JSON.parse(content); resolve(statusObj.client_arch === 'x64'); } else { resolve(false); } }); }); }; /** * @function 获取设备状态 * * @param { string } devicename //(设备名称,可为空) * * @param { number } devicetype //(设备类型,1摄像头,2麦克风),3扬声器(mac端没有) * @return: Promise */ const getDeviceState = (devicename, devicetype) => { return callMethod('GetDeviceState', {devicetype, devicename}); }; //获取设备状态 export const getDevicePermissionsFun = async (devicename, devicetype) => { defaultApi.writeLog(`sdk action : getDevicePermissionsFun devicename: ${devicename} devicetype: ${devicetype}`); try { let res =JSON.parse((await getDeviceState(devicename, devicetype)).msg).devicestate // let codemsg = { // '0':'有权限可用', // '1':'没有询问是否开启权限', // '2':'用户未授权', // '3':'未授权,家长限制', // '4':'未知权限类型', // '5':'操作系统不支持权限管理', // '6':'不可用(win10隐私关闭)', // '7':'设备占用' // }; // return codemsg[res]; console.log('getDevicePermissions_res',res); return res; } catch (error){ console.log('getDevicePermissions_error',error) return 'error'; }; }; export const setMediaPermissionFun = (enableVideo, enableMicrophone) =>{ return callMethod('SetMediaPermission',{enableVideo, enableMicrophone}); }; export const deviceListReport = { cameraList: {}, micList: {}, speakerList: {}, };