AudioApiRequestUtil.kt 3.84 KB
Newer Older
洪国微 committed
1 2 3 4 5
package com.ydl.audioim.http

import com.google.gson.Gson
import com.ydl.audioim.bean.AgoraTokenResponse
import com.ydl.audioim.bean.ConnectBean
6 7 8
import com.ydl.audioim.http.command.ConnectCommand
import com.ydl.audioim.http.command.ConnectExceptionCommand
import com.ydl.audioim.http.command.NoticePushCommand
严久程 committed
9 10
import com.ydl.consultantim.bean.ListenTokenBean
import com.ydl.consultantim.command.ListenTokenCmd
洪国微 committed
11 12 13
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.data.http.RxUtils
严久程 committed
14
import com.ydl.ydlcommon.utils.NetworkParamsUtils
洪国微 committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import com.ydl.ydlnet.YDLHttpUtils
import io.reactivex.Observable
import okhttp3.MediaType
import okhttp3.RequestBody

/**
 * @author jiucheng
 * @描述:声网业务接口请求
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/11/9
 */
class AudioApiRequestUtil {
    companion object {
        /**
         * 倾诉
         */
        fun connectListen(cmd: ConnectCommand): Observable<BaseAPIResponse<ConnectBean>> {
            return RxUtils.mapObservable(cmd)
34
                    .flatMap { it ->
洪国微 committed
35 36 37 38 39 40 41 42 43 44
                        YDLHttpUtils.obtainApi(AudioNetAPi::class.java).connectListen(it)
                    }
        }

        /**
         * 通话开始回调
         *
         * @param param
         * @return
         */
45 46 47 48 49 50
//        fun connectStart(param: ConnectStartCommand): Observable<BaseAPIResponse<Any>> {
////            val list = YdlRetrofitUtils.getPostList(param)
//            var str = Gson().toJson(param)
//            val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str) as RequestBody
//            return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).connectStart(body)
//        }
洪国微 committed
51 52 53 54 55 56 57

        /**
         * 通话结束回调
         *
         * @param param
         * @return
         */
58 59 60 61 62 63
//        fun connectFinish(param: ConnectFinishCommand): Observable<BaseAPIResponse<Any>> {
////            val list = YdlRetrofitUtils.getPostList(param)
//            var str = Gson().toJson(param)
//            val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str) as RequestBody
//            return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).connectFinish(body)
//        }
洪国微 committed
64

65 66 67 68 69 70 71 72 73 74 75 76
        /**
         * 通话警告与异常回调
         *
         * @param param
         * @return
         */
        fun connectException(param: ConnectExceptionCommand): Observable<BaseAPIResponse<Any>> {
            var str = Gson().toJson(param)
            val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str) as RequestBody
            return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).connectException(body)
        }

洪国微 committed
77 78 79 80 81 82 83 84 85 86 87 88
        /**
         * 通知服务端发送推送
         */
        fun noticeServerPush(param: NoticePushCommand): Observable<BaseResponse<Any>> {
            var str = Gson().toJson(param)
            val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str) as RequestBody
            return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).noticeServerPush(body)
        }

        /**
         * 获取声网登录token
         */
89
        fun getAgoraToken(): Observable<BaseAPIResponse<AgoraTokenResponse>> {
洪国微 committed
90
            return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).getAgoraToken()
洪国微 committed
91
        }
严久程 committed
92 93 94 95

        /**
         * 获取声网登录token
         */
96
        fun listenToken(cmd: ListenTokenCmd): Observable<BaseResponse<ListenTokenBean>> {
严久程 committed
97 98
            return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).listenToken(NetworkParamsUtils.getMaps(cmd))
        }
99

严久程 committed
100
        fun callEndStatusUpdate(channelId: String, endStatus: Int, msg: String): Observable<BaseAPIResponse<Any>> {
101 102
            return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).callEndStatusUpdate(channelId, endStatus, msg)
        }
洪国微 committed
103 104
    }
}