Example #1
0
  private void loadChatHistory() {
    QBRequestGetBuilder customObjectRequestBuilder = new QBRequestGetBuilder();
    customObjectRequestBuilder.setPagesLimit(100);
    customObjectRequestBuilder.sortDesc("date_sent");

    QBChatService.getDialogMessages(
        dialog,
        customObjectRequestBuilder,
        new QBEntityCallbackImpl<ArrayList<QBChatMessage>>() {
          @Override
          public void onSuccess(ArrayList<QBChatMessage> messages, Bundle args) {

            adapter = new ChatAdapter(ChatActivity.this, new ArrayList<QBChatMessage>());
            messagesContainer.setAdapter(adapter);

            for (int i = messages.size() - 1; i >= 0; --i) {
              QBChatMessage msg = messages.get(i);
              showMessage(msg);
            }

            progressBar.setVisibility(View.GONE);
          }

          @Override
          public void onError(List<String> errors) {
            if (!ChatActivity.this.isFinishing()) {
              AlertDialog.Builder dialog = new AlertDialog.Builder(ChatActivity.this);
              dialog.setMessage("load chat history errors: " + errors).create().show();
            }
          }
        });
  }
  public void addConversationFragmentReceiveCall() {

    QBRTCSession session = getCurrentSession();

    if (getCurrentSession() != null) {
      Integer myId = QBChatService.getInstance().getUser().getId();
      ArrayList<Integer> opponentsWithoutMe = new ArrayList<>(session.getOpponents());
      opponentsWithoutMe.remove(new Integer(myId));
      opponentsWithoutMe.add(session.getCallerID());

      ArrayList<QBUser> opponents =
          DataHolder.getUsersByIDs(
              opponentsWithoutMe.toArray(new Integer[opponentsWithoutMe.size()]));
      SettingsUtil.setSettingsStrategy(opponents, getDefaultSharedPrefs(), this);
      ConversationFragment fragment =
          ConversationFragment.newInstance(
              opponents,
              DataHolder.getUserNameByID(session.getCallerID()),
              session.getConferenceType(),
              session.getUserInfo(),
              StartConversetionReason.INCOME_CALL_FOR_ACCEPTION,
              getCurrentSession().getSessionID());
      // Start conversation fragment
      audioManager.init();
      FragmentExecuotr.addFragment(
          getFragmentManager(), R.id.fragment_container, fragment, CONVERSATION_CALL_FRAGMENT);
    }
  }
  private void logoutSession() {
    try {
      DataHolder.setLoggedUser(null);
      QBRTCClient.getInstance(this).destroy();

      // comment if you haven't started ping alarm
      ChatPingAlarmManager.onDestroy();
      QBChatService.getInstance().logout();
    } catch (SmackException.NotConnectedException e) {
      e.printStackTrace();
    }
  }
  private void initQBRTCClient() {
    rtcClient = QBRTCClient.getInstance(this);
    // Add signalling manager
    QBChatService.getInstance()
        .getVideoChatWebRTCSignalingManager()
        .addSignalingManagerListener(
            new QBVideoChatSignalingManagerListener() {
              @Override
              public void signalingCreated(QBSignaling qbSignaling, boolean createdLocally) {
                if (!createdLocally) {
                  rtcClient.addSignaling((QBWebRTCSignaling) qbSignaling);
                }
              }
            });

    rtcClient.setCameraErrorHendler(
        new VideoCapturerAndroid.CameraErrorHandler() {
          @Override
          public void onCameraError(final String s) {
            CallActivity.this.runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    Toaster.longToast(s);
                  }
                });
          }
        });

    // Configure
    //
    QBRTCConfig.setMaxOpponentsCount(6);
    QBRTCConfig.setDisconnectTime(30);
    QBRTCConfig.setAnswerTimeInterval(30l);
    QBRTCConfig.setStatsReportInterval(60);
    QBRTCConfig.setDebugEnabled(true);

    // Add activity as callback to RTCClient
    rtcClient.addSessionCallbacksListener(this);
    // Start mange QBRTCSessions according to VideoCall parser's callbacks
    rtcClient.prepareToProcessCalls();

    QBChatService.getInstance()
        .addConnectionListener(
            new AbstractConnectionListener() {

              @Override
              public void connectionClosedOnError(Exception e) {
                showNotificationPopUp(R.string.connection_was_lost, true);
              }

              @Override
              public void reconnectionSuccessful() {
                showNotificationPopUp(R.string.connection_was_lost, false);
              }

              @Override
              public void reconnectingIn(int seconds) {
                Log.i(TAG, "reconnectingIn " + seconds);
              }
            });
  }