-
Hello everyone and thanks for your awesome package. I just tried the play from disk example and adopt to my project structure. On the local network it works just fine, but in the Web the connection doesn't work. I am not sure, if this is a bug or if i did something wrong. For the client side I tried flutter webrtc and browser and both not working in the web. func StartWebRTCSession(ctx context.Context, o string, c chan webrtc.SessionDescription) error {
var offer = webrtc.SessionDescription{}
utils.Decode(o, &offer)
mediaEngine := webrtc.MediaEngine{}
if err := mediaEngine.PopulateFromSDP(offer); err != nil {
logger.ErrorLn(err)
return err
}
//if err := settingsEngine.SetEphemeralUDPPortRange(5000, 5200); err != nil {
// logger.ErrorLn(err)
//}
api := webrtc.NewAPI(webrtc.WithMediaEngine(mediaEngine))
peerConnection, err := api.NewPeerConnection(webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:stun.l.google.com:19302"},
},
{
URLs: []string{"***"},
Username: "***",
Credential: "***",
},
},
})
if err != nil {
log.Println(err)
return err
}
if err = peerConnection.SetRemoteDescription(offer); err != nil {
log.Println(err)
return err
}
iceConnectedCtx, iceConnectedCtxCancel := context.WithCancel(context.Background())
payloadType, err := getPayloadType(mediaEngine, webrtc.RTPCodecTypeVideo, "VP8")
if err != nil {
logger.ErrorLn(err)
return err
}
videoTrack, addTrackErr := peerConnection.NewTrack(payloadType, rand.Uint32(), "video", "pion")
if addTrackErr != nil {
panic(addTrackErr)
}
if _, addTrackErr = peerConnection.AddTrack(videoTrack); addTrackErr != nil {
panic(addTrackErr)
}
go func() {
// Open a IVF file and start reading using our IVFReader
file, ivfErr := os.Open(videoFile)
if ivfErr != nil {
panic(ivfErr)
}
ivf, header, ivfErr := ivfreader.NewWith(file)
if ivfErr != nil {
panic(ivfErr)
}
// Wait for connection established
<-iceConnectedCtx.Done()
// Send our video file frame at a time. Pace our sending so we send it at the same speed it should be played back as.
// This isn't required since the video is timestamped, but we will such much higher loss if we send all at once.
sleepTime := time.Millisecond * time.Duration((float32(header.TimebaseNumerator)/float32(header.TimebaseDenominator))*1000)
for {
frame, _, ivfErr := ivf.ParseNextFrame()
if ivfErr == io.EOF {
fmt.Printf("All video frames parsed and sent")
break
}
if ivfErr != nil {
panic(ivfErr)
}
time.Sleep(sleepTime)
if ivfErr = videoTrack.WriteSample(media.Sample{Data: frame, Samples: 90000}); ivfErr != nil {
panic(ivfErr)
}
}
}()
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
fmt.Printf("Connection State has changed %s \n", connectionState.String())
if connectionState == webrtc.ICEConnectionStateConnected {
iceConnectedCtxCancel()
}
})
answer, err := peerConnection.CreateAnswer(nil)
c <- answer
if err != nil {
panic(err)
}
// Create channel that is blocked until ICE Gathering is complete
gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
// Sets the LocalDescription, and starts our UDP listeners
if err := peerConnection.SetLocalDescription(answer); err != nil {
panic(err)
}
// Block until ICE Gathering is complete, disabling trickle ICE
// we do this because we only can exchange one signaling message
// in a production application you should exchange ICE Candidates via OnICECandidate
<-gatherComplete
return nil
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @arttobe Would you mind upgrading to v3, With connectivity issues the problem is usually that candidates aren't being shared. Are you blocking until all candidates are gathered and sharing the SessionDescription, or do you use trickle ICE? |
Beta Was this translation helpful? Give feedback.
Hi @arttobe
Would you mind upgrading to v3,
PopulateFromSDP
was from/v2
so your issue may just be fixed by that.With connectivity issues the problem is usually that candidates aren't being shared. Are you blocking until all candidates are gathered and sharing the SessionDescription, or do you use trickle ICE?