Skip to content

Commit f66b8b6

Browse files
committed
Update examples to handle going to Closed
Relates to #1767
1 parent b9c3b86 commit f66b8b6

File tree

16 files changed

+105
-6
lines changed

16 files changed

+105
-6
lines changed

examples/custom-logger/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ func main() {
100100
fmt.Println("Peer Connection has gone to failed exiting")
101101
os.Exit(0)
102102
}
103+
104+
if s == webrtc.PeerConnectionStateClosed {
105+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
106+
fmt.Println("Peer Connection has gone to closed exiting")
107+
os.Exit(0)
108+
}
103109
})
104110

105111
// Set the handler for Peer connection state

examples/data-channels-detach/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ func main() {
6262
fmt.Println("Peer Connection has gone to failed exiting")
6363
os.Exit(0)
6464
}
65+
66+
if s == webrtc.PeerConnectionStateClosed {
67+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
68+
fmt.Println("Peer Connection has gone to closed exiting")
69+
os.Exit(0)
70+
}
6571
})
6672

6773
// Register data channel creation handling

examples/data-channels-flow-control/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ func main() {
172172
fmt.Println("Peer Connection has gone to failed exiting")
173173
os.Exit(0)
174174
}
175+
176+
if s == webrtc.PeerConnectionStateClosed {
177+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
178+
fmt.Println("Peer Connection has gone to closed exiting")
179+
os.Exit(0)
180+
}
175181
})
176182

177183
// Set the handler for Peer connection state
@@ -186,6 +192,12 @@ func main() {
186192
fmt.Println("Peer Connection has gone to failed exiting")
187193
os.Exit(0)
188194
}
195+
196+
if s == webrtc.PeerConnectionStateClosed {
197+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
198+
fmt.Println("Peer Connection has gone to closed exiting")
199+
os.Exit(0)
200+
}
189201
})
190202

191203
// Now, create an offer

examples/data-channels/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ func main() {
4848
fmt.Println("Peer Connection has gone to failed exiting")
4949
os.Exit(0)
5050
}
51+
52+
if s == webrtc.PeerConnectionStateClosed {
53+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
54+
fmt.Println("Peer Connection has gone to closed exiting")
55+
os.Exit(0)
56+
}
5157
})
5258

5359
// Register data channel creation handling

examples/insertable-streams/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ func main() {
126126
fmt.Println("Peer Connection has gone to failed exiting")
127127
os.Exit(0)
128128
}
129+
130+
if s == webrtc.PeerConnectionStateClosed {
131+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
132+
fmt.Println("Peer Connection has gone to closed exiting")
133+
os.Exit(0)
134+
}
129135
})
130136

131137
// Wait for the offer to be pasted

examples/pion-to-pion/answer/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ func main() { // nolint:gocognit
147147
fmt.Println("Peer Connection has gone to failed exiting")
148148
os.Exit(0)
149149
}
150+
151+
if s == webrtc.PeerConnectionStateClosed {
152+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
153+
fmt.Println("Peer Connection has gone to closed exiting")
154+
os.Exit(0)
155+
}
150156
})
151157

152158
// Register data channel creation handling

examples/pion-to-pion/offer/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ func main() { //nolint:gocognit
132132
fmt.Println("Peer Connection has gone to failed exiting")
133133
os.Exit(0)
134134
}
135+
136+
if s == webrtc.PeerConnectionStateClosed {
137+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
138+
fmt.Println("Peer Connection has gone to closed exiting")
139+
os.Exit(0)
140+
}
135141
})
136142

137143
// Register channel opening handling

examples/play-from-disk-renegotiation/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ func main() {
140140
fmt.Println("Peer Connection has gone to failed exiting")
141141
os.Exit(0)
142142
}
143+
144+
if s == webrtc.PeerConnectionStateClosed {
145+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
146+
fmt.Println("Peer Connection has gone to closed exiting")
147+
os.Exit(0)
148+
}
143149
})
144150

145151
http.Handle("/", http.FileServer(http.Dir(".")))

examples/play-from-disk/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ func main() {
238238
fmt.Println("Peer Connection has gone to failed exiting")
239239
os.Exit(0)
240240
}
241+
242+
if s == webrtc.PeerConnectionStateClosed {
243+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
244+
fmt.Println("Peer Connection has gone to closed exiting")
245+
os.Exit(0)
246+
}
241247
})
242248

243249
// Wait for the offer to be pasted

examples/reflect/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ func main() {
139139
fmt.Println("Peer Connection has gone to failed exiting")
140140
os.Exit(0)
141141
}
142+
143+
if s == webrtc.PeerConnectionStateClosed {
144+
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
145+
fmt.Println("Peer Connection has gone to closed exiting")
146+
os.Exit(0)
147+
}
142148
})
143149

144150
// Create an answer

0 commit comments

Comments
 (0)