123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- var heAnth = null,heList = [],nowHe = null,userAgent = null,setItime = null,setItimes = 0;
- var o = void 0,
- s = void 0,
- 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();
- }
-
- })
- $(document).ready(function(){
- heAnth = JSON.parse(localStorage.getItem("nowShip"));
- getList();
- 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("关闭成功");
- nowHe = null;
- $("#_View").html('<div class="noBg"><img src="../img/maozi.png" ></div>');
- }else if(_data.cmd == "ma_set_sip_info"&& _data.status){
- console.log(11111)
- 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(){
- d = document.getElementById("remoteMonitor");
- c = document.getElementById("helmeVi");
- var i = {
- sessionDescriptionHandlerOptions: {
- constraints: {
- audio: !0,
- video: !1
- }
- }
- }
- h = userAgent.invite(a, i);
- u = 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(), document.getElementById(
- "remoteMonitor").controls = !0, c
- .muted = !1, 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()
- }
- callSes();
- });
- 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) {
- callErr();
- // console.log("onTerminated - ", t, i);
- })
- // console.log()
- }
- function getList(){
- 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 = [];
- let _str = "";
- if(res.status){
- let _obj = res.data;
- if(_obj.length){
- _obj.forEach((item,ind)=>{
- if(item.device_id == dsd[1]){
- _str += `<li class="flex align-center" data-yz="${item.device_id}">
- <img src="../img/${item.on_line==0?'maozi_no':'maozi'}.png" style="width:26px;margin-right:6px;"/>
- <div class="text-sm ${item.on_line==0?'text-rgb':'text-white'}">${item.nick}</div>
- </li>`;
- }
- });
- heList = _obj;
- }else{
- _str=`<li class="text-center padding-sm text-sm text-grey">暂无设备列表</li>`
- }
- }else{
- _str=`<li class="text-center padding-sm text-sm text-grey">暂无设备列表</li>`
- }
- $("#html_view").html(_str);
- })
- }else{
- $("#html_view").html(`<li class="text-center padding-sm text-sm text-grey">暂无设备列表</li>`);
- }
- }
- $(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){
- showErr("安全帽离线中!");
- return;
- }else{
- $("#html_view li .text-sm").removeClass("act");
- $(this).find(".text-sm").addClass("act");
- $("#_View").html('<img src="../img/load.png" class="loadImg" alt=""><video style="width:100%;height:100%;" id="localMonitor" poster="" controls></video>');
- 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){
- showErr("安全帽离线中!");
- return;
- }else{
- $("._Call").css("display","block");
- }
- }else{
- showErr("请先选择一个安全帽!");
- return;
- }
- })
- $(document).on("click","._Call .icon-cha",function(){
- $("._Call").css("display","none");
- 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{
- showErr("暂无安全帽在播放!");
- return;
- }
- })
- $(".tool").on("click",".icon-quanping",function(){
- let ele = document.getElementById("_View");
- if (ele.requestFullscreen) {
- ele.requestFullscreen();
- } else if (ele.mozRequestFullScreen) {
- ele.mozRequestFullScreen();
- } else if (ele.webkitRequestFullscreen) {
- ele.webkitRequestFullscreen();
- } else if (ele.msRequestFullscreen) {
- ele.msRequestFullscreen();
- }
- })
- $(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);
- let _sjh = JSON.parse(localStorage.getItem("sipIds"));
- s = _sjh[nowHe.device_id];
- a = s+"@47.106.114.236:11011";
- window.parent.postMessage({info:{
- act: "ma_set_sip_info",
- user_id: nowHe.user_id,
- v_type: 1
- },change: "helemt"}, '*');
- }, function(e) {
- showErr("获取麦克风失败!")
- }) : showErr("获取麦克风权限失败!")
- }else{
- callErr();
- }
- })
- function callErr(){
- $("._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");
- $("#_View").html('<img src="../img/load.png" class="loadImg" alt=""><video style="width:100%;height:100%;" id="remoteMonitor" poster="" controls></video>');
- window.parent.postMessage({info:{act: "ma_open_rtsp",device_id: nowHe.device_id},change: "helemt"}, '*');
- }
- function callSes(){
- $("._Call .margin-top-sm").text("已连接");
- $("._Call img").attr("src","../img/voice.yz8975.png");
- $("._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);
- }
|