private var mDisposable: Disposable? = null
//在initVeiw中执行initLiveSocket就可以启动任务
//观看直播心跳 initialDelay:首次执行任务延迟多少 period:定时任务时间间隔 unit:时间单位
private fun initLiveSocket() {
mDisposable = Observable.interval(5, 10, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Consumer<Long> {
override fun accept(t: Long?) {
LogUtil.e("------livePlayActivity定时轮询:$t")
mRoomInfo?.room_no?.let {
LiveSocketUtil.sendLive(this@LivePlayActivityKt, it.toInt())
}
}
})
}
//在onDestroy()中执行下面代码关闭任务
//停止心跳包
mDisposable?.dispose()