Skip to content

Commit

Permalink
hot fix: readd locks
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Oct 24, 2023
1 parent a2cebaf commit 6a44498
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions machinery/src/cloud/Cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,12 @@ func HandleLiveStreamHD(livestreamCursor *pubsub.QueueCursor, configuration *mod
for handshake := range communication.HandleLiveHDHandshake {
log.Log.Info("HandleLiveStreamHD: setting up a peer connection.")
key := config.Key + "/" + handshake.SessionID
webrtc.CandidatesMutex.Lock()
_, ok := webrtc.CandidateArrays[key]
if !ok {
webrtc.CandidateArrays[key] = make(chan string)
}
webrtc.CandidatesMutex.Unlock()
webrtc.InitializeWebRTCConnection(configuration, communication, mqttClient, videoTrack, audioTrack, handshake, webrtc.CandidateArrays[key])

}
Expand Down
6 changes: 6 additions & 0 deletions machinery/src/webrtc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,19 @@ func InitializeWebRTCConnection(configuration *models.Configuration, communicati
panic(err)
}

// When an ICE candidate is available send to the other Pion instance
// the other Pion instance will add this candidate by calling AddICECandidate
var candidatesMux sync.Mutex
// When an ICE candidate is available send to the other peer using the signaling server (MQTT).
// The other peer will add this candidate by calling AddICECandidate
peerConnection.OnICECandidate(func(candidate *pionWebRTC.ICECandidate) {
if candidate == nil {
return
}

candidatesMux.Lock()
defer candidatesMux.Unlock()

// Create a config map
valueMap := make(map[string]interface{})
candateJSON := candidate.ToJSON()
Expand Down

0 comments on commit 6a44498

Please sign in to comment.