@@ -41,7 +41,15 @@ func HTTPAPIServerStreamWebRTC(c *gin.Context) {
41
41
}).Errorln (err .Error ())
42
42
return
43
43
}
44
- muxerWebRTC := webrtc .NewMuxer (webrtc.Options {ICEServers : Storage .ServerICEServers (), ICEUsername : Storage .ServerICEUsername (), ICECredential : Storage .ServerICECredential (), PortMin : Storage .ServerWebRTCPortMin (), PortMax : Storage .ServerWebRTCPortMax ()})
44
+
45
+ muxerWebRTC := webrtc .NewMuxer (webrtc.Options {
46
+ ICEServers : Storage .ServerICEServers (),
47
+ ICEUsername : Storage .ServerICEUsername (),
48
+ ICECredential : Storage .ServerICECredential (),
49
+ PortMin : Storage .ServerWebRTCPortMin (),
50
+ PortMax : Storage .ServerWebRTCPortMax (),
51
+ })
52
+
45
53
answer , err := muxerWebRTC .WriteHeader (codecs , c .PostForm ("data" ))
46
54
if err != nil {
47
55
c .IndentedJSON (400 , Message {Status : 0 , Payload : err .Error ()})
@@ -68,17 +76,27 @@ func HTTPAPIServerStreamWebRTC(c *gin.Context) {
68
76
return
69
77
}
70
78
defer Storage .ClientDelete (c .Param ("uuid" ), cid , c .Param ("channel" ))
79
+ defer muxerWebRTC .Close () // Close the WebRTC session when done
71
80
var videoStart bool
72
81
noVideo := time .NewTimer (10 * time .Second )
73
82
for {
74
83
select {
75
84
case <- noVideo .C :
76
- // c.IndentedJSON(500, Message{Status: 0, Payload: ErrorStreamNoVideo.Error()})
85
+ c .IndentedJSON (500 , Message {Status : 0 , Payload : ErrorStreamNoVideo .Error ()})
77
86
requestLogger .WithFields (logrus.Fields {
78
87
"call" : "ErrorStreamNoVideo" ,
79
88
}).Errorln (ErrorStreamNoVideo .Error ())
80
89
return
81
- case pck := <- ch :
90
+ case pck , ok := <- ch :
91
+ if ! ok {
92
+ // Channel closed, likely due to camera disconnection
93
+ c .IndentedJSON (500 , Message {Status : 0 , Payload : "Camera disconnected" })
94
+ requestLogger .WithFields (logrus.Fields {
95
+ "call" : "CameraDisconnected" ,
96
+ }).Errorln ("Camera disconnected" )
97
+ return
98
+ }
99
+
82
100
if pck .IsKeyFrame {
83
101
noVideo .Reset (10 * time .Second )
84
102
videoStart = true
0 commit comments