"use strict";const e=require("../common/vendor.js"),t=require("../store/index.js"),s=require("../config.js");exports.init=()=>{if(e.index.getStorageSync("token")){console.log("sok-登录");var n=1e4,o=null,r=0;setInterval((()=>{r++}),1e3),a()}else console.log("sok-未登录");function a(){e.index.connectSocket({url:`wss://${s.config.sok}/ws/deviceUpMessage?token=${e.index.getStorageSync("token")}`,success(e){},fail(e){}}),e.index.onSocketOpen((t=>{e.index.sendSocketMessage({data:"ping",success:e=>{r=0},fail:e=>{a()}})})),e.index.onSocketError((e=>{})),n=1e4,o=null,e.index.onSocketMessage((s=>{r=0,function(s){var c;console.log(s);let i=getCurrentPages(),l=i[i.length-1].route;"pong"!==s&&(t.store.commit("setSokStatus",1),e.index.hideLoading(),c=JSON.parse(s),t.store.commit("setCommand",c.command),t.store.commit("setDataObj",c),console.log(c),(c.insertStatus||0===c.insertStatus)&&t.store.commit("setInsertStatus",c.insertStatus),"startResult"==c.command&&"-1"==c.result&&e.index.showModal({title:"提示",content:"启动失败，请重试",showCancel:!1,confirmText:"确认",success:()=>{}}),"startResult"==c.command&&"-2"==c.result&&e.index.showModal({title:"提示",content:"启动超时，请重试",showCancel:!1,confirmText:"确认",success:()=>{}}),"startResult"==c.command&&"01"==c.result&&"pageOrder/recharge/recharge"!=l&&e.index.navigateTo({url:`/pageOrder/recharge/recharge?transactionNo=${c.transactionNo}&type=order`}),"transactionResult"==c.command&&"pageOrder/recharge/recharge"==l&&e.index.navigateBack()),r=0,clearInterval(o),o=setInterval((function(){r>10?a():e.index.sendSocketMessage({data:"ping",success:e=>{},fail:e=>{a()}})}),n)}(s.data)}))}};
