add[声望升级]
This commit is contained in:
@@ -76,6 +76,17 @@ public class CommonAppConfig {
|
||||
public static boolean isGetNewWrap = false;//是否获取到新的包裹礼物
|
||||
public static int alert_time = 1;
|
||||
public static int alert_end_time = 1;
|
||||
public static String SWToken = ""; //声网Token
|
||||
public static final String SWChannelPrefix = "g";
|
||||
|
||||
|
||||
/**
|
||||
* 获取通道
|
||||
* @return
|
||||
*/
|
||||
public static String getChannelName() {
|
||||
return SWChannelPrefix+ getInstance().getUid();
|
||||
}
|
||||
|
||||
private CommonAppConfig() {
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.yunbao.common.bean;
|
||||
|
||||
/**
|
||||
* 声网token
|
||||
*/
|
||||
public class SwTokenModel extends BaseModel {
|
||||
private String token;
|
||||
|
||||
public SwTokenModel() {
|
||||
}
|
||||
|
||||
public SwTokenModel(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@ import com.yunbao.common.bean.StarChallengeStatusModel;
|
||||
import com.yunbao.common.bean.SudGameUserModel;
|
||||
import com.yunbao.common.bean.SudRoomListModel;
|
||||
import com.yunbao.common.bean.SudgameCodeModel;
|
||||
import com.yunbao.common.bean.SwTokenModel;
|
||||
import com.yunbao.common.bean.UserAreaBean;
|
||||
import com.yunbao.common.bean.UserAvatarSelectBean;
|
||||
import com.yunbao.common.bean.VipModel;
|
||||
@@ -1192,4 +1193,6 @@ public interface PDLiveApi {
|
||||
Observable<ResponseModel<CheckUpgradesModel>> checkUpgrades(@Query("liveuid") String liveUid);
|
||||
@GET("/api/public/?service=Guard.getRewards")
|
||||
Observable<ResponseModel<Object>> guardGetRewards(@Query("guard_level") String guardLevel,@Query("liveuid") String liveUid);
|
||||
@GET("/api/public/?service=Tx.getShengwangToken")
|
||||
Observable<ResponseModel<SwTokenModel>> getSwToken();
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ import com.yunbao.common.bean.StarChallengeStatusModel;
|
||||
import com.yunbao.common.bean.SudGameUserModel;
|
||||
import com.yunbao.common.bean.SudRoomListModel;
|
||||
import com.yunbao.common.bean.SudgameCodeModel;
|
||||
import com.yunbao.common.bean.SwTokenModel;
|
||||
import com.yunbao.common.bean.UserAreaBean;
|
||||
import com.yunbao.common.bean.UserAvatarSelectBean;
|
||||
import com.yunbao.common.bean.VipModel;
|
||||
@@ -3133,7 +3134,6 @@ public class LiveNetManager {
|
||||
}
|
||||
}
|
||||
}).isDisposed();
|
||||
|
||||
}
|
||||
|
||||
public void guardGetRewards(String guardLevel, String liveUid, HttpCallback<Object> callback) {
|
||||
@@ -3160,6 +3160,30 @@ public class LiveNetManager {
|
||||
|
||||
}
|
||||
|
||||
public void getSwToken( HttpCallback<SwTokenModel> callback) {
|
||||
API.get().pdLiveApi(mContext)
|
||||
.getSwToken()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<ResponseModel<SwTokenModel>>() {
|
||||
@Override
|
||||
public void accept(ResponseModel<SwTokenModel> listResponseModel) throws Exception {
|
||||
if (callback != null) {
|
||||
callback.onSuccess(listResponseModel.getData().getInfo());
|
||||
}
|
||||
}
|
||||
}, new Consumer<Throwable>() {
|
||||
@Override
|
||||
public void accept(Throwable throwable) throws Exception {
|
||||
throwable.printStackTrace();
|
||||
if (callback != null) {
|
||||
callback.onError(mContext.getString(R.string.net_error));
|
||||
}
|
||||
}
|
||||
}).isDisposed();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 直播间取消网络请求
|
||||
*/
|
||||
|
||||
@@ -5,15 +5,18 @@ import android.content.Context;
|
||||
import android.view.SurfaceView;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.CommonAppContext;
|
||||
import com.yunbao.common.manager.base.BaseCacheManager;
|
||||
import com.yunbao.common.utils.L;
|
||||
import com.yunbao.common.utils.StringUtil;
|
||||
|
||||
import io.agora.rtc2.ChannelMediaOptions;
|
||||
import io.agora.rtc2.Constants;
|
||||
import io.agora.rtc2.IRtcEngineEventHandler;
|
||||
import io.agora.rtc2.RtcEngine;
|
||||
import io.agora.rtc2.RtcConnection;
|
||||
import io.agora.rtc2.RtcEngineConfig;
|
||||
import io.agora.rtc2.RtcEngineEx;
|
||||
import io.agora.rtc2.video.VideoCanvas;
|
||||
|
||||
/**
|
||||
@@ -24,12 +27,9 @@ public class SWAuManager extends BaseCacheManager {
|
||||
// 填写项目的 App ID,可在声网控制台中生成
|
||||
public static final String shengwang_appId = "4cf0376582d742ac8a96778b25b1079e";
|
||||
// 填写频道名
|
||||
public static final String shengwang_channelName = "12";
|
||||
// 填写声网控制台中生成的临时 Token
|
||||
public static final String shengwang_token = "007eJxSYJi477Xju22xV7ov7GfzzOnbtCU0IuK9+YuwWf2uLPGnl8xRYDBJTjMwNjcztTBKMTcxSky2SLQ0Mze3SDIyTTI0MLdMPWQrltYQyMjw/4kCCyMDBIL4TAyGRiwMlpaWloAAAAD//w/TIFY=";
|
||||
private Activity mContext;
|
||||
public static SWAuManager manager;
|
||||
private RtcEngine mRtcEngine;
|
||||
private RtcEngineEx mRtcEngine;
|
||||
private FrameLayout audienceContainer; //主播视图
|
||||
private FrameLayout pkContainer1; //pk主播视图1
|
||||
private FrameLayout pkContainer2; //pk主播视图2
|
||||
@@ -64,7 +64,7 @@ public class SWAuManager extends BaseCacheManager {
|
||||
config.mAppId = SWAuManager.shengwang_appId;
|
||||
config.mEventHandler = mRtcEventHandler;
|
||||
// 创建并初始化 RtcEngine
|
||||
mRtcEngine = RtcEngine.create(config);
|
||||
mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Check the error.");
|
||||
}
|
||||
@@ -76,7 +76,6 @@ public class SWAuManager extends BaseCacheManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* guanzhong
|
||||
* 加入房间
|
||||
*/
|
||||
public void joinRoom(String strUid, String token, String channelName) {
|
||||
@@ -96,11 +95,60 @@ public class SWAuManager extends BaseCacheManager {
|
||||
options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE;
|
||||
// 直播场景下,设置频道场景为 BROADCASTING (直播场景)
|
||||
options.audienceLatencyLevel = Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY; // 觀眾走極速直播
|
||||
|
||||
// 使用临时 Token 加入频道,自行指定用户 ID 并确保其在频道内的唯一性
|
||||
mRtcEngine.joinChannel(token, channelName, uid, options);
|
||||
}
|
||||
|
||||
|
||||
public void joinExRoomEx(String strUid, String token, String channelName) {
|
||||
int uid;
|
||||
if (StringUtil.isEmpty(strUid)) {
|
||||
uid = 0;
|
||||
} else {
|
||||
uid = Integer.parseInt(strUid);
|
||||
}
|
||||
|
||||
// 创建 ChannelMediaOptions 对象,并进行配置
|
||||
ChannelMediaOptions options = new ChannelMediaOptions();
|
||||
// 根据场景将用户角色设置为 AUDIENCE (观众)
|
||||
options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE;
|
||||
// 直播场景下,设置频道场景为 BROADCASTING (直播场景)
|
||||
options.audienceLatencyLevel = Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY; // 觀眾走極速直播
|
||||
options.autoSubscribeVideo = true;
|
||||
options.autoSubscribeAudio = true;
|
||||
|
||||
RtcConnection rtcConnection = new RtcConnection();
|
||||
rtcConnection.channelId = "g99411"; //對方主播的頻道
|
||||
rtcConnection.localUid = 99412;//自己的ID
|
||||
|
||||
mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() {
|
||||
@Override
|
||||
public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
|
||||
super.onJoinChannelSuccess(channel, uid, elapsed);
|
||||
L.eSw("onJoinChannelSuccess:" + channel + " uid " +uid+ " elapsed: " + elapsed);
|
||||
|
||||
SurfaceView surfaceView = new SurfaceView(mContext);
|
||||
surfaceView.setZOrderMediaOverlay(true);
|
||||
pkContainer1.addView(surfaceView);
|
||||
|
||||
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, 99411);
|
||||
|
||||
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int err) {
|
||||
super.onError(err);
|
||||
L.eSw("onError:" + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getChannelName(String liveUid) {
|
||||
return CommonAppConfig.SWChannelPrefix + liveUid;
|
||||
}
|
||||
|
||||
//远程监听
|
||||
private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() {
|
||||
@Override
|
||||
@@ -110,7 +158,7 @@ public class SWAuManager extends BaseCacheManager {
|
||||
@Override
|
||||
public void run() {
|
||||
// 获取 uid 后,设置远端视频视图
|
||||
setupRemoteVideo(uid);
|
||||
//setupRemoteVideo(uid);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,17 +5,23 @@ import android.content.Context;
|
||||
import android.view.SurfaceView;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.CommonAppContext;
|
||||
import com.yunbao.common.bean.SwTokenModel;
|
||||
import com.yunbao.common.http.base.HttpCallback;
|
||||
import com.yunbao.common.http.live.LiveNetManager;
|
||||
import com.yunbao.common.manager.base.BaseCacheManager;
|
||||
import com.yunbao.common.utils.L;
|
||||
import com.yunbao.common.utils.StringUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import cn.rongcloud.rtc.base.RCRTCParamsType;
|
||||
import io.agora.rtc2.ChannelMediaOptions;
|
||||
import io.agora.rtc2.Constants;
|
||||
import io.agora.rtc2.IRtcEngineEventHandler;
|
||||
import io.agora.rtc2.RtcConnection;
|
||||
import io.agora.rtc2.RtcEngine;
|
||||
import io.agora.rtc2.RtcEngineConfig;
|
||||
import io.agora.rtc2.RtcEngineEx;
|
||||
import io.agora.rtc2.video.VideoCanvas;
|
||||
import io.agora.rtc2.video.VideoEncoderConfiguration;
|
||||
|
||||
@@ -27,12 +33,9 @@ public class SWManager extends BaseCacheManager {
|
||||
// 填写项目的 App ID,可在声网控制台中生成
|
||||
public static final String shengwang_appId = "4cf0376582d742ac8a96778b25b1079e";
|
||||
// 填写频道名
|
||||
public static final String shengwang_channelName = "12";
|
||||
// 填写声网控制台中生成的临时 Token
|
||||
public static final String shengwang_token = "007eJxTYOD6Iv3buTHm6666BKY1Cr7mUZU3tY0eHH5qbF4jv5nNukqBwSQ5zcDY3MzUwijF3MQoMdki0dLM3Nwiycg0ydDA3DL1xX/RtIZARgb+3ExWRgYIBPGZGAyNGBgAhDMb8Q==";
|
||||
private Activity mContext;
|
||||
public static SWManager manager;
|
||||
private RtcEngine mRtcEngine;
|
||||
private RtcEngineEx mRtcEngine;
|
||||
private int uid;
|
||||
VideoEncoderConfiguration cfg;
|
||||
private FrameLayout anchorContainer; //主播视图
|
||||
@@ -79,7 +82,7 @@ public class SWManager extends BaseCacheManager {
|
||||
config.mAppId = SWManager.shengwang_appId;
|
||||
config.mEventHandler = mRtcEventHandler;
|
||||
// 创建并初始化 RtcEngine
|
||||
mRtcEngine = RtcEngine.create(config);
|
||||
mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Check the error.");
|
||||
}
|
||||
@@ -131,7 +134,6 @@ public class SWManager extends BaseCacheManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建房间
|
||||
*/
|
||||
@@ -143,6 +145,68 @@ public class SWManager extends BaseCacheManager {
|
||||
mRtcEngine.joinChannel(token, channelName, uid, options);
|
||||
}
|
||||
|
||||
public void updateMyVideoView(FrameLayout frameLayout, String channelName) {
|
||||
mRtcEngine.setupRemoteVideoEx(null, null);
|
||||
|
||||
RtcConnection rtcConnection = new RtcConnection();
|
||||
rtcConnection.channelId = channelName; //自己频道名称
|
||||
rtcConnection.localUid = uid;//自己的ID
|
||||
|
||||
SurfaceView surfaceView = new SurfaceView(mContext);
|
||||
surfaceView.setZOrderMediaOverlay(true);
|
||||
frameLayout.addView(surfaceView);
|
||||
|
||||
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid);
|
||||
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
|
||||
}
|
||||
|
||||
|
||||
public void joinExRoomEx(String strUid, String token,String toUid, String channelName) {
|
||||
int tempUid;
|
||||
if (StringUtil.isEmpty(strUid)) {
|
||||
tempUid = 0;
|
||||
} else {
|
||||
tempUid = Integer.parseInt(strUid);
|
||||
}
|
||||
|
||||
// 创建 ChannelMediaOptions 对象,并进行配置
|
||||
ChannelMediaOptions options = new ChannelMediaOptions();
|
||||
// 根据场景将用户角色设置为 AUDIENCE (观众)
|
||||
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
|
||||
options.autoSubscribeVideo = true;
|
||||
options.autoSubscribeAudio = true;
|
||||
options.publishMicrophoneTrack = false;
|
||||
options.publishCameraTrack = false;
|
||||
|
||||
RtcConnection rtcConnection = new RtcConnection();
|
||||
rtcConnection.channelId = channelName; //對方主播的頻道
|
||||
rtcConnection.localUid = tempUid;//自己的ID
|
||||
L.eSw("strUid:" + tempUid + "_token:" + token + "_channelName:" + channelName);
|
||||
mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() {
|
||||
@Override
|
||||
public void onJoinChannelSuccess(String channel, int scUid, int elapsed) {
|
||||
super.onJoinChannelSuccess(channel, scUid, elapsed);
|
||||
L.eSw("onJoinChannelSuccess:" + channel + " uid " + scUid + " elapsed: " + elapsed);
|
||||
mContext.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SurfaceView surfaceView = new SurfaceView(mContext);
|
||||
surfaceView.setZOrderMediaOverlay(true);
|
||||
pkContainer1.addView(surfaceView);
|
||||
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid));
|
||||
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int err) {
|
||||
super.onError(err);
|
||||
L.eSw("onError:" + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//远程监听
|
||||
private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() {
|
||||
@Override
|
||||
@@ -152,7 +216,7 @@ public class SWManager extends BaseCacheManager {
|
||||
@Override
|
||||
public void run() {
|
||||
// 获取 uid 后,设置远端视频视图
|
||||
setupRemoteVideo(uid);
|
||||
//setupRemoteVideo(uid);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -170,8 +234,36 @@ public class SWManager extends BaseCacheManager {
|
||||
super.onError(err);
|
||||
ToastUtil.show("onError:" + err);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTokenPrivilegeWillExpire(String token) {
|
||||
super.onTokenPrivilegeWillExpire(token);
|
||||
refreshToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestToken() {
|
||||
super.onRequestToken();
|
||||
refreshToken();
|
||||
}
|
||||
};
|
||||
|
||||
private void refreshToken() {
|
||||
LiveNetManager.get(mContext).getSwToken(new HttpCallback<SwTokenModel>() {
|
||||
@Override
|
||||
public void onSuccess(SwTokenModel data) {
|
||||
if (mRtcEngine != null) {
|
||||
mRtcEngine.renewToken(data.getToken());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//设置对方主播视图
|
||||
private void setupRemoteVideo(int uid) {
|
||||
SurfaceView surfaceView = new SurfaceView(mContext);
|
||||
|
||||
@@ -12,10 +12,18 @@ public class L {
|
||||
|
||||
private final static String TAG = "log--->";
|
||||
|
||||
private final static String TAG_SW = "log--->TAG_SW";
|
||||
|
||||
public static void e(String s) {
|
||||
e(TAG, s);
|
||||
}
|
||||
|
||||
public static void eSw(String s) {
|
||||
if (sDeBug) {
|
||||
Log.e(TAG_SW, s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void e(String tag, String s) {
|
||||
if (sDeBug) {
|
||||
Log.e(tag, s);
|
||||
|
||||
Reference in New Issue
Block a user