我正在尝试在Android中使用WebRtc
实施QuickBlox
。在本教程之后,我完成了以下编码。我面临以下问题。
我不这么认为我的电话是从用户A转到用户B.
我没有收到有关来电的通知(可能是因为来电根本没有来)。
当我点击接受按钮时,我收到以下错误。
E / AndroidRuntime(11413):致命异常:Thread-37793 E / AndroidRuntime(11413):处理:com.example.testqb,PID:11413 E / AndroidRuntime(11413):java.lang.NullPointerException:尝试调用虚方法'void com.quickblox.videochat.model.listeners.OnQBVideoChatListener.runOnVideoChatStateChangeUI(com.quickblox.videochat.model.objects.CallState,com.quickblox。 videochat.model.objects.VideoChatConfig)'对空对象引用 E / AndroidRuntime(11413):at com.quickblox.videochat.core.objects.XMPPConnectionClient $ CallingRunnable.sendNotAnsweredCallback(XMPPConnectionClient.java:173) E / AndroidRuntime(11413):at com.quickblox.videochat.core.objects.XMPPConnectionClient $ CallingRunnable.run(XMPPConnectionClient.java:158) E / AndroidRuntime(11413):在java.lang.Thread.run(Thread.java:818)
我的完整代码如下:
我使用A
按钮登录电话login1
,使用B
按钮登录login2
。我的完整代码如下。
public class MainActivity extends ActionBarActivity implements OnClickListener,
QBRTCClientSessionCallbacks, QBRTCClientConnectionCallbacks,
QBRTCClientVideoTracksCallbacks {
Button sign_up, btn_login, btn_call, btn_recieve, btn_login2;
QBChatService chatService;
final QBUser user1 = new QBUser("temp151", "123456789");
final QBUser user2 = new QBUser("temp152", "123456789");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
QBSettings.getInstance().fastConfigInit("xxxx", "xxxxxxxx-",
"xxxxxxx");
sign_up = (Button) findViewById(R.id.sign_up);
btn_login = (Button) findViewById(R.id.btn_login);
btn_call = (Button) findViewById(R.id.btn_call);
btn_recieve = (Button) findViewById(R.id.btn_recieve);
btn_login2 = (Button) findViewById(R.id.btn_login2);
sign_up.setOnClickListener(MainActivity.this);
btn_login.setOnClickListener(MainActivity.this);
btn_call.setOnClickListener(MainActivity.this);
btn_recieve.setOnClickListener(MainActivity.this);
btn_login2.setOnClickListener(MainActivity.this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.sign_up:
QBAuth.createSession(new QBEntityCallback<QBSession>() {
@Override
public void onError(List<String> arg0) {
// TODO Auto-generated method stub
Log.i("error", "" + arg0);
}
@Override
public void onSuccess() {
// TODO Auto-generated method stub
user1.setFullName("temp151");
user1.setPhone("123456789");
QBUsers.signUp(user1, new QBEntityCallbackImpl<QBUser>() {
@Override
public void onSuccess(QBUser user, Bundle args) {
}
@Override
public void onError(List<String> errors) {
}
});
}
@Override
public void onSuccess(final QBSession session, Bundle arg1) {
// TODO Auto-generated method stub
final QBUser user1 = new QBUser("temp151", "123456789");
user1.setFullName("temp151");
user1.setPhone("123456789");
QBUsers.signUp(user1, new QBEntityCallbackImpl<QBUser>() {
@Override
public void onSuccess(QBUser user, Bundle args) {
user1.setId(session.getUserId());
if (!QBChatService.isInitialized()) {
QBChatService.init(MainActivity.this);
chatService = QBChatService.getInstance();
}
}
@Override
public void onError(List<String> errors) {
}
});
}
});
break;
case R.id.btn_login:
create_session();
break;
case R.id.btn_call:
QBRTCTypes.QBConferenceType qbConferenceType = QBConferenceType.QB_CONFERENCE_TYPE_VIDEO;
List<Integer> opponents = new ArrayList<Integer>();
opponents.add(4319012); // QBUser ID
Map<String, String> userInfo = new HashMap<>();
userInfo.put("user", "temp152");
// Init session
QBRTCSession session = QBRTCClient.getInstance()
.createNewSessionWithOpponents(opponents, qbConferenceType);
// Start call
session.startCall(userInfo);
break;
case R.id.btn_recieve:
// VideoChatConfig videoChatConfig =
// QBVideoChatController.getInstance().callFriend(user2,
// CallType.VIDEO_AUDIO, null);
QBVideoChatController.getInstance().callFriend(user1,
CallType.VIDEO_AUDIO, null);
break;
case R.id.btn_login2:
QBAuth.createSession(user2, new QBEntityCallback<QBSession>() {
@Override
public void onError(List<String> arg0) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess() {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(QBSession arg0, Bundle arg1) {
// TODO Auto-generated method stub
user2.setId(arg0.getUserId());
if (!QBChatService.isInitialized()) {
QBChatService.init(MainActivity.this);
chatService = QBChatService.getInstance();
}
chatService.login(user2,
new QBEntityCallbackImpl<QBUser>() {
@Override
public void onSuccess() {
// success
Log.i("Login Successful", "Logged In");
create_SignallingManager();
}
@Override
public void onError(List errors) {
// error
Log.i("errors", "" + errors.toString());
}
});
}
});
break;
default:
break;
}
}
public void create_SignallingManager() {
// TODO Auto-generated method stub
QBChatService
.getInstance()
.getVideoChatWebRTCSignalingManager()
.addSignalingManagerListener(
new QBVideoChatSignalingManagerListener() {
@Override
public void signalingCreated(
QBSignaling qbSignaling,
boolean createdLocally) {
if (!createdLocally) {
QBRTCClient.getInstance().addSignaling(
(QBWebRTCSignaling) qbSignaling);
}
}
});
QBRTCClient.getInstance().addSessionCallbacksListener(this);
QBRTCClient.getInstance().addConnectionCallbacksListener(this);
QBRTCClient.getInstance().addVideoTrackCallbacksListener(this);
QBRTCClient.getInstance().prepareToProcessCalls(this);
SessionCallback loginlistener = new SessionCallback() {
@Override
public void sessionCreated(InputMethodSession arg0) {
// TODO Auto-generated method stub
try {
QBVideoChatController.getInstance()
.initQBVideoChatMessageListener();
} catch (XMPPException e) {
e.printStackTrace();
}
}
};
}
public void create_session() {
QBAuth.createSession(user1, new QBEntityCallback<QBSession>() {
@Override
public void onError(List<String> arg0) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess() {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(QBSession arg0, Bundle arg1) {
// TODO Auto-generated method stub
user1.setId(arg0.getUserId());
if (!QBChatService.isInitialized()) {
QBChatService.init(MainActivity.this);
chatService = QBChatService.getInstance();
}
chatService.login(user1, new QBEntityCallbackImpl<QBUser>() {
@Override
public void onSuccess() {
// success
Log.i("Login Successful", "Logged In");
create_SignallingManager();
}
@Override
public void onError(List errors) {
// error
Log.i("errors", "" + errors.toString());
}
});
}
});
}
@Override
public void onCallRejectByUser(QBRTCSession arg0, Integer arg1,
Map<String, String> arg2) {
// TODO Auto-generated method stub
}
@Override
public void onReceiveHangUpFromUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
@Override
public void onReceiveNewSession(QBRTCSession arg0) {
// TODO Auto-generated method stub
Map<String, String> userInfo = new HashMap<String, String>();
userInfo.put("user", "temp152");
// Accept incoming call
arg0.acceptCall(userInfo);
}
@Override
public void onSessionClosed(QBRTCSession arg0) {
// TODO Auto-generated method stub
}
@Override
public void onSessionStartClose(QBRTCSession arg0) {
// TODO Auto-generated method stub
}
@Override
public void onUserNotAnswer(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
@Override
public void onConnectedToUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
Log.i("connected to second user", "connected");
}
@Override
public void onConnectionClosedForUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
@Override
public void onConnectionFailedWithUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
@Override
public void onDisconnectedFromUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
@Override
public void onDisconnectedTimeoutFromUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
}
@Override
public void onError(QBRTCSession arg0, QBRTCException arg1) {
// TODO Auto-generated method stub
Log.i("Error", "" + arg1.toString());
}
@Override
public void onStartConnectToUser(QBRTCSession arg0, Integer arg1) {
// TODO Auto-generated method stub
Log.i("Connection", "connecting to user");
}
@Override
public void onLocalVideoTrackReceive(QBRTCSession arg0, QBRTCVideoTrack arg1) {
// TODO Auto-generated method stub
QBGLVideoView localVideoVidew = (QBGLVideoView) findViewById(R.id.localVideoView);
VideoRenderer localRenderer = new VideoRenderer(new VideoCallBacks(
localVideoVidew, QBGLVideoView.Endpoint.LOCAL));
arg1.addRenderer(localRenderer);
localVideoVidew.setVideoTrack(arg1, QBGLVideoView.Endpoint.LOCAL);
}
@Override
public void onRemoteVideoTrackReceive(QBRTCSession arg0,
QBRTCVideoTrack remoteVideoTrack, Integer arg2) {
// TODO Auto-generated method stub
QBGLVideoView remoteVideoView = (QBGLVideoView) findViewById(R.id.remoteVideoView);
VideoRenderer remoteRenderer = new VideoRenderer(new VideoCallBacks(
remoteVideoView, QBGLVideoView.Endpoint.REMOTE));
remoteVideoTrack.addRenderer(remoteRenderer);
remoteVideoView.setVideoTrack(remoteVideoTrack,
QBGLVideoView.Endpoint.REMOTE);
}
private VideoChatConfig videoChatConfig;
private OnQBVideoChatListener qbVideoChatListener = new OnQBVideoChatListener() {
@Override
public void onVideoChatStateChange(CallState arg0, VideoChatConfig arg1) {
// TODO Auto-generated method stub
videoChatConfig = arg1;
switch (arg0) {
case ACCEPT:
// show call dialog
Toast.makeText(MainActivity.this, "accept", 1000).show();
break;
case ON_ACCEPT_BY_USER:
// your call was accepted
QBVideoChatController.getInstance().onAcceptFriendCall(
videoChatConfig, null);
break;
case ON_REJECTED_BY_USER:
// your call was rejected
break;
case ON_DID_NOT_ANSWERED:
// opponent did not answer your call
Toast.makeText(MainActivity.this, "not answer", 1000).show();
break;
case ON_CANCELED_CALL:
videoChatConfig = null;
Toast.makeText(MainActivity.this, "cancelled", 1000).show();
break;
// call was canceled
case ON_CALL_START:
// call started
Toast.makeText(MainActivity.this, "call started", 1000).show();
break;
case ON_CALL_END:
Toast.makeText(MainActivity.this, "end", 1000).show();
// call finished
break;
}
}
};
}