* @param token 加入 RTC 房间的 token
* @param roomId 加入 RTC 房间的 id
* @param userId 加入 RTC 房间的 用户id
public static void joinRoom(String token, String roomId, String uid) {
MLog.d("joinChannel", "token:" + token + " roomId:" + roomId + " uid:" + uid);
if (mRTCVideo == null) {
mRTCRoom = mRTCVideo.createRTCRoom(roomId);
mRTCRoom.setRTCRoomEventHandler(mRTCRoomEventHandler);
UserInfo userInfo = new UserInfo(uid, null);
RTCRoomConfig roomConfig = new RTCRoomConfig(ChannelProfile.CHANNEL_PROFILE_COMMUNICATION,
mRTCRoom.joinRoom(token, userInfo, roomConfig);
* @param activity 游戏所在页面
private void initSdk(FragmentActivity activity, long gameId, String code) {
String appId = getAppId();
String appKey = getAppKey();
SudMGP.initSDK(activity, appId, appKey, isTestEnv(), new ISudListenerInitSDK() {
public void onSuccess() {
loadGame(activity, code, gameId);
public void onFailure(int errCode, String errMsg) {
Toast.makeText(activity, "initSDK onFailure:" + errMsg + "(" + errCode + ")", Toast.LENGTH_LONG).show();
delayLoadGame(activity, gameId);
* @param activity 游戏所在页面
private void loadGame(FragmentActivity activity, String code, long gameId) {
if (activity.isDestroyed() || !isRunning || gameId != playingGameId) {
sudFSMMGDecorator.setSudFSMMGListener(this);
ISudFSTAPP iSudFSTAPP = SudMGP.loadMG(activity, getUserId(), gameRoomId, code, gameId, getLanguageCode(), sudFSMMGDecorator);
if (iSudFSTAPP == null) {
Toast.makeText(activity, "loadMG params error", Toast.LENGTH_LONG).show();
delayLoadGame(activity, gameId);
sudFSTAPPDecorator.setISudFSTAPP(iSudFSTAPP);
// 获取游戏视图,将其抛回Activity进行展示
// Activity调用:gameContainer.addView(view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
gameView = iSudFSTAPP.getGameView();
onAddGameView(gameView);
* 文档:https://docs.sud.tech/zh-CN/app/Client/API/ISudFSMMG/onGetGameViewInfo.html
public void processOnGetGameViewInfo(View gameView, ISudFSMStateHandle handle) {
int gameViewWidth = gameView.getMeasuredWidth();
int gameViewHeight = gameView.getMeasuredHeight();
if (gameViewWidth > 0 && gameViewHeight > 0) {
notifyGameViewInfo(handle, gameViewWidth, gameViewHeight);
//如果游戏View未加载完成,则监听加载完成时回调
gameView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
gameView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int width = gameView.getMeasuredWidth();
int height = gameView.getMeasuredHeight();
notifyGameViewInfo(handle, width, height);
private void notifyGameViewInfo(ISudFSMStateHandle handle, int gameViewWidth, int gameViewHeight) {
GameViewInfoModel gameViewInfoModel = new GameViewInfoModel();
gameViewInfoModel.ret_code = 0;
gameViewInfoModel.view_size.width = gameViewWidth;
gameViewInfoModel.view_size.height = gameViewHeight;
getGameRect(gameViewInfoModel);
String json = SudJsonUtils.toJson(gameViewInfoModel);