Skip to content

Commit dc3af4a

Browse files
authored
Update ex-webrtc (#32)
* Manually terminate elements after pc fail * Bump version * Ensure processes are terminated
1 parent cbb3576 commit dc3af4a

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The package can be installed by adding `membrane_webrtc_plugin` to your list of
1515
```elixir
1616
def deps do
1717
[
18-
{:membrane_webrtc_plugin, "~> 0.25.3"}
18+
{:membrane_webrtc_plugin, "~> 0.26.0"}
1919
]
2020
end
2121
```
@@ -34,13 +34,13 @@ To run one of these demos, type: `elixir <script_name>` and visit `http://localh
3434

3535
## Exchanging Signaling Messages
3636

37-
To establish a WebRTC connection you have to exchange WebRTC signaling messages between peers.
38-
In `membrane_webrtc_plugin` it can be done by the user, with `Membrane.WebRTC.Signaling` or by passing WebSocket address to
37+
To establish a WebRTC connection you have to exchange WebRTC signaling messages between peers.
38+
In `membrane_webrtc_plugin` it can be done by the user, with `Membrane.WebRTC.Signaling` or by passing WebSocket address to
3939
`Membrane.WebRTC.Source` or `Membrane.WebRTC.Sink`, but there are two additional ways of doing it, dedicated to be used within
4040
`Phoenix` projects:
4141
- The first one is to use `Membrane.WebRTC.PhoenixSignaling` along with `Membrane.WebRTC.PhoenixSignaling.Socket`
4242
- The second one is to use `Phoenix.LiveView` `Membrane.WebRTC.Live.Player` or `Membrane.WebRTC.Live.Capture`. These modules expect
43-
`t:Membrane.WebRTC.Signaling.t/0` as an argument and take advantage of WebSocket used by `Phoenix.LiveView` to exchange WebRTC
43+
`t:Membrane.WebRTC.Signaling.t/0` as an argument and take advantage of WebSocket used by `Phoenix.LiveView` to exchange WebRTC
4444
signaling messages, so there is no need to add any code to handle signaling messages.
4545

4646
### How to use Membrane.WebRTC.PhoenixSignaling in your own Phoenix project?
@@ -109,17 +109,17 @@ Visit `examples/phoenix_signaling/assets/js/signaling.js` to see how WebRTC sign
109109
110110
## Integrating Phoenix.LiveView with Membrane WebRTC Plugin
111111
112-
`membrane_webrtc_plugin` comes with two `Phoenix.LiveView`s:
113-
- `Membrane.WebRTC.Live.Capture` - exchanges WebRTC signaling messages between `Membrane.WebRTC.Source` and the browser. It
114-
expects the same `Membrane.WebRTC.Signaling` that has been passed to the related `Membrane.WebRTC.Source`. As a result,
115-
`Membrane.Webrtc.Source` will return the media stream captured from the browser, where `Membrane.WebRTC.Live.Capture` has been
112+
`membrane_webrtc_plugin` comes with two `Phoenix.LiveView`s:
113+
- `Membrane.WebRTC.Live.Capture` - exchanges WebRTC signaling messages between `Membrane.WebRTC.Source` and the browser. It
114+
expects the same `Membrane.WebRTC.Signaling` that has been passed to the related `Membrane.WebRTC.Source`. As a result,
115+
`Membrane.Webrtc.Source` will return the media stream captured from the browser, where `Membrane.WebRTC.Live.Capture` has been
116116
rendered.
117-
- `Membrane.WebRTC.Live.Player` - exchanges WebRTC signaling messages between `Membrane.WebRTC.Sink` and the browser. It
118-
expects the same `Membrane.WebRTC.Signaling` that has been passed to the related `Membrane.WebRTC.Sink`. As a result,
119-
`Membrane.WebRTC.Live.Player` will play media streams passed to the related `Membrane.WebRTC.Sink`. Currently supports up
117+
- `Membrane.WebRTC.Live.Player` - exchanges WebRTC signaling messages between `Membrane.WebRTC.Sink` and the browser. It
118+
expects the same `Membrane.WebRTC.Signaling` that has been passed to the related `Membrane.WebRTC.Sink`. As a result,
119+
`Membrane.WebRTC.Live.Player` will play media streams passed to the related `Membrane.WebRTC.Sink`. Currently supports up
120120
to one video stream and up to one audio stream.
121121
122-
### Usage
122+
### Usage
123123
124124
To use `Phoenix.LiveView`s from this repository, you have to use related JS hooks. To do so, add the following code snippet to `assets/js/app.js`
125125

lib/membrane_webrtc/ex_webrtc/sink.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ defmodule Membrane.WebRTC.ExWebRTCSink do
215215
{[setup: :complete, notify_parent: :connected], %{state | status: :connected}}
216216
end
217217

218+
@impl true
219+
def handle_info({:ex_webrtc, _from, {:connection_state_change, :failed}}, _ctx, state) do
220+
Membrane.Logger.debug("webrtc connection failed")
221+
{[terminate: {:shutdown, :connection_failed}], %{state | status: :closed}}
222+
end
223+
218224
@impl true
219225
def handle_info({:ex_webrtc, _from, {message, track_id}}, _ctx, _state)
220226
when message in [:track_muted, :track_removed] do

lib/membrane_webrtc/ex_webrtc/source.ex

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ defmodule Membrane.WebRTC.ExWebRTCSource do
3838
output_tracks: %{(pad_id :: term()) => output_track()},
3939
awaiting_outputs: [{:video | :audio, Membrane.Pad.ref()}],
4040
awaiting_candidates: [ExWebRTC.ICECandidate.t()],
41-
signaling: Signaling.t() | {:websocket, SimpleWebSocketServer.options()},
41+
signaling:
42+
Signaling.t()
43+
| {:websocket, SimpleWebSocketServer.options()}
44+
| {:whip, Membrane.WebRTC.Source.whip_options()},
4245
status: :init | :connecting | :connected | :closed,
4346
audio_params: [ExWebRTC.RTPCodecParameters.t()],
4447
video_params: [ExWebRTC.RTPCodecParameters.t()],
@@ -210,6 +213,12 @@ defmodule Membrane.WebRTC.ExWebRTCSource do
210213
{[], %{state | status: :connected}}
211214
end
212215

216+
@impl true
217+
def handle_info({:ex_webrtc, _from, {:connection_state_change, :failed}}, _ctx, state) do
218+
Membrane.Logger.debug("webrtc connection failed")
219+
{[terminate: {:shutdown, :connection_failed}], %{state | status: :closed}}
220+
end
221+
213222
@impl true
214223
def handle_info({:ex_webrtc, _from, message}, _ctx, state) do
215224
Membrane.Logger.debug("Ignoring ex_webrtc message: #{inspect(message)}")
@@ -298,6 +307,10 @@ defmodule Membrane.WebRTC.ExWebRTCSource do
298307
ctx,
299308
%{signaling: %{pid: signaling_pid}} = state
300309
) do
310+
if state.pc != nil do
311+
PeerConnection.stop(state.pc)
312+
end
313+
301314
handle_close(ctx, state)
302315
end
303316

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Membrane.WebRTC.Plugin.Mixfile do
22
use Mix.Project
33

4-
@version "0.25.3"
4+
@version "0.26.0"
55
@github_url "https://github.com/membraneframework/membrane_webrtc_plugin"
66

77
def project do
@@ -49,7 +49,7 @@ defmodule Membrane.WebRTC.Plugin.Mixfile do
4949
{:membrane_rtp_opus_plugin, "~> 0.10.0"},
5050

5151
# Other dependencies
52-
{:ex_webrtc, "~> 0.8.0"},
52+
{:ex_webrtc, "~> 0.15.0"},
5353
{:corsica, "~> 2.0"},
5454
{:bandit, "~> 1.2"},
5555
{:websock_adapter, "~> 0.5.0"},

0 commit comments

Comments
 (0)