feat(telemost): Improve reconnection handling and message processing

This commit is contained in:
zarazaex59
2026-04-07 01:38:59 +03:00
parent 8c8faaad1d
commit a61363471d
2 changed files with 15 additions and 5 deletions

View File

@@ -73,6 +73,12 @@ func Run(roomURL, keyHex string) error {
peer.SetReconnectCallback(func(dc *webrtc.DataChannel) {
log.Println("Server reconnected - resetting multiplexer state")
for sid, conn := range s.connections {
conn.Close()
delete(s.connections, sid)
}
s.mux.Reset()
s.mux.UpdateSendFunc(func(frame []byte) error {
encrypted, err := s.cipher.Encrypt(frame)
@@ -158,15 +164,11 @@ func (s *Server) handleConnect(sid uint16, req ConnectRequest) {
for {
n, err := conn.Read(buf)
if err != nil {
if err != io.EOF {
log.Printf("Read error sid=%d: %v", sid, err)
}
s.mux.CloseStream(sid)
return
}
if err := s.mux.SendData(sid, buf[:n]); err != nil {
log.Printf("Send error sid=%d: %v", sid, err)
return
}
}

View File

@@ -187,6 +187,14 @@ func (p *Peer) handleSignaling() {
p.sendAck(uid)
}
if _, ok := msg["updateDescription"]; ok {
p.sendAck(uid)
}
if _, ok := msg["vadActivity"]; ok {
p.sendAck(uid)
}
if offer, ok := msg["subscriberSdpOffer"].(map[string]interface{}); ok && !pubSent {
sdp, _ := offer["sdp"].(string)
pcSeq, _ := offer["pcSeq"].(float64)
@@ -385,7 +393,7 @@ func (p *Peer) reconnect(ctx context.Context) error {
p.pcPub.Close()
}
time.Sleep(2 * time.Second)
time.Sleep(500 * time.Millisecond)
conn, err := GetConnectionInfo(p.roomURL, p.name)
if err != nil {