【问题标题】:QuickBlox android session userinfo is nullQuickBlox android 会话用户信息为空
【发布时间】:2017-11-06 12:34:20
【问题描述】:

我正在使用用于 Android 23 API 的 quickblox。我想在呼叫建立之前将用户信息从一个呼叫者传递到另一个呼叫者。 为此,我使用了 QBRTCSession 的“用户信息”部分并放入了一个键值对。但对于另一端,它为“userinfo”提供空值。有人可以提出可能的原因并提出解决方案吗?

两个调用的会话 ID 相同。开始调用函数-

  private void startCall(boolean isVideoCall) {
    if (opponentsAdapter.getSelectedItems().size() > Consts.MAX_OPPONENTS_COUNT) {
        Toaster.longToast(String.format(getString(R.string.error_max_opponents_count),
                Consts.MAX_OPPONENTS_COUNT));
        return;
    }
    Log.d(TAG
            , "startCall()");
    //ArrayList<Integer> opponentsList = CollectionsUtils.getIdsSelectedOpponents(opponentsAdapter.getSelectedItems());
    ArrayList<Integer> opponentsList = new ArrayList<>();
    opponentsList.add(currentOpponentsList.get(0).getId());
    QBRTCTypes.QBConferenceType conferenceType = isVideoCall
            ? QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_VIDEO
            : QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_AUDIO;
    QBRTCClient qbrtcClient = QBRTCClient.getInstance(getApplicationContext());
    QBRTCSession newQbRtcSession = qbrtcClient.createNewSessionWithOpponents(opponentsList, conferenceType);
    newQbRtcSession.getUserInfo().put("som","name");
    Log.v("SessionThing",newQbRtcSession.getSessionDescription().toString());

    WebRtcSessionManager.getInstance(this).setCurrentSession(newQbRtcSession);
 //   newQbRtcSession.

    PushNotificationSender.sendPushMessage(opponentsList, "Hello"+currentUser.getFullName());
    Toast.makeText(getApplicationContext(),name,Toast.LENGTH_LONG).show();
    CallActivity.start(this, false);

    Log.d(TAG, "conferenceType = " + conferenceType);
}

通话中-

  public void onReceiveNewSession(final QBRTCSession session) {
    Log.d("userinfo_needed", "Session " + session.getSessionID() + " are income");
    Log.v("qbrtcsession",session.getSessionDescription().toString());
    userInfo = session.getUserInfo();
    if (getCurrentSession() != null) {
        //userInfo = session.getUserInfo();
        Log.d(TAG, "Stop new session. Device now is busy");
        session.rejectCall(null);
    }
}

In IncomeCallFragment - toast 给出 null

  private void initUI(View view) {
    callTypeTextView = (TextView) view.findViewById(R.id.call_type);

    ImageView callerAvatarImageView = (ImageView) view.findViewById(R.id.image_caller_avatar);
    callerAvatarImageView.setBackgroundDrawable(getBackgroundForCallerAvatar(currentSession.getCallerID()));

    TextView callerNameTextView = (TextView) view.findViewById(R.id.text_caller_name);

    QBUser callerUser = qbUserDbManager.getUserById(currentSession.getCallerID());
    callerNameTextView.setText(UsersUtils.getUserNameOrId(callerUser, currentSession.getCallerID()));
    Toast.makeText(getActivity().getApplicationContext(),currentSession.getSessionDescription().getUserInfo()+" ", Toast.LENGTH_LONG).show();
    TextView otherIncUsersTextView = (TextView) view.findViewById(R.id.text_other_inc_users);
    otherIncUsersTextView.setText(getOtherIncUsersNames());

    alsoOnCallText = (TextView) view.findViewById(R.id.text_also_on_call);
    setVisibilityAlsoOnCallTextView();

    rejectButton = (ImageButton) view.findViewById(R.id.image_button_reject_call);
    takeButton = (ImageButton) view.findViewById(R.id.image_button_accept_call);
    accept();
}

【问题讨论】:

  • 你在哪里调用 session.startcall() .??
  • 你得到答案了吗?
  • @user2828360 你有什么解决办法吗?请回复

标签: android session webrtc quickblox


【解决方案1】:

一旦你创建了会话集地图在会话中开始调用:

public static Map<String,String> createSessionUserInfo(){
    // Make sure you do not add anything null in this Map. Otherwise it will throw Exception,
    // So add blank string instead of null
    Map<String,String> userInfo=new HashMap<>();
    userInfo.put("img_user" , "img_url_here");
    userInfo.put("name_user" , "name_here");
    return userInfo;
}

然后添加此信息以开始通话:

 Map<String,String> userInfo= createSessionUserInfo();
            currentCallSession.startCall(userInfo);

在对手端,您将在 onReceiveNewSession() 中收到此会话及其默认行为。:

 @Override
public void onReceiveNewSession(final QBRTCSession qbrtcSession) {
    try {
        Map<String, String> userSessionInfo = qbrtcSession.getUserInfo();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

如果您仍然遇到问题,请告诉我。

【讨论】:

  • 我们试过了,但还是不行,好像连onReceiveNewSession()方法都没有调用。这是在我们的开始调用中- QBRTCSession newQbRtcSession = qbrtcClient.createNewSessionWithOpponents(opponentsList, meetingType); Map userinfo = new HashMap(); userinfo.put("a",name); newQbRtcSession.startCall(userinfo); WebRtcSessionManager.getInstance(this).setCurrentSession(newQbRtcSession);我们正在使用 Quickblox 的视频通话示例应用程序。
  • 您确定您在地图中传递的名称不为空或空白??用代码编辑您的问题..
  • 我没有看到你的 session.startcall(userInfo) 调用。你在哪里叫它?
  • @ADM 。对我来说,接收方得到了 userinfo null 。发送方代码如下。 WebRtcSessionManager.getInstance(this).setCurrentSession(newQbRtcSession); WebRtcSessionManager.getInstance(this).getCurrentSession().startCall(userInfo);
  • 在这种情况下你确定userInfo为null还是为空调试代码。
猜你喜欢
  • 2016-05-21
  • 2014-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多