ionorg / ion-sdk-go

ion sdk for golang
MIT License
55 stars 46 forks source link

Track-to-rtp example doesn't work #25

Closed fenestron closed 3 years ago

fenestron commented 3 years ago

Your environment.

What did you do?

Launched pubsubtest from ion-sfu:

git clone https://github.com/pion/ion-sfu
docker-compose -f ion-sfu/examples/pubsubtest/docker-compose.yaml up -d

Opened a link in a browser: http://localhost:8000/ And pressed the start button

Run the track-to-rtp example:

git clone https://github.com/pion/ion-sdk-go
cd ion-sdk-go/example/track-to-rtp/
go run main.go -addr "localhost:50051" -session "test session"

What did you expect?

Video and audio tracks are forwarded to local UDP ports 4000 and 4002

What happened?

I get an error:

[2021-03-18 12:38:59.270] [INFO] [29][main.go][trackToRTP] => output%!(EXTRA string=track-b0b4a5b1-6e16-4d59-9859-153d82583d6f.sdp, []uint8=[], *exec.ExitError=exit status 1)
panic: write udp 127.0.0.1:43353->127.0.0.1:4000: write: connection refused

goroutine 220 [running]:
main.trackToRTP(0xc000570480, 0xc000213080)
    /home/fenestron/Projects/ion-sdk-go/example/track-to-rtp/main.go:103 +0x967
github.com/pion/ion-sdk-go.(*Client).Join.func1(0xc000570480, 0xc000213080)
    /home/fenestron/Projects/ion-sdk-go/client.go:125 +0x5d0
created by github.com/pion/webrtc/v3.(*PeerConnection).onTrack
    /home/fenestron/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.11/peerconnection.go:451 +0x10f
exit status 2

Full log: full-log.txt

fenestron commented 3 years ago

I found the solution in the rtp-forwarder example from the pion/webrtc repository https://github.com/pion/webrtc/blob/545613dcdeb5dedb01cce94175f40bcbe045df2e/examples/rtp-forwarder/main.go#L152

For this particular example, third party applications usually timeout after a short amount of time during which the user doesn't have enough time to provide the answer to the browser. That's why, for this particular example, the user first needs to provide the answer to the browser then open the third party application. Therefore we must not kill the forward on "connection refused" errors

To prevent this error, add these lines:

if opError, ok := err.(*net.OpError); ok && opError.Err.Error() == "write: connection refused" {
    continue
}