118 lines
2.7 KiB
Plaintext
118 lines
2.7 KiB
Plaintext
import HttpUnit from "../Common/HttpUnit";
|
|
|
|
export class WebSDK{
|
|
|
|
//初始化
|
|
init(cb: Function = null) {
|
|
console.log("init webSDK");
|
|
cb && cb();
|
|
}
|
|
|
|
//检查权限
|
|
checkAutoSetting(autoKey:string, cb:Function = null) {
|
|
cb && cb(true);
|
|
}
|
|
|
|
//获取用户信息
|
|
getUserInfo(cb:Function = null) {
|
|
let name = HttpUnit.GetNickName();
|
|
cb && cb({ nickName:name, avatarUrl:"https://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/webHead.png" });
|
|
}
|
|
|
|
//登录
|
|
login(cb: Function = null) {
|
|
cb && cb({ platform:2, code: null });
|
|
}
|
|
|
|
//显示视频广告
|
|
show_video(callback:Function, tag:number) {
|
|
callback && callback({ code: 0, tag: tag });
|
|
}
|
|
|
|
//显示插屏
|
|
show_splash() {
|
|
|
|
|
|
}
|
|
|
|
//显示Banner
|
|
show_banner(...args) {
|
|
|
|
}
|
|
|
|
//隐藏Banner
|
|
hide_banner(...args) {
|
|
|
|
}
|
|
|
|
//主动拉起分享
|
|
show_share(rewardCB?:Function) {
|
|
rewardCB && rewardCB();
|
|
}
|
|
|
|
//获取设备分辨率
|
|
getWindowSize() {
|
|
return {width:screen.width, height: screen.height};
|
|
}
|
|
|
|
//显示游戏圈
|
|
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
|
|
|
|
}
|
|
//隐藏游戏圈
|
|
hide_gameClub() {
|
|
|
|
}
|
|
|
|
//检查是否支持base64音频播放
|
|
checkSupportBase64Audio() {
|
|
return true;
|
|
}
|
|
//播放base64音频
|
|
private _audioInst:HTMLAudioElement = null;
|
|
playBase64Audio(base64:string, loop:boolean) {
|
|
let substring = base64;
|
|
let qianzhui = "data:audio/x-wav;base64,"
|
|
if(base64.startsWith(qianzhui)) {
|
|
substring = base64.substring(qianzhui.length, base64.length)
|
|
}
|
|
|
|
// 解码 Base64 字符串为二进制数据
|
|
const binaryData = atob(substring);
|
|
|
|
// 创建一个包含二进制数据的 Uint8Array
|
|
const byteArray = new Uint8Array(binaryData.length);
|
|
for (let i = 0; i < binaryData.length; i++) {
|
|
byteArray[i] = binaryData.charCodeAt(i);
|
|
}
|
|
|
|
// 创建 Blob 对象,指定 MIME 类型为音频格式(例如 mp3)
|
|
const audioBlob = new Blob([byteArray], { type: 'audio/mp3' });
|
|
|
|
// 创建音频 URL
|
|
const audioUrl = URL.createObjectURL(audioBlob);
|
|
|
|
console.log("web 播放base64音频", audioUrl)
|
|
// 创建音频元素并播放
|
|
if (this._audioInst == null) {
|
|
this._audioInst = new Audio(audioUrl);
|
|
} else {
|
|
this._audioInst.src = audioUrl;
|
|
}
|
|
this._audioInst.play();
|
|
|
|
}
|
|
|
|
|
|
//region 友盟+
|
|
umaInit() {
|
|
}
|
|
//友盟统计是否开启
|
|
umaSwt() {
|
|
return false;
|
|
}
|
|
//友盟事件统计
|
|
umaEvent(eventName: string, value: any = {}) {
|
|
}
|
|
}
|