QuickBlox / quickblox-android-sdk

QuickBlox Android SDK includes code snippets with main use cases and framework JAR library.
BSD 3-Clause "New" or "Revised" License
417 stars 697 forks source link

Integarion into app #286

Closed lordmen99 closed 7 years ago

lordmen99 commented 8 years ago

Dear all, anyone have some guide and simple how add video call into app ? with latest sdk.. i cant find simple guide for that. Please if anyoone have success add video call function with quickblox. can share the code here

RomanPronin commented 8 years ago

Hi, @lordmen99. You can find all necessary information on this link, also here is the link to the source sample-videochat with latest sdk.

lordmen99 commented 8 years ago

hi thank you for fast reply..i mean i want to know more clearly for add video call codee into my android app. maybe u have some guide different from quickblox?

RomanPronin commented 8 years ago

Listen, can you tell me what difficulties do you have with official docs?. What do you want to clarify?

lordmen99 commented 8 years ago

yes, i plan add videochat into my app. where my app have 2 app running. similiar my app like this https://play.google.com/store/apps/details?id=com.automated.kosti .

i want know, simple code can direct to connect video call

RomanPronin commented 8 years ago

Here is one more link to Q-municate Android which includes audio/video calls. Hope, it helps you.

lordmen99 commented 8 years ago

Please correct this codes.. i run got error "FATAL EXCEPTION: main Process: com.xplancer.vidchater, PID: 2393 java.lang.IllegalArgumentException: User's id and password can't be null "

'package` com.xplancer.vidchater;

import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;

import com.quickblox.auth.QBAuth; import com.quickblox.auth.model.QBSession; import com.quickblox.chat.QBChatService; import com.quickblox.chat.QBSignaling; import com.quickblox.chat.QBWebRTCSignaling; import com.quickblox.chat.listeners.QBVideoChatSignalingManagerListener; import com.quickblox.core.QBEntityCallback; import com.quickblox.core.QBSettings; import com.quickblox.core.exception.QBResponseException; import com.quickblox.users.model.QBUser; import com.quickblox.videochat.webrtc.QBRTCClient; import com.quickblox.videochat.webrtc.QBRTCConfig; import com.quickblox.videochat.webrtc.QBRTCSession; import com.quickblox.videochat.webrtc.QBRTCTypes; import com.quickblox.videochat.webrtc.QBSignalingSpec; import com.quickblox.videochat.webrtc.callbacks.QBRTCClientSessionCallbacks; import com.quickblox.videochat.webrtc.callbacks.QBRTCClientVideoTracksCallbacks; import com.quickblox.videochat.webrtc.callbacks.QBRTCSessionConnectionCallbacks; import com.quickblox.videochat.webrtc.callbacks.QBRTCSignalingCallback; import com.quickblox.videochat.webrtc.exception.QBRTCException; import com.quickblox.videochat.webrtc.exception.QBRTCSignalException; import com.quickblox.videochat.webrtc.view.QBRTCVideoTrack; import com.quickblox.videochat.webrtc.view.RTCGLVideoView;

import org.webrtc.VideoCapturerAndroid; import org.webrtc.VideoRenderer;

import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;

public class MainActivity extends AppCompatActivity implements QBRTCClientSessionCallbacks, QBRTCClientVideoTracksCallbacks, QBRTCSignalingCallback, QBRTCSessionConnectionCallbacks {

static final String APP_ID = "39854";
static final String AUTH_KEY = "JtensAa9y4AM5Yk";
static final String AUTH_SECRET = "AsDFwwwxpr3LN5w";
static final String ACCOUNT_KEY = "7yvNe17TnjNUqDoPwfqp";

RTCGLVideoView LocalVideoView;
RTCGLVideoView remoteVideoView;

String login = "";
String password = "x6Bt0VDy5";

QBChatService chatService;
QBRTCClient rtcClient;

EditText et_user, et_paw, et_id;
Button btn_call, btn_login;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    et_user = (EditText) findViewById(R.id.et_caller_user);
    et_paw = (EditText) findViewById(R.id.et_caller_pw);
    et_id = (EditText) findViewById(R.id.et_caller_tid);
    btn_call = (Button) findViewById(R.id.btn_caller_call);
    btn_login = (Button) findViewById(R.id.btn_caller_login);

    LocalVideoView = (RTCGLVideoView) findViewById(R.id.localView);
    remoteVideoView = (RTCGLVideoView) findViewById(R.id.opponentView);

    btn_login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            login = et_user.getText().toString();
            password = et_paw.getText().toString();
            initializingQB();
        }
    });
    btn_call.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            starcall(Integer.parseInt(et_id.getText().toString()));

        }
    });

}

private void initializingQB() {
    QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);
    QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);

    final QBUser user = new QBUser();

// CREATE SESSION WITH USER // If you use create session with user data, // then the user will be logged in automatically QBAuth.createSession(user, new QBEntityCallback() { @Override public void onSuccess(QBSession session, Bundle args) {

            user.setId(session.getUserId());
            Toast.makeText(MainActivity.this, "Loging in!!!", Toast.LENGTH_LONG).show();
            Log.w("qb", "logedin app");
            // INIT CHAT SERVICE
            chatService = QBChatService.getInstance();
            Log.w("qb", "loging chat");
            // LOG IN CHAT SERVICE
            chatService.login(user, new QBEntityCallback<QBUser>() {

                @Override
                public void onSuccess(QBUser qbUser, Bundle args) {
                    Log.w("qb", "loged chat");
                    initQBRTCClient();

                }

                @Override
                public void onError(QBResponseException errors) {
                    Log.w("qb", "not loged\n" + errors.getMessage());
                    //error

                }
            });
        }

        @Override
        public void onError(QBResponseException errors) {
            //error
            Toast.makeText(MainActivity.this, "ERROR!!!\n" + errors.getMessage(), Toast.LENGTH_LONG).show();
        }
    });
}

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);
            }
        }
    });

    // Configure
    //

    QBRTCConfig.setMaxOpponentsCount(2);
    QBRTCConfig.setDisconnectTime(30);
    QBRTCConfig.setAnswerTimeInterval(301);
    QBRTCConfig.setDebugEnabled(true);

    //rtcClient.addVideoTrackCallbacksListener(this);

    // rtcSession.removeVideoTrackCallbacksListener(this);
    // Add activity as callback to RTCClient
    rtcClient.addSessionCallbacksListener(this);

    //rtcClient.addVideoTrackCallbacksListener(this);

    //QBRTCClient.getInstance(this).removeSessionCallbacksListener(this);
    // Start mange QBRTCSessions according to VideoCall parser's callbacks
    rtcClient.prepareToProcessCalls();

}

private void starcall(int tid) {

    //Set conference type

//There are two types of calls: // - QB_CONFERENCE_TYPE_VIDEO - for video call; // - QB_CONFERENCE_TYPE_AUDIO - for audio call; QBRTCTypes.QBConferenceType qbConferenceType = QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_VIDEO;

//Initiate opponents list List opponents = new ArrayList(); opponents.add(tid); //12345 - QBUser ID

//Set user information // User can set any string key and value in user info // Then retrieve this data from sessions which is returned in callbacks // and parse them as he wish Map<String, String> userInfo = new HashMap<>(); userInfo.put("key", "value");

//Init session QBRTCSession session = rtcClient.createNewSessionWithOpponents(opponents, qbConferenceType); session.addVideoTrackCallbacksListener(this); session.addSessionCallbacksListener(this); session.addSessionCallbacksListener(this);

//Start call session.startCall(userInfo); Log.w("qb", "startcall: " + String.valueOf(tid)); }

@Override
public void onReceiveNewSession(QBRTCSession qbrtcSession) {
    // obtain received user info
    Map<String, String> userInfo = qbrtcSession.getUserInfo();

    // .....
    // ..... your code
    // .....

    // Set userInfo
    // User can set any string key and value in user info
    userInfo = new HashMap<String, String>();
    userInfo.put("Key", "Value");

    // Accept incoming call

    qbrtcSession.addVideoTrackCallbacksListener(this);
    qbrtcSession.addSessionCallbacksListener(this);
    qbrtcSession.acceptCall(userInfo);

    Log.w("call", "accepted:" + String.valueOf(qbrtcSession.getSessionID()));
}

@Override
public void onUserNotAnswer(QBRTCSession qbrtcSession, Integer integer) {

}

@Override
public void onCallRejectByUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {

}

@Override
public void onCallAcceptByUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {

}

@Override
public void onReceiveHangUpFromUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {

}

public void onReceiveHangUpFromUser(QBRTCSession qbrtcSession, Integer integer) {

}

@Override
public void onUserNoActions(QBRTCSession qbrtcSession, Integer integer) {

}

@Override
public void onSessionClosed(QBRTCSession qbrtcSession) {

}

@Override
public void onSessionStartClose(QBRTCSession qbrtcSession) {

}

@Override
public void onLocalVideoTrackReceive(QBRTCSession qbrtcSession, QBRTCVideoTrack qbrtcVideoTrack) {
    Log.w("TAG", "onLocalVideoTrackReceive()");
    //  RTCGLVideoView videoView, QBRTCVideoTrack videoTrack, boolean remoteRenderer

    fillVideoView(LocalVideoView, qbrtcVideoTrack, false);

}

@Override
public void onRemoteVideoTrackReceive(QBRTCSession qbrtcSession, QBRTCVideoTrack qbrtcVideoTrack, Integer integer) {
    Log.w("TAG", "onRemoteVideoTrackReceive(),,,");

    fillVideoView(remoteVideoView, qbrtcVideoTrack, true);

}

private void fillVideoView(RTCGLVideoView videoView, QBRTCVideoTrack videoTrack, boolean remoteRenderer) {
    videoTrack.addRenderer(new VideoRenderer(remoteRenderer ?
            videoView.obtainVideoRenderer(RTCGLVideoView.RendererSurface.MAIN) :
            videoView.obtainVideoRenderer(RTCGLVideoView.RendererSurface.SECOND)));
}

@Override
public void onSuccessSendingPacket(QBSignalingSpec.QBSignalCMD qbSignalCMD, Integer integer) {

}

@Override
public void onErrorSendingPacket(QBSignalingSpec.QBSignalCMD qbSignalCMD, Integer integer, QBRTCSignalException e) {

}

@Override
public void onStartConnectToUser(QBRTCSession qbrtcSession, Integer integer) {
    Log.w("connection", "onStartConnectToUser");
}

@Override
public void onConnectedToUser(QBRTCSession qbrtcSession, Integer integer) {
    Log.w("connection", "onConnectedToUser");
}

@Override
public void onConnectionClosedForUser(QBRTCSession qbrtcSession, Integer integer) {
    Log.w("connection", "onConnectionClosedForUser");

}

@Override
public void onDisconnectedFromUser(QBRTCSession qbrtcSession, Integer integer) {
    Log.w("connection", "onDisconnectedFromUser");

}

@Override
public void onDisconnectedTimeoutFromUser(QBRTCSession qbrtcSession, Integer integer) {
    Log.w("connection", "onDisconnectedTimeoutFromUser");

}

@Override
public void onConnectionFailedWithUser(QBRTCSession qbrtcSession, Integer integer) {
    Log.w("connection", "onConnectionFailedWithUser");

}

@Override
public void onError(QBRTCSession qbrtcSession, QBRTCException e) {
    Log.w("connection", "onError");

}

}`

RomanPronin commented 8 years ago

All I can say, you should check whether your current user has id and password before you are doing chatService.login, and by yourself find out why it hasn't. Look at the sample videchat code more carefully.

lordmen99 commented 8 years ago

I want put auto execute for name and chatroom with my already app code. its correct? i use button click

public void onClick(View v) { switch (v.getId()) { case R.id.btnCall: if (driver != null) { String plat = driver.getCarModel(); String sopire = driver.getFirstName(); startActivity(new Intent(getActivity(),SplashActivity.class)); / if (!TextUtils.isEmpty(number)) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + number)); startActivity(callIntent); } / //createSession();

        }
lordmen99 commented 8 years ago

hi, i success until step session>signup>signin but when load OpponentsActivity get error like this =

=== REQUEST ==== 6ea0f7df-c5b6-4774-8d49-4bc12d4b9b42 === REQUEST GET https://api.quickblox.com/users/by_tags.json HEADERS QuickBlox-REST-API-Version=0.1.1 QB-SDK=Android 2.6.1 QB-Token=bccab230a7147655ef2caf49db61896ba9009bae PARAMETERS tags=null

i use this startActivity(new Intent(getActivity(),OpponentsActivity.class)) to call function.

how put tags not null??

RomanPronin commented 8 years ago

Hi, follow this link

lordmen99 commented 8 years ago

i change the step code, i try make direct callservice like this =

`QBUsers.signUp(user, new QBEntityCallback() {

                                        public void onSuccess(QBUser user, Bundle args) {
                                            Intent tempIntent = new Intent(getActivity(), CallService.class);
                                            PendingIntent pendingIntent = createPendingResult(Consts.EXTRA_LOGIN_RESULT_CODE, tempIntent, 0);
                                            CallService.start(getActivity(),user, tempIntent);`

but for createPendingResult is in mode red. how make method direct for createPendingResult ?

RomanPronin commented 8 years ago

In CallService.start wrong 3rd argument type, required PendingIntent, not Intent.

lordmen99 commented 8 years ago

add my skype please = poster994. i want fast fix few code vidchat

RomanPronin commented 8 years ago

If you wanna get more support you may choose one of the plan.

lordmen99 commented 8 years ago

http://image.prntscr.com/image/9b1281bd5b024943ac0da0ebf4caa4d3.png see in blue box. how add method for that

RomanPronin commented 8 years ago

Just add getActivity().createPendingResult(Consts.EXTRA_LOGIN_RESULT_CODE, tempIntent, 0);

lordmen99 commented 8 years ago

until now success, but user cant load .. see this http://prntscr.com/ci8dnd

i can get tags for name roomchat but for user cant load. then when click name in list get bad connection internet error messages. what are my missing codes :)

vfite commented 7 years ago

Closed as for Long time inactivity.