From 1439f77c3713df8309eb55d3b420c9a71e7b546d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wala?= Date: Wed, 27 Sep 2023 08:21:19 +0200 Subject: [PATCH] Add used SDP examples --- examples/example.exs | 2 +- examples/example.js | 13 ++++++--- examples/sdp_answer.txt | 33 +++++++++++++++++++++++ examples/sdp_offer.txt | 36 +++++++++++++++++++++++++ lib/ex_webrtc/peer_connection.ex | 45 +++++++++++++++++++++++++++----- 5 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 examples/sdp_answer.txt create mode 100644 examples/sdp_offer.txt diff --git a/examples/example.exs b/examples/example.exs index 96f035ec..2b481582 100644 --- a/examples/example.exs +++ b/examples/example.exs @@ -1,7 +1,7 @@ Mix.install([{:gun, "~> 2.0.1"}, {:ex_webrtc, path: "./", force: true}, {:jason, "~> 1.4.0"}]) require Logger -Logger.configure(level: :debug) +Logger.configure(level: :info) defmodule Peer do use GenServer diff --git a/examples/example.js b/examples/example.js index 97d49f64..0b48c5b7 100644 --- a/examples/example.js +++ b/examples/example.js @@ -13,7 +13,11 @@ const start_connection = async (ws) => { const pc = new RTCPeerConnection(pcConfig); pc.onconnectionstatechange = _ => console.log("Connection state changed:", pc.connectionState); - + pc.onicecandidateerror = event => console.log("ICE candidate error:", event); + pc.oniceconnectionstatechange = _ => console.log("ICE connection state changed:", pc.iceConnectionState); + pc.onicegatheringstatechange = _ => console.log("ICE gathering state changed:", pc.iceGatheringState); + pc.onsignalingstatechange = _ => console.log("Signaling state changed:", pc.signalingState); + pc.ontrack = event => console.log("New track:", event); pc.onicecandidate = event => { console.log("New local ICE candidate:", event.candidate); @@ -22,16 +26,17 @@ const start_connection = async (ws) => { } }; - pc.ontrack = null; // TODO - ws.onmessage = event => { const msg = JSON.parse(event.data); - console.log("Received message:", msg); if (msg.type === "answer") { + console.log("Recieved SDP answer:", msg); pc.setRemoteDescription(msg); } else if (msg.type === "ice") { + console.log("Recieved remote ICE candidate:", msg.data); pc.addIceCandidate(msg.data); + } else { + console.log("Received unexpected message:", msg); } }; diff --git a/examples/sdp_answer.txt b/examples/sdp_answer.txt new file mode 100644 index 00000000..7fb84476 --- /dev/null +++ b/examples/sdp_answer.txt @@ -0,0 +1,33 @@ +v=0 +o=- 7596991810024734139 2 IN IP4 127.0.0.1 +s=- +t=0 0 +a=group:BUNDLE 0 +a=extmap-allow-mixed +a=msid-semantic: WMS +m=audio 9 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:vx/1 +a=ice-pwd:ldFUrCsXvndFY2L1u0UQ7ikf +a=ice-options:trickle +a=fingerprint:sha-256 76:61:77:1E:7C:2E:BB:CD:19:B5:27:4E:A7:40:84:06:6B:17:97:AB:C4:61:90:16:EE:96:9F:9E:BD:42:96:3D +a=setup:passive +a=mid:0 +a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level +a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid +a=recvonly +a=rtcp-mux +a=rtpmap:111 opus/48000/2 +a=rtcp-fb:111 transport-cc +a=fmtp:111 minptime=10;useinbandfec=1 +a=rtpmap:63 red/48000/2 +a=fmtp:63 111/111 +a=rtpmap:9 G722/8000 +a=rtpmap:0 PCMU/8000 +a=rtpmap:8 PCMA/8000 +a=rtpmap:13 CN/8000 +a=rtpmap:110 telephone-event/48000 +a=rtpmap:126 telephone-event/8000 diff --git a/examples/sdp_offer.txt b/examples/sdp_offer.txt new file mode 100644 index 00000000..57adad68 --- /dev/null +++ b/examples/sdp_offer.txt @@ -0,0 +1,36 @@ +v=0 +o=- 8941027839948408955 2 IN IP4 127.0.0.1 +s=- +t=0 0 +a=group:BUNDLE 0 +a=extmap-allow-mixed +a=msid-semantic: WMS 4d0a4923-289d-4f4c-931a-c72db00c055f +m=audio 9 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:q1Cp +a=ice-pwd:AazQ7Pof8R7suS3j9aod8DjV +a=ice-options:trickle +a=fingerprint:sha-256 42:85:3D:4C:72:D6:C2:5B:AE:EE:7F:6A:53:7C:04:63:6E:B9:55:18:46:E5:82:31:57:EE:21:F0:E7:60:82:CD +a=setup:actpass +a=mid:0 +a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level +a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid +a=sendrecv +a=msid:4d0a4923-289d-4f4c-931a-c72db00c055f 6a7555a6-7a70-4196-a58f-89567c49b12d +a=rtcp-mux +a=rtpmap:111 opus/48000/2 +a=rtcp-fb:111 transport-cc +a=fmtp:111 minptime=10;useinbandfec=1 +a=rtpmap:63 red/48000/2 +a=fmtp:63 111/111 +a=rtpmap:9 G722/8000 +a=rtpmap:0 PCMU/8000 +a=rtpmap:8 PCMA/8000 +a=rtpmap:13 CN/8000 +a=rtpmap:110 telephone-event/48000 +a=rtpmap:126 telephone-event/8000 +a=ssrc:2776039216 cname:1qch+ontR0BspBY6 +a=ssrc:2776039216 msid:4d0a4923-289d-4f4c-931a-c72db00c055f 6a7555a6-7a70-4196-a58f-89567c49b12d diff --git a/lib/ex_webrtc/peer_connection.ex b/lib/ex_webrtc/peer_connection.ex index a27f6f7b..8b6c04c3 100644 --- a/lib/ex_webrtc/peer_connection.ex +++ b/lib/ex_webrtc/peer_connection.ex @@ -24,6 +24,42 @@ defmodule ExWebRTC.PeerConnection do signaling_state: :stable ] + @dummy_sdp " + v=0\r\n + o=- 7596991810024734139 2 IN IP4 127.0.0.1\r\n + s=-\r\n + t=0 0\r\n + a=group:BUNDLE 0\r\n + a=extmap-allow-mixed\r\n + a=msid-semantic: WMS\r\n + m=audio 9 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126\r\n + c=IN IP4 0.0.0.0\r\n + a=rtcp:9 IN IP4 0.0.0.0\r\n + a=ice-ufrag:vx/1\r\n + a=ice-pwd:ldFUrCsXvndFY2L1u0UQ7ikf\r\n + a=ice-options:trickle\r\n + a=fingerprint:sha-256 76:61:77:1E:7C:2E:BB:CD:19:B5:27:4E:A7:40:84:06:6B:17:97:AB:C4:61:90:16:EE:96:9F:9E:BD:42:96:3D\r\n + a=setup:passive\r\n + a=mid:0\r\n + a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n + a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n + a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\n + a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\n + a=recvonly\r\n + a=rtcp-mux\r\n + a=rtpmap:111 opus/48000/2\r\n + a=rtcp-fb:111 transport-cc\r\n + a=fmtp:111 minptime=10;useinbandfec=1\r\n + a=rtpmap:63 red/48000/2\r\n + a=fmtp:63 111/111\r\n + a=rtpmap:9 G722/8000\r\n + a=rtpmap:0 PCMU/8000\r\n + a=rtpmap:8 PCMA/8000\r\n + a=rtpmap:13 CN/8000\r\n + a=rtpmap:110 telephone-event/48000\r\n + a=rtpmap:126 telephone-event/8000\r\n + " + #### API #### def start_link(configuration \\ []) do @@ -71,6 +107,7 @@ defmodule ExWebRTC.PeerConnection do config = struct(Configuration, config) :ok = Configuration.check_support(config) + # ATM, ExICE does not support relay via TURN stun_servers = config.ice_servers |> Enum.flat_map(&if(is_list(&1.urls), do: &1.urls, else: [&1.urls])) @@ -90,14 +127,9 @@ defmodule ExWebRTC.PeerConnection do @impl true def handle_call({:create_answer, _options}, _from, state) when state.signaling_state in [:have_remote_offer, :have_local_pranswer] do - # hardcoded answer based generated by chrome with no added tracks - # in response to offer also generated by chrome with 1 audio track {:ok, ufrag, pwd} = ICEAgent.get_local_credentials(state.ice_agent) - test_answer = - "v=0\r\no=- 7596991810024734139 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:vx/1\r\na=ice-pwd:ldFUrCsXvndFY2L1u0UQ7ikf\r\na=ice-options:trickle\r\na=fingerprint:sha-256 76:61:77:1E:7C:2E:BB:CD:19:B5:27:4E:A7:40:84:06:6B:17:97:AB:C4:61:90:16:EE:96:9F:9E:BD:42:96:3D\r\na=setup:active\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=recvonly\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:63 red/48000/2\r\na=fmtp:63 111/111\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:126 telephone-event/8000\r\n" - - sdp = ExSDP.parse!(test_answer) + sdp = ExSDP.parse!(@dummy_sdp) media = hd(sdp.media) attrs = @@ -148,7 +180,6 @@ defmodule ExWebRTC.PeerConnection do end end - @impl true def handle_call({:add_ice_candidate, candidate}, _from, state) do with "candidate:" <> attr <- candidate.candidate do ICEAgent.add_remote_candidate(state.ice_agent, attr)