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") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Set the handler for Peer connection state

View File

@@ -62,6 +62,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Register data channel creation handling

View File

@@ -172,6 +172,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Set the handler for Peer connection state
@@ -186,6 +192,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Now, create an offer

View File

@@ -48,6 +48,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Register data channel creation handling

View File

@@ -126,6 +126,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // 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") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Register data channel creation handling

View File

@@ -132,6 +132,12 @@ func main() { //nolint:gocognit
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Register channel opening handling

View File

@@ -140,6 +140,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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("."))) http.Handle("/", http.FileServer(http.Dir(".")))

View File

@@ -238,6 +238,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Wait for the offer to be pasted

View File

@@ -139,6 +139,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Create an answer

View File

@@ -197,6 +197,12 @@ func main() {
fmt.Println("Done forwarding") fmt.Println("Done forwarding")
os.Exit(0) 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 // Wait for the offer to be pasted

View File

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

View File

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

View File

@@ -165,6 +165,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Create an answer

View File

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

View File

@@ -143,6 +143,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Set the handler for Peer connection state
@@ -157,6 +163,12 @@ func main() {
fmt.Println("Peer Connection has gone to failed exiting") fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0) 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 // Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate