Update examples to handle going to Closed

Relates to #1767
This commit is contained in:
Sean DuBois
2023-09-05 10:44:57 -04:00
committed by Sean DuBois
parent b9c3b86be0
commit f66b8b6ce2
16 changed files with 105 additions and 6 deletions

View File

@@ -100,6 +100,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Set the handler for Peer connection state

View File

@@ -62,6 +62,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Register data channel creation handling

View File

@@ -172,6 +172,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Set the handler for Peer connection state
@@ -186,6 +192,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Now, create an offer

View File

@@ -48,6 +48,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Register data channel creation handling

View File

@@ -126,6 +126,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Wait for the offer to be pasted

View File

@@ -147,6 +147,12 @@ func main() { // nolint:gocognit
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Register data channel creation handling

View File

@@ -132,6 +132,12 @@ func main() { //nolint:gocognit
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Register channel opening handling

View File

@@ -140,6 +140,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
http.Handle("/", http.FileServer(http.Dir(".")))

View File

@@ -238,6 +238,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Wait for the offer to be pasted

View File

@@ -139,6 +139,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Create an answer

View File

@@ -197,6 +197,12 @@ func main() {
fmt.Println("Done forwarding")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Done forwarding")
os.Exit(0)
}
})
// Wait for the offer to be pasted

View File

@@ -30,10 +30,12 @@ func saveToDisk(i media.Writer, track *webrtc.TrackRemote) {
for {
rtpPacket, _, err := track.ReadRTP()
if err != nil {
panic(err)
fmt.Println(err)
return
}
if err := i.WriteRTP(rtpPacket); err != nil {
panic(err)
fmt.Println(err)
return
}
}
}
@@ -113,7 +115,7 @@ func main() {
if connectionState == webrtc.ICEConnectionStateConnected {
fmt.Println("Ctrl+C the remote client to stop the demo")
} else if connectionState == webrtc.ICEConnectionStateFailed {
} else if connectionState == webrtc.ICEConnectionStateFailed || connectionState == webrtc.ICEConnectionStateClosed {
if closeErr := ivfFile.Close(); closeErr != nil {
panic(closeErr)
}

View File

@@ -31,10 +31,12 @@ func saveToDisk(i media.Writer, track *webrtc.TrackRemote) {
for {
rtpPacket, _, err := track.ReadRTP()
if err != nil {
panic(err)
fmt.Println(err)
return
}
if err := i.WriteRTP(rtpPacket); err != nil {
panic(err)
fmt.Println(err)
return
}
}
}
@@ -137,7 +139,7 @@ func main() {
if connectionState == webrtc.ICEConnectionStateConnected {
fmt.Println("Ctrl+C the remote client to stop the demo")
} else if connectionState == webrtc.ICEConnectionStateFailed {
} else if connectionState == webrtc.ICEConnectionStateFailed || connectionState == webrtc.ICEConnectionStateClosed {
if closeErr := oggFile.Close(); closeErr != nil {
panic(closeErr)
}

View File

@@ -165,6 +165,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Create an answer

View File

@@ -139,6 +139,11 @@ func main() { // nolint:gocognit
// Note that the PeerConnection may come back from PeerConnectionStateDisconnected.
done()
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
done()
}
})
// Create an answer

View File

@@ -143,6 +143,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Set the handler for Peer connection state
@@ -157,6 +163,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}
if s == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
}
})
// Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate