-
Notifications
You must be signed in to change notification settings - Fork 0
/
pub.go
54 lines (43 loc) · 1.1 KB
/
pub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package rtc
import (
"fmt"
"github.com/pion/webrtc/v3"
"github.com/sirupsen/logrus"
)
func OfferPublishToAnswer(api *webrtc.API, videoFile string, videoFps int, generateAnswerFunc func(webrtc.SessionDescription) (webrtc.SessionDescription, error)) (err error) {
videoTrack, err := NewH264LocalStaticSampleVideoTrack(videoFile, videoFps)
if err != nil {
return
}
peerConnection, err := NewVideoTrackPeerConnection(api, videoTrack)
if err != nil {
return
}
var offer1, offer2, answer webrtc.SessionDescription
offer1, err = peerConnection.CreateOffer(nil)
if err != nil {
return
}
peerConnection.OnICECandidate(func(candidate *webrtc.ICECandidate) {
if candidate == nil {
return
}
})
err = peerConnection.SetLocalDescription(offer1)
if err != nil {
return
}
<-webrtc.GatheringCompletePromise(peerConnection)
offer2 = *peerConnection.LocalDescription()
logrus.Debug("offer2: ", offer2.SDP)
fmt.Printf("%+v\n", offer2.SDP)
answer, err = generateAnswerFunc(offer2)
if err != nil {
return
}
err = peerConnection.SetRemoteDescription(answer)
if err != nil {
return
}
return
}