helmetLive - 副本.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. var heAnth = null,heList = [],nowHe = null,userAgent = null,setItime = null,setItimes = 0;
  2. var o = void 0,
  3. s = 14963200,
  4. n = o+"@47.106.114.236:11011",
  5. a = s+"@47.106.114.236:11011",
  6. l = "wss://caps.runde.pro:11014",
  7. r = "0000",
  8. h = void 0,
  9. u = void 0,
  10. p = void 0,
  11. m = void 0,
  12. d = null,
  13. c = null,
  14. _ = null,
  15. y = null,
  16. f = [],
  17. v = void 0;
  18. window.addEventListener('message',(_data)=>{
  19. if(_data.data.cmd != undefined){
  20. setPlay(_data.data);
  21. }else{
  22. if(nowHe != null){
  23. $("._Call img").attr("src","../img/voice.yz4975.png");
  24. if(y != null) u.terminate();
  25. clearInterval(setItime);
  26. setItime = null;
  27. setItimes = 0;
  28. $("._Call .margin-top-sm").text("未连接");
  29. $("._Call .text-lg").text("00:00:00");
  30. $("._helme").css("display","none");
  31. $("#html_view li .text-sm").removeClass("act");
  32. window.parent.postMessage({info:{act: "ma_stop_rtsp",device_id: nowHe.device_id},change: "helemt"}, '*');
  33. }
  34. heAnth = JSON.parse(localStorage.getItem("nowShip"));
  35. getList(0);
  36. }
  37. })
  38. var User = JSON.parse(localStorage.getItem("_yz_TU"));
  39. $(document).ready(function(){
  40. heAnth = JSON.parse(localStorage.getItem("nowShip"));
  41. getList(0);
  42. setInterval(()=>{
  43. getList(1);
  44. },60*1000);
  45. sipInit();
  46. });
  47. function setPlay(_data){
  48. if(_data.cmd == "ma_open_rtsp"&& _data.status){
  49. let _ind = _data.play_url.findIndex((i,ind) => {return i.indexOf("webrtc://") != -1;});
  50. player = new JSWebrtc.Player(_data.api_url, _data.play_url[_ind], {
  51. video: document.getElementById("localMonitor"),
  52. autoplay: !0,
  53. onPlay: startPlay,
  54. onFail: onFail
  55. })
  56. }else if(_data.cmd == "ma_stop_rtsp"&& _data.status){
  57. console.log("关闭成功");
  58. $("._Call").css("display","none");
  59. callErr();
  60. $("#_View").html('<div class="noBg"><img src="../img/maozi.png" ></div>');
  61. }else if(_data.cmd == "ma_set_sip_info"&& _data.status){
  62. sipCall();
  63. }
  64. }
  65. var startPlay = function () {
  66. console.log("开始播放");
  67. $(".loadImg").remove();
  68. };
  69. var onFail = function () {
  70. setTimeout(function() {
  71. window.parent.postMessage({info:{act: "ma_open_rtsp",device_id: nowHe.device_id},change: "helemt"}, '*');
  72. }, 1000)
  73. }
  74. function sipInit() {
  75. o = localStorage.getItem("sipId");
  76. n = o+"@47.106.114.236:11011"
  77. var e = {
  78. uri: n,
  79. transportOptions: {
  80. wsServers: [l],
  81. connectionTimeout: 30
  82. },
  83. authorizationUser: o,
  84. password: r,
  85. sessionDescriptionHandlerFactoryOptions: {
  86. peerConnectionOptions: {
  87. rtcConfiguration: {
  88. iceServers: [{
  89. urls: "stun:47.106.114.236:40998",
  90. }, {
  91. urls: "turn:47.106.114.236:40998",
  92. username: "fstest",
  93. credential: "123456"
  94. }]
  95. }
  96. }
  97. }
  98. };
  99. userAgent = new SIP.UA(e);
  100. userAgent.on("registered", function() {
  101. console.log("registered ok");
  102. // call();
  103. })
  104. userAgent.on("registrationFailed", function(){
  105. console.log("registrationFailed ok")
  106. })
  107. }
  108. function sipCall(){
  109. console.log(11233)
  110. c = document.getElementById("helmeVi");
  111. d = document.getElementById("remoteMonitor");
  112. var i = {
  113. sessionDescriptionHandlerOptions: {
  114. constraints: {
  115. audio: !0,
  116. video: !1
  117. }
  118. }
  119. }
  120. h = userAgent.invite(a, i),
  121. p = h,
  122. h.on("accepted",function(t) {
  123. var i = h.sessionDescriptionHandler.peerConnection,
  124. o = new MediaStream;
  125. if (i.getReceivers().forEach(function(t) {
  126. o.addTrack(t.track)
  127. }), c.srcObject = o, c.play(), c
  128. .muted = !0, i.getSenders()) {
  129. var s = new MediaStream;
  130. i.getSenders().forEach(function(t) {
  131. s.addTrack(t.track), t.track.kind
  132. }),d.srcObject = s, d.play(), y = new MediaRecorder(s)
  133. }
  134. _ = new MediaRecorder(o), y.ondataavailable = function(t) {
  135. v.push(t.data)
  136. }, _.ondataavailable = function(t) {
  137. v.push(t.data)
  138. }, _.onstop = function(t) {
  139. e.blobDownload()
  140. }
  141. setTimeout(()=>{
  142. callSes();
  143. },4000)
  144. });
  145. h.on("rejected", function(t, i) {
  146. console.log("onRejected - ", t, i)
  147. });
  148. h.on("failed", function(t, i) {
  149. console.log("onFailed - ", t, i)
  150. });
  151. h.on("terminated", function(t, i) {
  152. console.log("onTerminated - ", t, i);
  153. })
  154. }
  155. function getList(num){
  156. if(heAnth !=null && heAnth != "null"&&heAnth.other_info !=null && heAnth.other_info != ""){
  157. var dsd = heAnth.other_info.split(",");
  158. let _opts = {
  159. url: helUrl + "/index.php?ctl=bruce&act=get_group_member_list",
  160. type:"POST"
  161. };
  162. let _data = {
  163. admin_id: 7903,
  164. udid: "11111111",
  165. g_id: dsd[0]
  166. };
  167. postAxios(_opts, _data, {}).then((res) =>{
  168. heList = [];
  169. if(res.status){
  170. if(res.data.length){
  171. setHelme(num,res.data,dsd);
  172. }else{
  173. _str=`<li class="text-center">暂无设备列表</li>`
  174. }
  175. }else{
  176. _str=`<li class="text-center">暂无设备列表</li>`
  177. }
  178. })
  179. }else{
  180. heList = [];
  181. $("#html_view").html(`<li class="text-center">暂无设备列表</li>`);
  182. }
  183. }
  184. function setHelme(num,_obj,_sji){
  185. let _str = "";
  186. _obj.forEach((item,ind)=>{
  187. if(item.device_id == _sji[1]){
  188. if(num == 0){
  189. _str += `<li class="flex align-center" data-yz="${item.device_id}">
  190. <img src="../img/${item.on_line==0?'maozi_no':'maozi'}.png" style="width:26px;margin-right:6px;"/>
  191. <div class="text-sm ${item.on_line==0?'text-rgb':'text-white'}">${item.nick}</div>
  192. </li>`;
  193. }else{
  194. if(item.on_line==0){
  195. $('#html_view li[data-yz="'+item.device_id+'] img').attr("src",'../img/maozi_no.png');
  196. $('#html_view li[data-yz="'+item.device_id+'] div').removeClass("text-white").addClass("text-rgb");
  197. }else{
  198. $('#html_view li[data-yz="'+item.device_id+'] img').attr("src",'../img/maozi.png');
  199. $('#html_view li[data-yz="'+item.device_id+'] div').removeClass("text-rgb").addClass("text-white");
  200. }
  201. }
  202. }
  203. });
  204. heList = _obj;
  205. if(num == 0){$("#html_view").html(_str);}
  206. }
  207. $(document).on("click","#html_view li",function(){
  208. let _id = $(this).data("yz");
  209. let _ind = heList.findIndex((i,ind) => {return i.device_id == _id});
  210. if(_ind != -1){
  211. nowHe = heList[_ind];
  212. }else{
  213. nowHe = null;
  214. }
  215. if(nowHe != null){
  216. if(nowHe.on_line==0){
  217. ShowLoading("安全帽离线中!",1);
  218. return;
  219. }else{
  220. $("#html_view li .text-sm").removeClass("act");
  221. $(this).find(".text-sm").addClass("act");
  222. $("#_View").html('<img src="../img/load.png" class="loadImg" alt=""><video style="width:100%;height:100%;" id="localMonitor" poster="" controls></video>');
  223. window.parent.postMessage({info:{act: "ma_open_rtsp",device_id: nowHe.device_id},change: "helemt"}, '*');
  224. }
  225. }
  226. })
  227. $(".tool").on("click",".icon-mic-on-full",function(){
  228. if(nowHe != null){
  229. if(nowHe.on_line==0){
  230. ShowLoading("安全帽离线中!",1);
  231. return;
  232. }else{
  233. $("._Call").css("display","block");
  234. }
  235. }else{
  236. ShowLoading("请先选择一个安全帽!",1);
  237. return;
  238. }
  239. })
  240. $(document).on("click","._Call .icon-cha",function(){
  241. $("._Call").css("display","none");
  242. //document.getElementById("localMonitor").muted = !1;
  243. callErr();
  244. })
  245. $(".tool").on("click",".icon-zhuxiaoguanji",function(){
  246. if(nowHe != null){
  247. $("#html_view li .text-sm").removeClass("act");
  248. window.parent.postMessage({info:{act: "ma_stop_rtsp",device_id: nowHe.device_id},change: "helemt"}, '*');
  249. }else{
  250. ShowLoading("暂无安全帽在播放!",1);
  251. return;
  252. }
  253. })
  254. $(".tool").on("click",".icon-quanping",function(){
  255. let _elem = document.getElementById("_View");
  256. requesetFullScreen(_elem);
  257. })
  258. $(document).on("click","._Call img",function(){
  259. if($(this).attr("src").indexOf("yz4975") != -1){
  260. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator
  261. .mozGetUserMedia || navigator.msGetUserMedia, navigator.getUserMedia ? navigator
  262. .getUserMedia({ audio: true, video: false },
  263. function(e) {
  264. console.log("已点击允许,开启成功",1);
  265. console.log("1111111这里")
  266. let _sjh = JSON.parse(localStorage.getItem("sipIds"));
  267. let _opts = {
  268. url: helUrl + "/index.php?ctl=device&act=get_user_sip_id&user_id="+nowHe.user_id,
  269. type:"GET"
  270. };
  271. let _data = {};
  272. getAxios(_opts, _data, {}).then((res) =>{
  273. if(res.status){
  274. $("._Call .margin-top-sm").text("连接中....");
  275. s = res.data.sip_id;
  276. a = s + "@47.106.114.236:11011";
  277. // window.parent.postMessage({info:{
  278. // act: "ma_set_sip_info",
  279. // user_id: nowHe.user_id,
  280. // v_type: 0
  281. // },change: "helemt"}, '*');
  282. }
  283. })
  284. // s = _sjh[nowHe.device_id];
  285. // // s = 1004326
  286. // a = s+"@47.106.114.236:11011";
  287. // window.parent.postMessage({info:{
  288. // act: "ma_set_sip_info",
  289. // user_id: nowHe.user_id,
  290. // v_type: 0
  291. // },change: "helemt"}, '*');
  292. }, function(e) {
  293. ShowLoading("获取麦克风失败!",1)
  294. }) : ShowLoading("获取麦克风权限失败!",1)
  295. }else{
  296. callErr();
  297. }
  298. })
  299. function callErr(){
  300. $("._Call img").attr("src","../img/voice.yz4975.png");
  301. if(p != null) p.terminate();
  302. clearInterval(setItime);
  303. setItime = null;
  304. setItimes = 0;
  305. $("._Call .margin-top-sm").text("未连接");
  306. $("._Call .text-lg").text("00:00:00");
  307. }
  308. function callSes(){
  309. $("._Call .margin-top-sm").text("已连接");
  310. $("._Call img").attr("src","../img/voice.yz8975.png");
  311. // document.getElementById("localMonitor").controls = !1;
  312. // document.getElementById("localMonitor").muted = !0;
  313. // $("._helme").css("display","block");
  314. clearInterval(setItime);
  315. setItime = setInterval(()=>{
  316. setItimes += 1;
  317. let hou = Math.floor(setItimes/3600);
  318. let a = setItimes - (hou*3600);
  319. let min = Math.floor(a/60);
  320. let sed = a - (min*60);
  321. $("._Call .text-lg").text((hou>9?hou:'0'+hou)+":"+(min>9?min:'0'+min)+":"+(sed>9?sed:'0'+sed));
  322. },1000);
  323. }