Java Code Examples for io.rong.imlib.RongIMClient#connect()

The following examples show how to use io.rong.imlib.RongIMClient#connect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainPageActivity.java    From sealrtc-android with MIT License 5 votes vote down vote up
/** 使用小乔环境 */
private void connectForXQ(final boolean isLive) {
    String token = SessionManager.getInstance().getString(ServerUtils.TOKEN_PRIVATE_CLOUD_KEY);
    FinLog.i(TAG, "private_Cloud_tokne : " + token);
    if (TextUtils.isEmpty(token)) {
        getTokenForXQ(isLive);
        return;
    }
    RongIMClient.connect(token, new RongIMClient.ConnectCallback() {
        public void onTokenIncorrect() {
            getTokenForXQ(isLive);
        }

        @Override
        public void onDatabaseOpened(DatabaseOpenStatus code) {}

        @Override
        public void onSuccess(String s) {
            FinLog.d(TAG, "IM  connectForXQ success ");
            if (isLive) {
                jumpLive();
            } else {
                connectToRoom();
            }
        }

        @Override
        public void onError(RongIMClient.ConnectionErrorCode errorCode) {
            Toast.makeText(MainPageActivity.this, "连接IM失败,请稍后重试", Toast.LENGTH_SHORT).show();
            if (errorCode == ConnectionErrorCode.RC_CONN_TOKEN_INCORRECT) {
                onTokenIncorrect();
            }
        }
    });
}
 
Example 2
Source File: MainAtPresenter.java    From LQRWeChat with MIT License 5 votes vote down vote up
/**
 * 建立与融云服务器的连接
 *
 * @param token
 */
private void connect(String token) {

    if (UIUtils.getContext().getApplicationInfo().packageName.equals(MyApp.getCurProcessName(UIUtils.getContext()))) {

        /**
         * IMKit SDK调用第二步,建立与服务器的连接
         */
        RongIMClient.connect(token, new RongIMClient.ConnectCallback() {

            /**
             * Token 错误,在线上环境下主要是因为 Token 已经过期,您需要向 App Server 重新请求一个新的 Token
             */
            @Override
            public void onTokenIncorrect() {
                LogUtils.e("--onTokenIncorrect");
            }

            /**
             * 连接融云成功
             * @param userid 当前 token
             */
            @Override
            public void onSuccess(String userid) {
                LogUtils.e("--onSuccess---" + userid);
                BroadcastManager.getInstance(mContext).sendBroadcast(AppConst.UPDATE_CONVERSATIONS);
            }

            /**
             * 连接融云失败
             * @param errorCode 错误码,可到官网 查看错误码对应的注释
             */
            @Override
            public void onError(RongIMClient.ErrorCode errorCode) {
                LogUtils.e("--onError" + errorCode);
                UIUtils.showToast(UIUtils.getString(R.string.disconnect_server));
            }
        });
    }
}