mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-27 17:08:34 +03:00
Smaller progress for websocket communication
This commit is contained in:
parent
568db40816
commit
9f1fef7ff1
3 changed files with 75 additions and 62 deletions
|
@ -1193,11 +1193,13 @@ public class CallController extends BaseController {
|
|||
if (webSocketCommunicationEvent.getType().equals("hello")) {
|
||||
callSession = webSocketClient.getSessionId();
|
||||
webSocketClient.joinRoomWithRoomToken(roomToken);
|
||||
alwaysGetPeerConnectionWrapperForSessionId(callSession);
|
||||
} else if (webSocketCommunicationEvent.equals("participantsUpdate")) {
|
||||
alwaysGetPeerConnectionWrapperForSessionId(callSession, true);
|
||||
} else if ("participantsUpdate".equals(webSocketCommunicationEvent.getType())) {
|
||||
if (webSocketCommunicationEvent.getHashMap().get("roomId").equals(roomToken)) {
|
||||
processUsersInRoom((List<HashMap<String, Object>>) webSocketClient.getJobWithId(Integer.valueOf(webSocketCommunicationEvent.getHashMap().get("jobId"))));
|
||||
}
|
||||
} else if ("signalingMessage".equals(webSocketCommunicationEvent.getType())) {
|
||||
processMessage((NCSignalingMessage) webSocketClient.getJobWithId(Integer.valueOf(webSocketCommunicationEvent.getHashMap().get("jobId"))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1235,51 +1237,55 @@ public class CallController extends BaseController {
|
|||
} else if ("message".equals(messageType)) {
|
||||
NCSignalingMessage ncSignalingMessage = LoganSquare.parse(signaling.getMessageWrapper().toString(),
|
||||
NCSignalingMessage.class);
|
||||
if (ncSignalingMessage.getRoomType().equals("video")) {
|
||||
MagicPeerConnectionWrapper magicPeerConnectionWrapper = alwaysGetPeerConnectionWrapperForSessionId
|
||||
(ncSignalingMessage.getFrom());
|
||||
processMessage(ncSignalingMessage);
|
||||
} else {
|
||||
Log.d(TAG, "Something went very very wrong");
|
||||
}
|
||||
}
|
||||
|
||||
String type = null;
|
||||
if (ncSignalingMessage.getPayload() != null && ncSignalingMessage.getPayload().getType() !=
|
||||
null) {
|
||||
type = ncSignalingMessage.getPayload().getType();
|
||||
} else if (ncSignalingMessage.getType() != null) {
|
||||
type = ncSignalingMessage.getType();
|
||||
private void processMessage(NCSignalingMessage ncSignalingMessage) {
|
||||
if (ncSignalingMessage.getRoomType().equals("video")) {
|
||||
MagicPeerConnectionWrapper magicPeerConnectionWrapper = alwaysGetPeerConnectionWrapperForSessionId
|
||||
(ncSignalingMessage.getFrom(), false);
|
||||
|
||||
String type = null;
|
||||
if (ncSignalingMessage.getPayload() != null && ncSignalingMessage.getPayload().getType() !=
|
||||
null) {
|
||||
type = ncSignalingMessage.getPayload().getType();
|
||||
} else if (ncSignalingMessage.getType() != null) {
|
||||
type = ncSignalingMessage.getType();
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
switch (type) {
|
||||
case "offer":
|
||||
case "answer":
|
||||
magicPeerConnectionWrapper.setNick(ncSignalingMessage.getPayload().getNick());
|
||||
String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec
|
||||
(ncSignalingMessage.getPayload().getSdp(),
|
||||
"VP8", false);
|
||||
|
||||
SessionDescription sessionDescriptionWithPreferredCodec = new SessionDescription(
|
||||
SessionDescription.Type.fromCanonicalForm(type),
|
||||
sessionDescriptionStringWithPreferredCodec);
|
||||
|
||||
if (magicPeerConnectionWrapper.getPeerConnection() != null) {
|
||||
magicPeerConnectionWrapper.getPeerConnection().setRemoteDescription(magicPeerConnectionWrapper
|
||||
.getMagicSdpObserver(), sessionDescriptionWithPreferredCodec);
|
||||
}
|
||||
break;
|
||||
case "candidate":
|
||||
NCIceCandidate ncIceCandidate = ncSignalingMessage.getPayload().getIceCandidate();
|
||||
IceCandidate iceCandidate = new IceCandidate(ncIceCandidate.getSdpMid(),
|
||||
ncIceCandidate.getSdpMLineIndex(), ncIceCandidate.getCandidate());
|
||||
magicPeerConnectionWrapper.addCandidate(iceCandidate);
|
||||
break;
|
||||
case "endOfCandidates":
|
||||
magicPeerConnectionWrapper.drainIceCandidates();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
switch (type) {
|
||||
case "offer":
|
||||
case "answer":
|
||||
magicPeerConnectionWrapper.setNick(ncSignalingMessage.getPayload().getNick());
|
||||
String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec
|
||||
(ncSignalingMessage.getPayload().getSdp(),
|
||||
"VP8", false);
|
||||
|
||||
SessionDescription sessionDescriptionWithPreferredCodec = new SessionDescription(
|
||||
SessionDescription.Type.fromCanonicalForm(type),
|
||||
sessionDescriptionStringWithPreferredCodec);
|
||||
|
||||
if (magicPeerConnectionWrapper.getPeerConnection() != null) {
|
||||
magicPeerConnectionWrapper.getPeerConnection().setRemoteDescription(magicPeerConnectionWrapper
|
||||
.getMagicSdpObserver(), sessionDescriptionWithPreferredCodec);
|
||||
}
|
||||
break;
|
||||
case "candidate":
|
||||
NCIceCandidate ncIceCandidate = ncSignalingMessage.getPayload().getIceCandidate();
|
||||
IceCandidate iceCandidate = new IceCandidate(ncIceCandidate.getSdpMid(),
|
||||
ncIceCandidate.getSdpMLineIndex(), ncIceCandidate.getCandidate());
|
||||
magicPeerConnectionWrapper.addCandidate(iceCandidate);
|
||||
break;
|
||||
case "endOfCandidates":
|
||||
magicPeerConnectionWrapper.drainIceCandidates();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Something went very very wrong");
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Something went very very wrong");
|
||||
|
@ -1455,7 +1461,7 @@ public class CallController extends BaseController {
|
|||
|
||||
for (String sessionId : newSessions) {
|
||||
if (!hasMCU) {
|
||||
alwaysGetPeerConnectionWrapperForSessionId(sessionId);
|
||||
alwaysGetPeerConnectionWrapperForSessionId(sessionId, false);
|
||||
} else {
|
||||
webSocketClient.requestOfferForSessionIdWithType(sessionId, "video");
|
||||
}
|
||||
|
@ -1503,28 +1509,22 @@ public class CallController extends BaseController {
|
|||
magicPeerConnectionWrapperList.remove(magicPeerConnectionWrapper);
|
||||
}
|
||||
|
||||
private MagicPeerConnectionWrapper alwaysGetPeerConnectionWrapperForSessionId(String sessionId) {
|
||||
private MagicPeerConnectionWrapper alwaysGetPeerConnectionWrapperForSessionId(String sessionId, boolean publisher) {
|
||||
MagicPeerConnectionWrapper magicPeerConnectionWrapper;
|
||||
if ((magicPeerConnectionWrapper = getPeerConnectionWrapperForSessionId(sessionId)) != null) {
|
||||
return magicPeerConnectionWrapper;
|
||||
} else {
|
||||
hasMCU = webSocketClient != null && webSocketClient.hasMCU();
|
||||
|
||||
MediaConstraints mediaConstraintsToUse;
|
||||
|
||||
if (hasMCU) {
|
||||
mediaConstraintsToUse = sdpConstraintsForMCU;
|
||||
} else {
|
||||
mediaConstraintsToUse = sdpConstraints;
|
||||
|
||||
}
|
||||
|
||||
if (sessionId.equals(callSession)) {
|
||||
if (hasMCU && publisher) {
|
||||
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory,
|
||||
iceServers, mediaConstraintsToUse, sessionId, callSession, localMediaStream, hasMCU);
|
||||
iceServers, sdpConstraintsForMCU, sessionId, callSession, localMediaStream, true);
|
||||
} else if (hasMCU) {
|
||||
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory,
|
||||
iceServers, sdpConstraints, sessionId, callSession, null, false);
|
||||
} else {
|
||||
magicPeerConnectionWrapper = new MagicPeerConnectionWrapper(peerConnectionFactory,
|
||||
iceServers, mediaConstraintsToUse, sessionId, callSession, null, hasMCU);
|
||||
iceServers, sdpConstraints, sessionId, callSession, localMediaStream, false);
|
||||
}
|
||||
|
||||
magicPeerConnectionWrapperList.add(magicPeerConnectionWrapper);
|
||||
|
@ -1626,6 +1626,7 @@ public class CallController extends BaseController {
|
|||
ncMessageWrapper.setSessionId(callSession);
|
||||
NCSignalingMessage ncSignalingMessage = new NCSignalingMessage();
|
||||
ncSignalingMessage.setTo(sessionDescriptionSend.getPeerId());
|
||||
ncSignalingMessage.setFrom(callSession);
|
||||
ncSignalingMessage.setRoomType("video");
|
||||
ncSignalingMessage.setType(sessionDescriptionSend.getType());
|
||||
NCMessagePayload ncMessagePayload = new NCMessagePayload();
|
||||
|
|
|
@ -75,7 +75,7 @@ public class MagicPeerConnectionWrapper {
|
|||
List<PeerConnection.IceServer> iceServerList,
|
||||
MediaConstraints mediaConstraints,
|
||||
String sessionId, String localSession, @Nullable MediaStream mediaStream,
|
||||
boolean hasMCU) {
|
||||
boolean isMCUPublisher) {
|
||||
|
||||
this.localMediaStream = mediaStream;
|
||||
|
||||
|
@ -89,11 +89,11 @@ public class MagicPeerConnectionWrapper {
|
|||
new MagicPeerConnectionObserver());
|
||||
|
||||
if (peerConnection != null) {
|
||||
if (localSession != null) {
|
||||
if (localSession != null && localMediaStream != null) {
|
||||
peerConnection.addStream(localMediaStream);
|
||||
}
|
||||
|
||||
if (hasInitiated || hasMCU) {
|
||||
if (isMCUPublisher || hasInitiated) {
|
||||
DataChannel.Init init = new DataChannel.Init();
|
||||
init.negotiated = false;
|
||||
magicDataChannel = peerConnection.createDataChannel("status", init);
|
||||
|
|
|
@ -169,6 +169,18 @@ public class MagicWebSocketInstance extends WebSocketListener {
|
|||
break;
|
||||
case "message":
|
||||
CallOverallWebSocketMessage callOverallWebSocketMessage = LoganSquare.parse(text, CallOverallWebSocketMessage.class);
|
||||
int newId;
|
||||
do {
|
||||
HashMap<String, String> messageHashMap = new HashMap<>();
|
||||
Random rand = new Random();
|
||||
newId = rand.nextInt(1000);
|
||||
if (!concurrentHashMapQueue.contains(newId)) {
|
||||
concurrentHashMapQueue.put(newId, callOverallWebSocketMessage.getCallWebSocketMessage().getNcSignalingMessage());
|
||||
messageHashMap.put("jobId", Integer.toString(newId));
|
||||
eventBus.post(new WebSocketCommunicationEvent("signalingMessage", messageHashMap));
|
||||
}
|
||||
} while (!concurrentHashMapQueue.contains(newId));
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue