mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 15:16:52 +08:00
Safer Event Callbacks
Resolves #218 Change Event Callback APIs to setter functions which take care of locking so that users don't need to know about or remember to do this.
This commit is contained in:
@@ -33,7 +33,7 @@ func main() {
|
||||
// Set a handler for when a new remote track starts, this handler saves buffers to disk as
|
||||
// an ivf file, since we could have multiple video tracks we provide a counter.
|
||||
// In your application this is where you would handle/process video
|
||||
peerConnection.OnTrack = func(track *webrtc.RTCTrack) {
|
||||
peerConnection.OnTrack(func(track *webrtc.RTCTrack) {
|
||||
if track.Codec.Name == webrtc.VP8 {
|
||||
fmt.Println("Got VP8 track, saving to disk as output.ivf")
|
||||
i, err := ivfwriter.New("output.ivf")
|
||||
@@ -43,13 +43,13 @@ func main() {
|
||||
util.Check(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
// This will notify you when the peer has connected/disconnected
|
||||
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||
}
|
||||
})
|
||||
|
||||
// Wait for the offer to be pasted
|
||||
sd := util.Decode(util.MustReadStdin())
|
||||
|
Reference in New Issue
Block a user