helmetLive1.js 8.5 KB

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