fix: handshake mutex was keeping the room mutex in locked state

pull/1/head
Benyamin Azarkhazin 2023-08-04 16:07:47 +03:30
parent 1ff98068cd
commit 53d51d446a
Signed by: benyamin
GPG Key ID: 3AE44F5623C70269
1 changed files with 10 additions and 7 deletions

View File

@ -25,6 +25,7 @@ type Peer struct {
Conn *webrtc.PeerConnection
CanPublish bool
HandshakeLock *sync.Mutex
didOnce bool
}
type Room struct {
@ -237,7 +238,7 @@ func (r *RoomRepository) updatePCTracks(roomId string) {
return
}
room := r.Rooms[roomId]
defer r.Unlock()
r.Unlock()
room.Lock()
defer room.Unlock()
for _, peer := range room.Peers {
@ -278,17 +279,19 @@ func (r *RoomRepository) updatePCTracks(roomId string) {
for trackId, rtpSender := range alreadySentTracks {
if _, exists := room.Tracks[trackId]; !exists {
println("[PC] remove track", trackId, "from", peer.ID)
_ = rtpSender.Stop()
//_ = rtpSender.Stop()
_ = peer.Conn.RemoveTrack(rtpSender)
}
}
room.trackLock.Unlock()
if renegotiate {
err := r.offerPeer(peer, roomId)
if err != nil {
println(`[E]`, err.Error())
return
}
go func(peer *Peer, roomId string) {
err := r.offerPeer(peer, roomId)
if err != nil {
println(`[E]`, err.Error())
return
}
}(peer, roomId)
}
}
}