fix: Implement proactive packet flushing based on Content-Length to resolve UI update lag
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -133,6 +134,7 @@ func (c *LocalCapturer) processStream(r io.Reader) {
|
||||
var buffer strings.Builder
|
||||
inSIPMessage := false
|
||||
var msgNetInfo *NetInfo
|
||||
contentLength := -1
|
||||
|
||||
for scanner.Scan() {
|
||||
c.mu.Lock()
|
||||
@@ -192,11 +194,38 @@ func (c *LocalCapturer) processStream(r io.Reader) {
|
||||
}
|
||||
|
||||
inSIPMessage = true
|
||||
contentLength = -1 // Reset for new message
|
||||
}
|
||||
|
||||
if inSIPMessage {
|
||||
buffer.WriteString(line)
|
||||
buffer.WriteString("\r\n")
|
||||
|
||||
// Check for Content-Length
|
||||
lowerLine := strings.ToLower(line)
|
||||
if strings.HasPrefix(lowerLine, "content-length:") || strings.HasPrefix(lowerLine, "l:") {
|
||||
parts := strings.Split(line, ":")
|
||||
if len(parts) >= 2 {
|
||||
val := strings.TrimSpace(parts[1])
|
||||
if val != "" {
|
||||
if cl, err := strconv.Atoi(val); err == nil {
|
||||
contentLength = cl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for end of headers (empty line)
|
||||
if line == "" {
|
||||
// If Content-Length is 0 (or not found, treating as 0 for safety in this context usually 0 for BYE/ACK)
|
||||
// Flush immediately
|
||||
if contentLength <= 0 {
|
||||
c.parseAndEmit(buffer.String(), msgNetInfo)
|
||||
buffer.Reset()
|
||||
inSIPMessage = false
|
||||
contentLength = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user