Skip to content

Instantly share code, notes, and snippets.

@Sean-Der
Last active December 24, 2020 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sean-Der/0b96b0ef47e6142f2e6d850ecfa5a662 to your computer and use it in GitHub Desktop.
Save Sean-Der/0b96b0ef47e6142f2e6d850ecfa5a662 to your computer and use it in GitHub Desktop.
diff --git a/examples/pion-to-pion/answer/main.go b/examples/pion-to-pion/answer/main.go
index 81ad7c8..019acbb 100644
--- a/examples/pion-to-pion/answer/main.go
+++ b/examples/pion-to-pion/answer/main.go
@@ -53,6 +53,10 @@ func main() { // nolint:gocognit
panic(err)
}
+ peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
+ fmt.Printf("Track %s has started, of type %d: %s \n", track.ID(), track.PayloadType(), track.Codec().MimeType)
+ })
+
// When an ICE candidate is available send to the other Pion instance
// the other Pion instance will add this candidate by calling AddICECandidate
peerConnection.OnICECandidate(func(c *webrtc.ICECandidate) {
diff --git a/examples/pion-to-pion/offer/main.go b/examples/pion-to-pion/offer/main.go
index c3c1112..8838519 100644
--- a/examples/pion-to-pion/offer/main.go
+++ b/examples/pion-to-pion/offer/main.go
@@ -12,6 +12,7 @@ import (
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/examples/internal/signal"
+ "github.com/pion/webrtc/v3/pkg/media"
)
func signalCandidate(addr string, c *webrtc.ICECandidate) error {
@@ -53,6 +54,33 @@ func main() { //nolint:gocognit
panic(err)
}
+ firstTrack, err := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: "video/vp8"}, "video1", "pion")
+ if err != nil {
+ panic(err)
+ }
+
+ if _, err := peerConnection.AddTrack(firstTrack); err != nil {
+ panic(err)
+ }
+
+ secondTrack, err := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: "video/vp8"}, "video2", "pion")
+ if err != nil {
+ panic(err)
+ }
+
+ if _, err := peerConnection.AddTrack(secondTrack); err != nil {
+ panic(err)
+ }
+
+ go func() {
+ for {
+ _ = firstTrack.WriteSample(media.Sample{Data: []byte{0x0, 0x1, 0x2, 0x3}, Duration: time.Second})
+ _ = secondTrack.WriteSample(media.Sample{Data: []byte{0x0, 0x1, 0x2, 0x3}, Duration: time.Second})
+
+ time.Sleep(time.Millisecond * 200)
+ }
+ }()
+
// When an ICE candidate is available send to the other Pion instance
// the other Pion instance will add this candidate by calling AddICECandidate
peerConnection.OnICECandidate(func(c *webrtc.ICECandidate) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment