@@ -14,8 +14,8 @@ import (
14
14
15
15
"github.com/pion/example-webrtc-applications/internal/signal"
16
16
"github.com/pion/rtcp"
17
- "github.com/pion/webrtc/v2 "
18
- "github.com/pion/webrtc/v2 /pkg/media/ivfwriter"
17
+ "github.com/pion/webrtc/v3 "
18
+ "github.com/pion/webrtc/v3 /pkg/media/ivfwriter"
19
19
"gocv.io/x/gocv"
20
20
)
21
21
@@ -140,29 +140,24 @@ func createWebRTCConn(ffmpegIn io.Writer) {
140
140
panic (err )
141
141
}
142
142
143
- if _ , err = peerConnection .AddTransceiver (webrtc .RTPCodecTypeVideo ); err != nil {
144
- panic (err )
145
- }
146
-
147
143
// Set a handler for when a new remote track starts, this handler copies inbound RTP packets,
148
144
// replaces the SSRC and sends them back
149
- peerConnection .OnTrack (func (track * webrtc.Track , receiver * webrtc.RTPReceiver ) {
145
+ peerConnection .OnTrack (func (track * webrtc.TrackRemote , receiver * webrtc.RTPReceiver ) {
150
146
// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
151
- // This is a temporary fix until we implement incoming RTCP events, then we would push a PLI only when a viewer requests it
152
147
go func () {
153
148
ticker := time .NewTicker (time .Second * 3 )
154
149
for range ticker .C {
155
- errSend := peerConnection .WriteRTCP ([]rtcp.Packet {& rtcp.PictureLossIndication {MediaSSRC : track .SSRC ()}})
150
+ errSend := peerConnection .WriteRTCP ([]rtcp.Packet {& rtcp.PictureLossIndication {MediaSSRC : uint32 ( track .SSRC () )}})
156
151
if errSend != nil {
157
152
fmt .Println (errSend )
158
153
}
159
154
}
160
155
}()
161
156
162
- fmt .Printf ("Track has started, of type %d: %s \n " , track .PayloadType (), track .Codec ().Name )
157
+ fmt .Printf ("Track has started, of type %d: %s \n " , track .PayloadType (), track .Codec ().RTPCodecCapability . MimeType )
163
158
for {
164
159
// Read RTP packets being sent to Pion
165
- rtp , readErr := track .ReadRTP ()
160
+ rtp , _ , readErr := track .ReadRTP ()
166
161
if readErr != nil {
167
162
panic (readErr )
168
163
}
@@ -194,13 +189,20 @@ func createWebRTCConn(ffmpegIn io.Writer) {
194
189
panic (err )
195
190
}
196
191
192
+ // Create channel that is blocked until ICE Gathering is complete
193
+ gatherComplete := webrtc .GatheringCompletePromise (peerConnection )
194
+
197
195
// Sets the LocalDescription, and starts our UDP listeners
198
196
err = peerConnection .SetLocalDescription (answer )
199
197
if err != nil {
200
198
panic (err )
201
199
}
202
200
203
- // Output the answer in base64 so we can paste it in browser
204
- fmt .Println (signal .Encode (answer ))
201
+ // Block until ICE Gathering is complete, disabling trickle ICE
202
+ // we do this because we only can exchange one signaling message
203
+ // in a production application you should exchange ICE Candidates via OnICECandidate
204
+ <- gatherComplete
205
205
206
+ // Output the answer in base64 so we can paste it in browser
207
+ fmt .Println (signal .Encode (* peerConnection .LocalDescription ()))
206
208
}
0 commit comments