import { layuiObj } from "./index.js";
import { sosSdk } from "./sosVideoAndAudio.js";
var sosAudioIndex=null;
var currentSosAudio=null;
function popSosAudio(obj){
currentSosAudio=JSON.parse(JSON.stringify(obj));
sosAudioIndex=layuiObj["layer"].open({
type: 1,
title: false, //不显示标题栏
closeBtn: false,
area: ['446px', 'auto'],
shade: 0.4,
id: new Date().getTime(), //设定一个id,防止重复弹出
btnAlign: 'c',
move:'.layui-move',
moveType: 1, //拖拽模式,0或者1
content:`
${currentSosAudio["pointAddress"]}
`,
success:function(){
sosAudioStart();
}
});
$(".popInfoTitle>img").on('click',function(){
layuiObj["layer"].close(sosAudioIndex)
sosAudioIndex=null;
sosAudioStop();
})
}
var taskCode="";
// 开始对讲
function sosAudioStart(){
if (sosSdk) {
let disconnectedCallback = (SipNum) => {
// 开始对讲之后,有设备或自己退出对讲
console.warn(SipNum, "已退出对讲", sosSdk && sosSdk.isMe(SipNum));
}
let stopCallback = () => {
// 开始对讲之后,服务器结束了对讲
console.warn("服务器结束对讲");
}
sosSdk.audioSpeakStart({
// 必填参数
DeviceId: parseInt(currentSosAudio["deviceId"]),
AudioDomId: "html_Audio_record", // 要保证document.getElementById("html_audio_remote")非null,你的audio标签,一定要存在
// 非必填参数
Force: false,
OnDisconnected: disconnectedCallback,
OnStop: stopCallback,
}).then((ret) => {
taskCode = ret.TaskCode
console.log(ret);
}).catch((e) => {
console.log(e);
switch (e.code) {
case 2005:
break;
case 2006:
layer.msg("设备离线")
break
case 3551:
break;
case 3552:
break;
default:
break;
}
})
} else {
alert("对讲失败,请先启动SDK")
}
}
// 结束对讲
function sosAudioStop(){
if (sosSdk) {
sosSdk.audioSpeakStop({
TaskCode: taskCode
}).then(() => {
console.log("对讲停止成功");
}).catch((error) => {
console.error(error);
})
} else {
alert("对讲停止失败,请先启动SDK")
}
}
export {popSosAudio}