MCPcopy Index your code
hub / github.com/Threadfin/Threadfin / broadcastProgressUpdate

Function broadcastProgressUpdate

src/webserver.go:144–194  ·  view source on GitHub ↗

Broadcast progress update to all connected WebSocket clients

(progress ProcessingProgress)

Source from the content-addressed store, hash-verified

142
143// Broadcast progress update to all connected WebSocket clients
144func broadcastProgressUpdate(progress ProcessingProgress) {
145 broadcastMutex.Lock()
146 defer broadcastMutex.Unlock()
147
148 connections := make([]*websocket.Conn, 0, len(wsConnections))
149 wsMutex.RLock()
150 for conn := range wsConnections {
151 connections = append(connections, conn)
152 }
153 wsMutex.RUnlock()
154
155 var deadConnections []*websocket.Conn
156
157 for _, conn := range connections {
158 progressMessage := map[string]interface{}{
159 "cmd": "progress",
160 "progress": progress,
161 }
162
163 wsWriteMutex.Lock()
164 if conn == nil {
165 deadConnections = append(deadConnections, conn)
166 } else {
167 wsMutex.RLock()
168 _, exists := wsConnections[conn]
169 connMutex, mutexExists := connWriteMutexes[conn]
170 wsMutex.RUnlock()
171
172 if !exists || !mutexExists {
173 continue
174 }
175
176 connMutex.Lock()
177 conn.SetWriteDeadline(time.Now().Add(5 * time.Second))
178
179 if err := conn.WriteJSON(progressMessage); err != nil {
180 deadConnections = append(deadConnections, conn)
181 }
182
183 conn.SetWriteDeadline(time.Time{})
184 connMutex.Unlock()
185 }
186 wsWriteMutex.Unlock()
187 }
188
189 for _, deadConn := range deadConnections {
190 if deadConn != nil {
191 removeWSConnection(deadConn)
192 }
193 }
194}
195
196// StartWebserver : Startet den Webserver
197func StartWebserver() (err error) {

Callers 5

buildXEPGFunction · 0.85
updateXEPGFunction · 0.85
createXEPGDatabaseFunction · 0.85
buildDatabaseDVRFunction · 0.85
generateStrmFilesFunction · 0.85

Calls 1

removeWSConnectionFunction · 0.85

Tested by

no test coverage detected