android: Only publish/receive video if setting SDP doesn't fail

A bad SDP will be rejected by the WebRTC implementation, so no further
publish/subscribe operations should be done on failure.

This expands on the idea of
https://github.com/OpenVidu/openvidu-tutorials/pull/174
and also simplifies implementations of CustomSdpObserver: there is no
need to inherit its methods just for logging, as CustomSdpObserver
already logs everything on its default implementation.
This commit is contained in:
Juan Navarro 2022-05-18 13:12:57 +02:00
parent 81b7c492d1
commit 4bcd06c235
2 changed files with 26 additions and 52 deletions

View File

@ -185,58 +185,34 @@ public class Session {
public void createOfferForPublishing(MediaConstraints constraints) {
localParticipant.getPeerConnection().createOffer(new CustomSdpObserver("createOffer") {
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
super.onCreateSuccess(sessionDescription);
Log.i("createOffer SUCCESS", sessionDescription.toString());
localParticipant.getPeerConnection().setLocalDescription(
new CustomSdpObserver("createOffer_setLocalDescription") {
@Override
public void onSetSuccess() {
super.onSetSuccess();
websocket.publishVideo(sessionDescription);
}
@Override
public void onSetFailure(String s) {
super.onCreateFailure(s);
Log.e("setLocalDescription ERROR", s);
}
},
sessionDescription);
public void onCreateSuccess(SessionDescription sdp) {
super.onCreateSuccess(sdp);
Log.i("createOffer SUCCESS", sdp.toString());
localParticipant.getPeerConnection().setLocalDescription(new CustomSdpObserver("createOffer_setLocalDescription") {
@Override
public void onSetSuccess() {
super.onSetSuccess();
websocket.publishVideo(sdp);
}
}, sdp);
}
@Override
public void onCreateFailure(String s) {
Log.e("createOffer ERROR", s);
}
}, constraints);
}
public void createAnswerForSubscribing(RemoteParticipant remoteParticipant, String streamId, MediaConstraints constraints) {
remoteParticipant.getPeerConnection().createAnswer(new CustomSdpObserver("createAnswerSubscribing") {
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
super.onCreateSuccess(sessionDescription);
Log.i("createAnswer SUCCESS", sessionDescription.toString());
public void onCreateSuccess(SessionDescription sdp) {
super.onCreateSuccess(sdp);
Log.i("createAnswer SUCCESS", sdp.toString());
remoteParticipant.getPeerConnection().setLocalDescription(new CustomSdpObserver("createAnswerSubscribing_setLocalDescription") {
@Override
public void onSetSuccess() {
websocket.receiveVideoFrom(sessionDescription, remoteParticipant, streamId);
super.onSetSuccess();
websocket.receiveVideoFrom(sdp, remoteParticipant, streamId);
}
@Override
public void onSetFailure(String s) {
Log.e("setRemoteDescription ER", s);
}
}, sessionDescription);
}, sdp);
}
@Override
public void onCreateFailure(String s) {
Log.e("createAnswer ERROR", s);
}
}, constraints);
}

View File

@ -174,12 +174,9 @@ public class CustomWebSocket extends AsyncTask<SessionActivity, Void, Void> impl
remoteParticipant.getPeerConnection().setRemoteDescription(new CustomSdpObserver("prepareReceiveVideoFrom_setRemoteDescription") {
@Override
public void onSetSuccess() {
super.onSetSuccess();
subscriptionInitiatedFromServer(remoteParticipant, streamId);
}
@Override
public void onSetFailure(String s) {
Log.i("setRemoteDescription ER", s);
}
}, remoteSdpOffer);
} else if (this.IDS_RECEIVEVIDEO.containsKey(rpcId)) {
// Response to receiveVideoFrom
@ -402,14 +399,15 @@ public class CustomWebSocket extends AsyncTask<SessionActivity, Void, Void> impl
remoteParticipant.getPeerConnection().createOffer(new CustomSdpObserver("remote offer sdp") {
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
super.onCreateSuccess(sessionDescription);
remoteParticipant.getPeerConnection().setLocalDescription(new CustomSdpObserver("remoteSetLocalDesc"), sessionDescription);
receiveVideoFrom(sessionDescription, remoteParticipant, streamId);
}
@Override
public void onCreateFailure(String s) {
Log.e("createOffer error", s);
public void onCreateSuccess(SessionDescription sdp) {
super.onCreateSuccess(sdp);
remoteParticipant.getPeerConnection().setLocalDescription(new CustomSdpObserver("remoteSetLocalDesc") {
@Override
public void onSetSuccess() {
super.onSetSuccess();
receiveVideoFrom(sdp, remoteParticipant, streamId);
}
}, sdp);
}
}, sdpConstraints);
}