From f264ef9f8ba1589c43a3ed276aeb4510d82def25 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 5 Apr 2020 16:12:44 +0200 Subject: [PATCH] create sdp string and set on peer connection --- .../xmpp/jingle/JingleRtpConnection.java | 37 +++++++++++++++++-- .../xmpp/jingle/SessionDescription.java | 8 +++- .../xmpp/jingle/stanzas/JinglePacket.java | 3 +- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index b872541a9..c82f8bcd3 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -43,6 +43,7 @@ public class JingleRtpConnection extends AbstractJingleConnection { private State state = State.NULL; private RtpContentMap initialRtpContentMap; + private PeerConnection peerConnection; public JingleRtpConnection(JingleConnectionManager jingleConnectionManager, Id id, Jid initiator) { @@ -63,6 +64,7 @@ public class JingleRtpConnection extends AbstractJingleConnection { } private void receiveSessionInitiate(final JinglePacket jinglePacket) { + Log.d(Config.LOGTAG,jinglePacket.toString()); if (isInitiator()) { Log.d(Config.LOGTAG, String.format("%s: received session-initiate even though we were initiating", id.account.getJid().asBareJid())); //TODO respond with out-of-order @@ -104,6 +106,31 @@ public class JingleRtpConnection extends AbstractJingleConnection { Log.d(Config.LOGTAG, "transport: " + descriptionTransport.transport); Log.d(Config.LOGTAG, "fingerprint " + iceUdpTransportInfo.getFingerprint()); } + setupWebRTC(); + org.webrtc.SessionDescription sessionDescription = new org.webrtc.SessionDescription(org.webrtc.SessionDescription.Type.OFFER, SessionDescription.of(contentMap).toString()); + Log.d(Config.LOGTAG, "debug print for sessionDescription:" + sessionDescription.description); + this.peerConnection.setRemoteDescription(new SdpObserver() { + @Override + public void onCreateSuccess(org.webrtc.SessionDescription sessionDescription) { + + } + + @Override + public void onSetSuccess() { + Log.d(Config.LOGTAG, "onSetSuccess() for setRemoteDescription"); + } + + @Override + public void onCreateFailure(String s) { + + } + + @Override + public void onSetFailure(String s) { + Log.d(Config.LOGTAG, "onSetFailure() for setRemoteDescription. " + s); + + } + }, sessionDescription); } void deliveryMessage(final Jid from, final Element message) { @@ -148,15 +175,16 @@ public class JingleRtpConnection extends AbstractJingleConnection { } private void sendSessionInitiate() { - setupWebRTC(); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": prepare session-initiate"); + setupWebRTC(); + createOffer(); } private void sendSessionInitiate(RtpContentMap rtpContentMap) { this.initialRtpContentMap = rtpContentMap; final JinglePacket sessionInitiate = rtpContentMap.toJinglePacket(JinglePacket.Action.SESSION_INITIATE, id.sessionId); Log.d(Config.LOGTAG, sessionInitiate.toString()); - Log.d(Config.LOGTAG,"here is what we think the sdp looks like"+SessionDescription.of(rtpContentMap).toString()); + Log.d(Config.LOGTAG, "here is what we think the sdp looks like" + SessionDescription.of(rtpContentMap).toString()); send(sessionInitiate); } @@ -211,7 +239,7 @@ public class JingleRtpConnection extends AbstractJingleConnection { stream.addTrack(audioTrack); - PeerConnection peerConnection = peerConnectionFactory.createPeerConnection(Collections.emptyList(), new PeerConnection.Observer() { + this.peerConnection = peerConnectionFactory.createPeerConnection(Collections.emptyList(), new PeerConnection.Observer() { @Override public void onSignalingChange(PeerConnection.SignalingState signalingState) { @@ -272,7 +300,10 @@ public class JingleRtpConnection extends AbstractJingleConnection { }); peerConnection.addStream(stream); + } + private void createOffer() { + Log.d(Config.LOGTAG, "createOffer()"); peerConnection.createOffer(new SdpObserver() { @Override diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/SessionDescription.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/SessionDescription.java index e9a6bf854..81f13307f 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/SessionDescription.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/SessionDescription.java @@ -21,7 +21,7 @@ public class SessionDescription { private final static String LINE_DIVIDER = "\r\n"; private final static String HARDCODED_MEDIA_PROTOCOL = "UDP/TLS/RTP/SAVPF"; //probably only true for DTLS-SRTP aka when we have a fingerprint - private final static int HARDCODED_MEDIA_PORT = 1; + private final static int HARDCODED_MEDIA_PORT = 9; private final static String HARDCODED_ICE_OPTIONS = "trickle renomination"; private final static String HARDCODED_CONNECTION = "IN IP4 0.0.0.0"; @@ -130,6 +130,8 @@ public class SessionDescription { final Group group = contentMap.group; if (group != null) { attributeMap.put("group", group.getSemantics() + " " + Joiner.on(' ').join(group.getIdentificationTags())); + } else { + Log.d(Config.LOGTAG,"group was null"); } //random additional attributes @@ -196,7 +198,7 @@ public class SessionDescription { } sessionDescriptionBuilder.setVersion(0); - sessionDescriptionBuilder.setName(" "); + sessionDescriptionBuilder.setName("-"); sessionDescriptionBuilder.setMedia(mediaListBuilder.build()); sessionDescriptionBuilder.setAttributes(attributeMap); @@ -224,6 +226,8 @@ public class SessionDescription { public String toString() { final StringBuilder s = new StringBuilder() .append("v=").append(version).append(LINE_DIVIDER) + .append("o=- 8770656990916039506 2 IN IP4 127.0.0.1").append(LINE_DIVIDER) //what ever that means + .append("t=0 0").append(LINE_DIVIDER) .append("s=").append(name).append(LINE_DIVIDER); appendAttributes(s, attributes); for (Media media : this.media) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java index 1c15af27f..3b4ef47d1 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java @@ -43,7 +43,8 @@ public class JinglePacket extends IqPacket { } public Group getGroup() { - final Element group = this.findChild("group", Namespace.JINGLE_APPS_GROUPING); + final Element jingle = findChild("jingle", Namespace.JINGLE); + final Element group = jingle.findChild("group", Namespace.JINGLE_APPS_GROUPING); return group == null ? null : Group.upgrade(group); }