Skip to content

Commit 39e30ab

Browse files
committed
Added PR deepch#485 (to upstream)
1 parent c2cff8f commit 39e30ab

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

apiHTTPWebRTC.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ func HTTPAPIServerStreamWebRTC(c *gin.Context) {
4141
}).Errorln(err.Error())
4242
return
4343
}
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+
4553
answer, err := muxerWebRTC.WriteHeader(codecs, c.PostForm("data"))
4654
if err != nil {
4755
c.IndentedJSON(400, Message{Status: 0, Payload: err.Error()})
@@ -68,17 +76,27 @@ func HTTPAPIServerStreamWebRTC(c *gin.Context) {
6876
return
6977
}
7078
defer Storage.ClientDelete(c.Param("uuid"), cid, c.Param("channel"))
79+
defer muxerWebRTC.Close() // Close the WebRTC session when done
7180
var videoStart bool
7281
noVideo := time.NewTimer(10 * time.Second)
7382
for {
7483
select {
7584
case <-noVideo.C:
76-
// c.IndentedJSON(500, Message{Status: 0, Payload: ErrorStreamNoVideo.Error()})
85+
c.IndentedJSON(500, Message{Status: 0, Payload: ErrorStreamNoVideo.Error()})
7786
requestLogger.WithFields(logrus.Fields{
7887
"call": "ErrorStreamNoVideo",
7988
}).Errorln(ErrorStreamNoVideo.Error())
8089
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+
82100
if pck.IsKeyFrame {
83101
noVideo.Reset(10 * time.Second)
84102
videoStart = true

0 commit comments

Comments
 (0)