Improve data channel handling

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-11-29 11:23:56 +01:00
parent a621401520
commit b98bb93e44
3 changed files with 19 additions and 16 deletions

View file

@ -298,7 +298,6 @@ public class CallActivity extends AppCompatActivity {
sdpConstraints.optional.add(new MediaConstraints.KeyValuePair("internalSctpDataChannels", "true"));
sdpConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
ncApi.joinRoom(credentials, ApiHelper.getUrlForJoinRoom(userEntity.getBaseUrl(), roomToken))
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
@ -547,7 +546,7 @@ public class CallActivity extends AppCompatActivity {
return magicPeerConnectionWrapper;
} else {
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory,
iceServers, sdpConstraints, sessionId);
iceServers, sdpConstraints, sessionId, callSession);
magicPeerConnectionWrapper.getPeerConnection().addStream(localMediaStream);
magicPeerConnectionWrapperList.add(magicPeerConnectionWrapper);
return magicPeerConnectionWrapper;

View file

@ -36,7 +36,6 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -237,7 +236,6 @@ public class CallsListController extends BaseController implements SearchView.On
callItems = new ArrayList<>();
Log.d("MARIO", userEntity.getUsername());
roomsQueryDisposable = ncApi.getRooms(ApiHelper.getCredentials(userEntity.getUsername(),
userEntity.getToken()), ApiHelper.getUrlForGetRooms(userEntity.getBaseUrl()))
.subscribeOn(Schedulers.newThread())

View file

@ -48,9 +48,10 @@ public class MagicPeerConnectionWrapper {
private static String TAG = "MagicPeerConnectionWrapper";
private static PeerConnection peerConnection;
List<IceCandidate> iceCandidates = new ArrayList<>();
List<PeerConnection.IceServer> iceServers;
List<NCIceCandidate> localCandidates = new ArrayList<>();
private List<PeerConnection.IceServer> iceServers;
private List<NCIceCandidate> localCandidates = new ArrayList<>();
private String sessionId;
private String localSession;
private String nick;
private MediaConstraints mediaConstraints;
private DataChannel magicDataChannel;
@ -62,19 +63,22 @@ public class MagicPeerConnectionWrapper {
public MagicPeerConnectionWrapper(PeerConnectionFactory peerConnectionFactory,
List<PeerConnection.IceServer> iceServerList,
MediaConstraints mediaConstraints,
String sessionId) {
String sessionId, String localSession) {
this.iceServers = iceServerList;
peerConnection = peerConnectionFactory.createPeerConnection(iceServerList, mediaConstraints,
new MagicPeerConnectionObserver());
if (sessionId.compareTo(localSession) < 0) {
DataChannel.Init init = new DataChannel.Init();
init.negotiated = false;
magicDataChannel = peerConnection.createDataChannel("status", init);
magicDataChannel.registerObserver(new MagicDataChannelObserver());
}
this.sessionId = sessionId;
this.localSession = localSession;
this.mediaConstraints = mediaConstraints;
magicSdpObserver = new MagicSdpObserver();
@ -119,7 +123,7 @@ public class MagicPeerConnectionWrapper {
buffer = ByteBuffer.wrap(LoganSquare.serialize(dataChannelMessage).getBytes());
magicDataChannel.send(new DataChannel.Buffer(buffer, false));
} catch (IOException e) {
e.printStackTrace();
Log.d(TAG, "Failed to send channel data");
}
}
@ -162,7 +166,6 @@ public class MagicPeerConnectionWrapper {
sendChannelData(new DataChannelMessage("videoOn"));
sendChannelData(new DataChannelMessage("audioOn"));
}
}
@Override
@ -187,12 +190,11 @@ public class MagicPeerConnectionWrapper {
@Override
public void onSignalingChange(PeerConnection.SignalingState signalingState) {
Log.d("MARIO", signalingState.name());
}
@Override
public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
}
@Override
@ -241,7 +243,11 @@ public class MagicPeerConnectionWrapper {
@Override
public void onDataChannel(DataChannel dataChannel) {
Log.d("MARIO", "DATA");
if (dataChannel.label().equals("status")) {
magicDataChannel = dataChannel;
magicDataChannel.registerObserver(new MagicDataChannelObserver());
}
}
@Override