| | |
| | | import android.app.Activity |
| | | import android.app.Application |
| | | import android.content.Context |
| | | import android.content.Intent |
| | | import android.os.Bundle |
| | | import android.os.Handler |
| | | import android.os.Looper |
| | | import android.util.Log |
| | | import androidx.multidex.MultiDex |
| | | import cn.sinata.rxnetty.Cache.CacheUtil |
| | | import cn.sinata.rxnetty.NettyClient |
| | | import cn.sinata.xldutils.BaseApplication |
| | | import cn.sinata.xldutils.utils.sysErr |
| | |
| | | import com.okgoincar.bean.websocket.HeartBean |
| | | import com.okgoincar.netUtls.Api |
| | | import com.okgoincar.netUtls.getUserId |
| | | import com.okgoincar.netUtls.sendAudio |
| | | import com.okgoincar.slab.MySlabBaseActivity |
| | | import com.okgoincar.utils.Cache.CacheKey |
| | | import com.tencent.bugly.crashreport.CrashReport |
| | | import org.jetbrains.anko.toast |
| | | import org.json.JSONObject |
| | | import java.security.SecureRandom |
| | |
| | | // PlatformConfig.setWeixin("wx65d2c03f04352f90", "7a3a57f9ba78c1f400b75298eec4c7c0") |
| | | // PlatformConfig.setQQZone("101877032", "eab94b262bf9789eec770cde42a6e71e") //qq互联 |
| | | // LogUtils.OpenLog(true) |
| | | CrashReport.initCrashReport(applicationContext, "666d35fada", false) |
| | | initUpPoint() |
| | | initSocket() |
| | | |
| | | } |
| | | |
| | | private fun initSocket() { |
| | | Handler(Looper.getMainLooper()).post { |
| | | toast("websocket初始化") |
| | | // toast("websocket初始化") |
| | | } |
| | | NettyClient.getInstance().init(this, Api.SOCKET_SERVER, Api.SOCKET_PORT, true) |
| | | NettyClient.getInstance() |
| | |
| | | val json = JSONObject(message) |
| | | val method = json.optString("method") |
| | | Handler(Looper.getMainLooper()).post { |
| | | toast("收到websocket=$method") |
| | | // toast("收到websocket=$method") |
| | | } |
| | | val data = json.optString("data") |
| | | val code = json.optInt("code", -1) |
| | |
| | | bean.data = dataBean |
| | | NettyClient.getInstance() |
| | | .sendMessage(Gson().toJson(bean)) |
| | | // Handler(Looper.getMainLooper()).post { |
| | | Handler(Looper.getMainLooper()).post { |
| | | // toast("发送location --> $dataBean") |
| | | // } |
| | | } |
| | | sysErr(dataBean.toString()) |
| | | } |
| | | } |
| | |
| | | if ((System.currentTimeMillis() - currentTime) / 1000 > 30) { |
| | | sysErr("sendHeart_websocket 重新连接") |
| | | currentTime = System.currentTimeMillis() |
| | | // var s = CacheUtil.get().getAsString("reConnect") |
| | | // s = "$s###初始化重连" |
| | | // CacheUtil.get().put("reConnect", s) |
| | | // NettyClient.getInstance().checkNettyState() |
| | | initSocket() |
| | | NettyClient.getInstance().checkNettyStateNull() //reconnect |
| | | |
| | | // initSocket() |
| | | heartHandler!!.postDelayed({ sendHeart() }, 5000) |
| | | } else { |
| | | sysErr("sendHeart_websocket 发送心跳") |