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