var heAnth = null,heList = [],nowHe = null,userAgent = null,setItime = null,setItimes = 0; var o = void 0, s = 14963200, n = o+"@47.106.114.236:11011", a = s+"@47.106.114.236:11011", l = "wss://caps.runde.pro:11014", r = "0000", h = void 0, u = void 0, p = void 0, m = void 0, d = null, c = null, _ = null, y = null, f = [], v = void 0; window.addEventListener('message',(_data)=>{ if(_data.data.cmd != undefined){ setPlay(_data.data); }else{ if(nowHe != null){ $("._Call img").attr("src","../img/voice.yz4975.png"); if(y != null) u.terminate(); clearInterval(setItime); setItime = null; setItimes = 0; $("._Call .margin-top-sm").text("未连接"); $("._Call .text-lg").text("00:00:00"); $("._helme").css("display","none"); $("#html_view li .text-sm").removeClass("act"); window.parent.postMessage({info:{act: "ma_stop_rtsp",device_id: nowHe.device_id},change: "helemt"}, '*'); } heAnth = JSON.parse(localStorage.getItem("nowShip")); getList(0); } }) var User = JSON.parse(localStorage.getItem("_yz_TU")); $(document).ready(function(){ heAnth = JSON.parse(localStorage.getItem("nowShip")); getList(0); setInterval(()=>{ getList(1); },60*1000); sipInit(); }); function setPlay(_data){ if(_data.cmd == "ma_open_rtsp"&& _data.status){ let _ind = _data.play_url.findIndex((i,ind) => {return i.indexOf("webrtc://") != -1;}); player = new JSWebrtc.Player(_data.api_url, _data.play_url[_ind], { video: document.getElementById("localMonitor"), autoplay: !0, onPlay: startPlay, onFail: onFail }) }else if(_data.cmd == "ma_stop_rtsp"&& _data.status){ console.log("关闭成功"); $("._Call").css("display","none"); callErr(); $("#_View").html('
'); }else if(_data.cmd == "ma_set_sip_info"&& _data.status){ sipCall(); } } var startPlay = function () { console.log("开始播放"); $(".loadImg").remove(); }; var onFail = function () { setTimeout(function() { window.parent.postMessage({info:{act: "ma_open_rtsp",device_id: nowHe.device_id},change: "helemt"}, '*'); }, 1000) } function sipInit() { o = localStorage.getItem("sipId"); n = o+"@47.106.114.236:11011" var e = { uri: n, transportOptions: { wsServers: [l], connectionTimeout: 30 }, authorizationUser: o, password: r, sessionDescriptionHandlerFactoryOptions: { peerConnectionOptions: { rtcConfiguration: { iceServers: [{ urls: "stun:47.106.114.236:40998", }, { urls: "turn:47.106.114.236:40998", username: "fstest", credential: "123456" }] } } } }; userAgent = new SIP.UA(e); userAgent.on("registered", function() { console.log("registered ok"); // call(); }) userAgent.on("registrationFailed", function(){ console.log("registrationFailed ok") }) } function sipCall(){ console.log(11233) c = document.getElementById("helmeVi"); d = document.getElementById("remoteMonitor"); var i = { sessionDescriptionHandlerOptions: { constraints: { audio: !0, video: !1 } } } h = userAgent.invite(a, i), p = h, h.on("accepted",function(t) { var i = h.sessionDescriptionHandler.peerConnection, o = new MediaStream; if (i.getReceivers().forEach(function(t) { o.addTrack(t.track) }), c.srcObject = o, c.play(), c .muted = !0, i.getSenders()) { var s = new MediaStream; i.getSenders().forEach(function(t) { s.addTrack(t.track), t.track.kind }),d.srcObject = s, d.play(), y = new MediaRecorder(s) } _ = new MediaRecorder(o), y.ondataavailable = function(t) { v.push(t.data) }, _.ondataavailable = function(t) { v.push(t.data) }, _.onstop = function(t) { e.blobDownload() } setTimeout(()=>{ callSes(); },4000) }); h.on("rejected", function(t, i) { console.log("onRejected - ", t, i) }); h.on("failed", function(t, i) { console.log("onFailed - ", t, i) }); h.on("terminated", function(t, i) { console.log("onTerminated - ", t, i); }) } function getList(num){ if(heAnth !=null && heAnth != "null"&&heAnth.other_info !=null && heAnth.other_info != ""){ var dsd = heAnth.other_info.split(","); let _opts = { url: helUrl + "/index.php?ctl=bruce&act=get_group_member_list", type:"POST" }; let _data = { admin_id: 7903, udid: "11111111", g_id: dsd[0] }; postAxios(_opts, _data, {}).then((res) =>{ heList = []; if(res.status){ if(res.data.length){ setHelme(num,res.data,dsd); }else{ _str=`
  • 暂无设备列表
  • ` } }else{ _str=`
  • 暂无设备列表
  • ` } }) }else{ heList = []; $("#html_view").html(`
  • 暂无设备列表
  • `); } } function setHelme(num,_obj,_sji){ let _str = ""; _obj.forEach((item,ind)=>{ if(item.device_id == _sji[1]){ if(num == 0){ _str += `
  • ${item.nick}
  • `; }else{ if(item.on_line==0){ $('#html_view li[data-yz="'+item.device_id+'] img').attr("src",'../img/maozi_no.png'); $('#html_view li[data-yz="'+item.device_id+'] div').removeClass("text-white").addClass("text-rgb"); }else{ $('#html_view li[data-yz="'+item.device_id+'] img').attr("src",'../img/maozi.png'); $('#html_view li[data-yz="'+item.device_id+'] div').removeClass("text-rgb").addClass("text-white"); } } } }); heList = _obj; if(num == 0){$("#html_view").html(_str);} } $(document).on("click","#html_view li",function(){ let _id = $(this).data("yz"); let _ind = heList.findIndex((i,ind) => {return i.device_id == _id}); if(_ind != -1){ nowHe = heList[_ind]; }else{ nowHe = null; } if(nowHe != null){ if(nowHe.on_line==0){ ShowLoading("安全帽离线中!",1); return; }else{ $("#html_view li .text-sm").removeClass("act"); $(this).find(".text-sm").addClass("act"); $("#_View").html(''); window.parent.postMessage({info:{act: "ma_open_rtsp",device_id: nowHe.device_id},change: "helemt"}, '*'); } } }) $(".tool").on("click",".icon-mic-on-full",function(){ if(nowHe != null){ if(nowHe.on_line==0){ ShowLoading("安全帽离线中!",1); return; }else{ $("._Call").css("display","block"); } }else{ ShowLoading("请先选择一个安全帽!",1); return; } }) $(document).on("click","._Call .icon-cha",function(){ $("._Call").css("display","none"); //document.getElementById("localMonitor").muted = !1; callErr(); }) $(".tool").on("click",".icon-zhuxiaoguanji",function(){ if(nowHe != null){ $("#html_view li .text-sm").removeClass("act"); window.parent.postMessage({info:{act: "ma_stop_rtsp",device_id: nowHe.device_id},change: "helemt"}, '*'); }else{ ShowLoading("暂无安全帽在播放!",1); return; } }) $(".tool").on("click",".icon-quanping",function(){ let _elem = document.getElementById("_View"); requesetFullScreen(_elem); }) $(document).on("click","._Call img",function(){ if($(this).attr("src").indexOf("yz4975") != -1){ navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator .mozGetUserMedia || navigator.msGetUserMedia, navigator.getUserMedia ? navigator .getUserMedia({ audio: true, video: false }, function(e) { console.log("已点击允许,开启成功",1); console.log("1111111这里") let _sjh = JSON.parse(localStorage.getItem("sipIds")); let _opts = { url: helUrl + "/index.php?ctl=device&act=get_user_sip_id&user_id="+nowHe.user_id, type:"GET" }; let _data = {}; getAxios(_opts, _data, {}).then((res) =>{ if(res.status){ $("._Call .margin-top-sm").text("连接中...."); s = res.data.sip_id; a = s + "@47.106.114.236:11011"; // window.parent.postMessage({info:{ // act: "ma_set_sip_info", // user_id: nowHe.user_id, // v_type: 0 // },change: "helemt"}, '*'); } }) // s = _sjh[nowHe.device_id]; // // s = 1004326 // a = s+"@47.106.114.236:11011"; // window.parent.postMessage({info:{ // act: "ma_set_sip_info", // user_id: nowHe.user_id, // v_type: 0 // },change: "helemt"}, '*'); }, function(e) { ShowLoading("获取麦克风失败!",1) }) : ShowLoading("获取麦克风权限失败!",1) }else{ callErr(); } }) function callErr(){ $("._Call img").attr("src","../img/voice.yz4975.png"); if(p != null) p.terminate(); clearInterval(setItime); setItime = null; setItimes = 0; $("._Call .margin-top-sm").text("未连接"); $("._Call .text-lg").text("00:00:00"); } function callSes(){ $("._Call .margin-top-sm").text("已连接"); $("._Call img").attr("src","../img/voice.yz8975.png"); // document.getElementById("localMonitor").controls = !1; // document.getElementById("localMonitor").muted = !0; // $("._helme").css("display","block"); clearInterval(setItime); setItime = setInterval(()=>{ setItimes += 1; let hou = Math.floor(setItimes/3600); let a = setItimes - (hou*3600); let min = Math.floor(a/60); let sed = a - (min*60); $("._Call .text-lg").text((hou>9?hou:'0'+hou)+":"+(min>9?min:'0'+min)+":"+(sed>9?sed:'0'+sed)); },1000); }