视频通话"onReceiveNewSession"不调用QuickBlox-android



我尝试使用 quickblox 进行视频通话,但它不起作用,我开始通话,但在另一台设备上onReceiveNewSession没有通话。

这是我的代码:-

此活动开始通话:-

package com.example.group.travilling.travilling.chat;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.example.group.travilling.travilling.R;
import com.example.group.travilling.travilling.common.Common;
import com.quickblox.auth.QBAuth;
import com.quickblox.auth.session.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.exception.QBResponseException;
import com.quickblox.users.model.QBUser;
import com.quickblox.videochat.webrtc.QBRTCClient;
import com.quickblox.videochat.webrtc.QBRTCSession;
import com.quickblox.videochat.webrtc.QBRTCTypes;
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.exception.QBRTCException;
import com.quickblox.videochat.webrtc.view.QBRTCSurfaceView;
import com.quickblox.videochat.webrtc.view.QBRTCVideoTrack;
import org.webrtc.RendererCommon;
import org.webrtc.VideoRenderer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.quickblox.videochat.webrtc.QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_VIDEO;
public class call_activity extends AppCompatActivity {
SharedPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio_activity);
prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

QBChatService.ConfigurationBuilder chatServiceConfigurationBuilder = new QBChatService.ConfigurationBuilder();
chatServiceConfigurationBuilder.setSocketTimeout(180); //Sets chat socket's read timeout in seconds
chatServiceConfigurationBuilder.setKeepAlive(true); //Sets connection socket's keepAlive option.
QBChatService.setConfigurationBuilder(chatServiceConfigurationBuilder);

//        String login = "login";
//        String password = "password";
//        final QBUser user = new QBUser(login, password);
final QBUser user = new QBUser("u" + prefs.getInt("account_phone_chat", 0) + "", Common.pass);
// CREATE SESSION WITH USER
// If you use create session with user data,
// then the user will be logged in automatically
QBAuth.createSession().performAsync(new QBEntityCallback<QBSession>() {
@Override
public void onSuccess(final QBSession qbSession, Bundle bundle) {
user.setId(Integer.parseInt(prefs.getString("user_id","0")));
//                    qbUser.setPassword(BaseService.getBaseService().getToken());
if (!QBChatService.getInstance().isLoggedIn()) {
QBChatService.getInstance().login(user, new QBEntityCallback() {
@Override
public void onSuccess(Object o, Bundle bundle) {
call();
}
@Override
public void onError(QBResponseException e) {
call();
Log.e("errorwhyis!", e.getMessage());
}
});
//                mDialog.dismiss();
} else {
System.out.println("SFSSFFSFSFSDF");
call();
}
}

@Override
public void onError(QBResponseException e) {
Log.e("error", e.getMessage() + "");
}
});
}
private void call() {

//Add signalling manager
add_signlling_manager();
//Notify RTCClient that you are ready to receive calls
QBRTCClient.getInstance(getBaseContext()).prepareToProcessCalls();
//To listen for the callbacks use the following methods:
QBRTCClient.getInstance(getBaseContext()).addSessionCallbacksListener(new QBRTCClientSessionCallbacks() {
//            * Called each time when new session request is received.
public void onReceiveNewSession(QBRTCSession session) {
// obtain received user info
Map<String, String> userInfo = session.getUserInfo();
// .....
// ..... your code
// .....

// Set userInfo
// User can set any string key and value in user info
//                                Map<String,String> userInfo = new HashMap<String,String>();
//                                userInfo.put("Key", "Value");
// Accept incoming call
session.acceptCall(userInfo);
// Rejecting call
//                                session.rejectCall(userInfo);

//                                session.hangUp(userInfo);
}
/**
* Called in case when user didn't answer in timer expiration period
*/
public void onUserNotAnswer(QBRTCSession session, Integer userID) {
System.out.println("NOOOOOOAAAAAA");
}
/**
* Called in case when opponent has rejected you call
*/
public void onCallRejectByUser(QBRTCSession session, Integer userID, Map<String, String> userInfo) {
System.out.println("NOOOOOOAAAAAA22");
}
/**
* Called in case when opponent has accepted you call
*/
public void onCallAcceptByUser(QBRTCSession session, Integer userID, Map<String, String> userInfo) {
System.out.println("NOOOOOOAAAAAA233");

}
/**
* Called in case when opponent hung up
*/
@Override
public void onReceiveHangUpFromUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
}

/**
* Called in case when user didn't make any actions on received session
*/
public void onUserNoActions(QBRTCSession session, Integer userID) {
System.out.println("NOOOOOOAAAAAA555");
}
/**
* Called in case when session will close
*/
public void onSessionStartClose(QBRTCSession session) {
}
/**
* Called when session is closed.
*/
public void onSessionClosed(QBRTCSession session) {
}
});
//        QBRTCClient.getInstance(getBaseContext()).removeSessionsCallbacksListener(this);

//Track connection state
addSessionCallbacksListener(new QBRTCSessionConnectionCallbacks() {
@Override
public void onStartConnectToUser(QBRTCSession qbrtcSession, Integer integer) {
System.out.println("NOOOOOOAAAAAA88");
}
@Override
public void onConnectedToUser(QBRTCSession qbrtcSession, Integer integer) {
System.out.println("NOOOOOOAAAAAA999");
}
@Override
public void onConnectionClosedForUser(QBRTCSession qbrtcSession, Integer integer) {
}
@Override
public void onDisconnectedFromUser(QBRTCSession qbrtcSession, Integer integer) {
}
@Override
public void onDisconnectedTimeoutFromUser(QBRTCSession qbrtcSession, Integer integer) {
}
@Override
public void onConnectionFailedWithUser(QBRTCSession qbrtcSession, Integer integer) {
}
@Override
public void onError(QBRTCSession qbrtcSession, QBRTCException e) {
}
});

//Obtain video tracks via QBRTCClientVideoTracksCallbacks interface
addVideoTrackCallbacksListener(new QBRTCClientVideoTracksCallbacks() {
@Override
public void onLocalVideoTrackReceive(QBRTCSession qbrtcSession, QBRTCVideoTrack qbrtcVideoTrack) {
}
@Override
public void onRemoteVideoTrackReceive(QBRTCSession qbrtcSession, QBRTCVideoTrack qbrtcVideoTrack, Integer integer) {
}
});

start_call();
}
//Render video stream to view
private void fillVideoView(int userId, QBRTCSurfaceView videoView, QBRTCVideoTrack videoTrack,
boolean remoteRenderer) {
videoTrack.addRenderer(new VideoRenderer(videoView));
updateVideoView(videoView, !remoteRenderer, RendererCommon.ScalingType.SCALE_ASPECT_FILL);
}
private void updateVideoView(QBRTCSurfaceView surfaceView, boolean mirror, RendererCommon.ScalingType scalingType) {
surfaceView.setScalingType(scalingType);
surfaceView.setMirror(mirror);
surfaceView.requestLayout();
}

private void add_signlling_manager() {
try {
QBChatService.getInstance().getVideoChatWebRTCSignalingManager()
.addSignalingManagerListener(new QBVideoChatSignalingManagerListener() {
@Override
public void signalingCreated(QBSignaling qbSignaling, boolean createdLocally) {
if (!createdLocally) {
QBRTCClient.getInstance(getBaseContext()).addSignaling((QBWebRTCSignaling) qbSignaling);
}
}
});
} catch (NullPointerException e) {
}
}
//Prepare your activity class to audio/video calls
public void addSessionCallbacksListener(QBRTCSessionConnectionCallbacks callback) {
}
public void addVideoTrackCallbacksListener(QBRTCClientVideoTracksCallbacks callback) {
}
//and next method on QBRTCClient instance:
public void addSessionCallbacksListener(QBRTCClientSessionCallbacks callback) {
}

void start_call() {
//start call
QBRTCTypes.QBConferenceType qbConferenceType = QB_CONFERENCE_TYPE_VIDEO;
//Initiate opponents list
List<Integer> opponents = new ArrayList<Integer>();
opponents.add(Common.admin_id); //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("Test", "state");
//Init session
QBRTCSession session =
QBRTCClient.getInstance(this).createNewSessionWithOpponents(opponents, qbConferenceType);
//Start call
System.out.println("SSSSSSSSSSSTTTTTTTTTTTA");
session.startCall(userInfo);
}
}

而这项服务接听电话>

package com.example.group.test_calender.traveling_admin.booking.chat;

import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import com.example.group.test_calender.traveling_admin.booking.common.Common;
import com.quickblox.auth.QBAuth;
import com.quickblox.auth.session.QBSession;
import com.quickblox.auth.session.QBSettings;
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.exception.QBResponseException;
import com.quickblox.users.model.QBUser;
import com.quickblox.videochat.webrtc.QBRTCClient;
import com.quickblox.videochat.webrtc.QBRTCSession;
import com.quickblox.videochat.webrtc.callbacks.QBRTCClientSessionCallbacks;
import java.util.Map;
//import static com.dev.trueme.TrueMeConstants.TRUE_ME_USERNEME;
public class VideoCallService extends Service implements QBRTCClientSessionCallbacks {
public VideoCallService() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
QBSettings.getInstance().init(getBaseContext(), Common.APP_ID, Common.AUTH_KEY, Common.AUTH_SECURITY);
QBSettings.getInstance().setAccountKey(Common.ACCOUNT_KEY);
QBChatService.setDebugEnabled(true);
QBChatService.ConfigurationBuilder chatServiceConfigurationBuilder = new QBChatService.ConfigurationBuilder();
chatServiceConfigurationBuilder.setSocketTimeout(180); //Sets chat socket's read timeout in seconds
chatServiceConfigurationBuilder.setKeepAlive(true); //Sets connection socket's keepAlive option.
QBChatService.setConfigurationBuilder(chatServiceConfigurationBuilder);
Log.wtf("service", "start");
LoginChatService();

}catch (Exception e){
Log.wtf("ex",""+e);
}
return START_STICKY;
}

private void InitSignalling() {
QBChatService.getInstance().getVideoChatWebRTCSignalingManager()
.addSignalingManagerListener(new QBVideoChatSignalingManagerListener() {
@Override
public void signalingCreated(QBSignaling qbSignaling, boolean createdLocally) {
if (!createdLocally) {
QBRTCClient.getInstance(VideoCallService.this).addSignaling((QBWebRTCSignaling) qbSignaling);
}
}
});
}
public  void LoginChatService()
{

final QBUser user = new QBUser(Common.user, Common.pass);
//                    SharedPreferences s=getSharedPreferences("QBid",0);
user.setId(30586775);
QBAuth.createSession().performAsync(new QBEntityCallback<QBSession>() {
@Override
public void onSuccess(final QBSession qbSession, Bundle bundle) {
//                user.setId(qbSession.getUserId());
//                    qbUser.setPassword(BaseService.getBaseService().getToken());
if (!QBChatService.getInstance().isLoggedIn()) {
QBChatService.getInstance().login(user, new QBEntityCallback() {
@Override
public void onSuccess(Object o, Bundle bundle) {
ProcessCalls();
InitSignalling();
QBRTCClient.getInstance(getBaseContext()).addSessionCallbacksListener   (VideoCallService.this);
}
@Override
public void onError(QBResponseException e) {
Log.e("errorwhyis!", e.getMessage());
ProcessCalls();
InitSignalling();
QBRTCClient.getInstance(getBaseContext()).addSessionCallbacksListener(VideoCallService.this);
}
});
//                mDialog.dismiss();
} else {
System.out.println("SFSSFFSFSFSDF");
ProcessCalls();
InitSignalling();
QBRTCClient.getInstance(getBaseContext()).addSessionCallbacksListener(VideoCallService.this);
}
}

@Override
public void onError(QBResponseException e) {
Log.e("error", e.getMessage() + "");
}
});

}
private void ProcessCalls() {
QBRTCClient.getInstance(this).prepareToProcessCalls();
}

@Override
public void onReceiveNewSession(QBRTCSession qbrtcSession) {
System.out.println("oiioikjskdkj");
//        DataHolder.getInstance().setServiceData(qbrtcSession,qbrtcSession.getUserInfo());
startActivity(new Intent(this,VideoCallActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra("service",true));
}
@Override
public void onUserNoActions(QBRTCSession qbrtcSession, Integer integer) {
}
@Override
public void onSessionStartClose(QBRTCSession qbrtcSession) {
}
@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) {
}
@Override
public void onSessionClosed(QBRTCSession qbrtcSession) {
}
}

如果您有解决方案或示例可以帮助我,请帮助我。

谢谢。

确保您已完成以下步骤来建立WebRTC点对点连接。 添加本机库 - libjingle_peerconnection_so.so 文件。将每个平台的本机库:arm64-v8a,armeabi-v7a,x86,x86_64放在app/src/main/jniLibs文件夹下。您可以在/src/main/jniLibs 文件夹下的示例中找到本机文件。

检查 DOC 中的屏幕截图。

相关内容

  • 没有找到相关文章

最新更新