123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- var heAnth = null,heList = [],nowHe = null,setItime = null,setItimes = 0;
- var sip_id = null,
- sip_pwd = null,
- sip_host = null,
- wss_url = null,
- stun_host = null,
- turn_host = null,
- turn_pwd = null,
- turn_user = null,
- device_sipId = null;
- var userAgent = null;
- var sipsession = null;
- var localVideo = document.getElementById("remoteMonitor");
- var remoteVideo = document.getElementById("helmeVi");
- window.addEventListener('message',(_data)=>{
- if(_data.data.cmd != undefined){
- if(_data.data.cmd == "ma_push_take_photo"){
- if(_data.data.status){
- ShowLoading("截图成功!",1);
- return;
- }else{
- ShowLoading("截图失败!",1);
- return;
- }
- }else{
- setPlay(_data.data);
- }
- }else{
- if(nowHe != null){
- $("._Call img").attr("src","../img/voice.yz4975.png");
- if(sipsession) sipsession.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 handleScreen(){
- if(nowHe != null){
- window.parent.postMessage({info:{
- act: "ma_push_take_photo",
- user_id: nowHe.user_id
- }, change: "helemt" }, '*');
- }
- }
- 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){
- $("._Call").css("display","none");
- callErr();
- $("#_View").html('<div class="noBg"><img src="../img/maozi.png" ></div>');
- }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() {
- let _obj = JSON.parse(localStorage.getItem("sipInfo"));
- sip_id = _obj["sip_id"];
- sip_pwd = _obj["sip_pwd"];
- sip_host = _obj["sip_host"];
- wss_url = _obj["wss_url"];
- stun_host = _obj["stun_host"];
- turn_host = _obj["turn_host"];
- turn_pwd = _obj["turn_pwd"];
- turn_user = _obj["turn_user"];
- var e = {
- uri: sip_id + '@' + sip_host, //此sip_id为拨打者账号
- transportOptions: {
- wsServers: [wss_url],
- connectionTimeout: 30
- },
- authorizationUser: sip_id,
- password: sip_pwd,
- sessionDescriptionHandlerFactoryOptions: {
- peerConnectionOptions: {
- rtcConfiguration: {
- iceServers: [{
- urls: 'stun:' + stun_host
- },
- {
- urls: 'turn:' + turn_host,
- username: turn_user,
- credential: turn_pwd
- }
- ]
- }
- }
- }
- };
- userAgent = new SIP.UA(e);
- userAgent.on("registered", function() {
- console.log("registered ok");
- })
- userAgent.on("registrationFailed", function(){
- console.log("registrationFailed ok")
- })
- userAgent.on("invite", function(session) {
- var url = session.remoteIdentity.uri.toString() + "--->call";
- var isaccept = confirm(url);
- if (isaccept) {
- //接收来电
- session.accept({
- sessionDescriptionHandlerOptions: {
- constraints: {
- audio: true,
- video: false
- }
- }
- });
- sipsession = session;
- session.on("accepted", function() {
- var pc = session.sessionDescriptionHandler.peerConnection;
- var remoteStream = new MediaStream();
- pc.getReceivers().forEach(function(receiver) {
- remoteStream.addTrack(receiver.track);
- });
- remoteVideo.srcObject = remoteStream;
- remoteVideo.play();
- if (pc.getSenders()) {
- var localStream = new MediaStream();
- pc.getSenders().forEach(function(sender) {
- localStream.addTrack(sender.track);
- });
- localVideo.srcObject = localStream;
- localVideo.play();
- }
- });
- } else {
- //拒绝来电
- session.reject();
- }
- })
- }
- function sipCall(){
- sipsession = userAgent.invite(device_sipId + '@' + sip_host, {
- sessionDescriptionHandlerOptions: {
- constraints: {
- audio: true,
- video: false //音频通话则为false
- }
- }
- });
- sipsession.on("accepted", function() {
- var pc = sipsession.sessionDescriptionHandler.peerConnection;
- // Gets remote tracks
- var remoteStream = new MediaStream();
- pc.getReceivers().forEach(function(receiver) {
- remoteStream.addTrack(receiver.track);
- });
- //此处remoteVideo为一个video标签
- remoteVideo.srcObject = remoteStream;
- remoteVideo.play();
- setTimeout(()=>{
- callSes();
- },4000)
- });
- sipsession.on("rejected", function(t, i) {
- // console.log("onRejected - ", t, i)
- });
- sipsession.on("failed", function(t, i) {
- // console.log("onFailed - ", t, i)
- });
- sipsession.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=`<li class="text-center">暂无设备列表</li>`
- }
- }else{
- _str=`<li class="text-center">暂无设备列表</li>`
- }
-
- })
- }else{
- heList = [];
- $("#html_view").html(`<li class="text-center">暂无设备列表</li>`);
- }
- }
- function setHelme(num,_obj,_sji){
- let _str = "";
- _obj.forEach((item,ind)=>{
- if(item.device_id == _sji[1]){
- if(num == 0){
- _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>`;
- }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('<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){
- 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);
- 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){
- device_sipId = res.data.sip_id;
- $("._Call .margin-top-sm").text("连接中....");
- 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 (sipsession) sipsession.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").muted = !1;
- // $("._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);
- }
|