File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -184,7 +184,6 @@ export function createPublisherHook(iceServers = []) {
184
184
185
185
view . disableControls ( view ) ;
186
186
187
- console . log ( iceServers ) ;
188
187
view . pc = new RTCPeerConnection ( { iceServers : iceServers } ) ;
189
188
190
189
// handle local events
Original file line number Diff line number Diff line change @@ -2,6 +2,11 @@ export function createSubscriberHook(iceServers = []) {
2
2
return {
3
3
async mounted ( ) {
4
4
this . pc = new RTCPeerConnection ( { iceServers : iceServers } ) ;
5
+
6
+ this . pc . onicecandidate = ( ev ) => {
7
+ this . pushEventTo ( this . el , "ice" , JSON . stringify ( ev . candidate ) ) ;
8
+ } ;
9
+
5
10
this . pc . ontrack = ( ev ) => {
6
11
console . log ( "ontrack" ) ;
7
12
this . el . srcObject = ev . streams [ 0 ] ;
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ defmodule LiveExWebRTC.Subscriber do
11
11
"""
12
12
end
13
13
14
+ def handle_event ( _event , _unsigned_params , % { assigns: % { pc: nil } } = socket ) do
15
+ { :noreply , socket }
16
+ end
17
+
14
18
def handle_event ( "offer" , unsigned_params , socket ) do
15
19
offer = SessionDescription . from_json ( unsigned_params )
16
20
{ :ok , pc } = spawn_peer_connection ( socket )
@@ -37,6 +41,22 @@ defmodule LiveExWebRTC.Subscriber do
37
41
{ :noreply , socket }
38
42
end
39
43
44
+ def handle_event ( "ice" , "null" , socket ) do
45
+ :ok = PeerConnection . add_ice_candidate ( socket . assigns . pc , % { candidate: "" } )
46
+ { :noreply , socket }
47
+ end
48
+
49
+ def handle_event ( "ice" , unsigned_params , socket ) do
50
+ cand =
51
+ unsigned_params
52
+ |> Jason . decode! ( )
53
+ |> ExWebRTC.ICECandidate . from_json ( )
54
+
55
+ :ok = PeerConnection . add_ice_candidate ( socket . assigns . pc , cand )
56
+
57
+ { :noreply , socket }
58
+ end
59
+
40
60
defp spawn_peer_connection ( socket ) do
41
61
pc_opts =
42
62
[
You can’t perform that action at this time.
0 commit comments