diff --git a/machinery/src/cloud/Cloud.go b/machinery/src/cloud/Cloud.go index b2dc551..7740eba 100644 --- a/machinery/src/cloud/Cloud.go +++ b/machinery/src/cloud/Cloud.go @@ -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]) } diff --git a/machinery/src/webrtc/main.go b/machinery/src/webrtc/main.go index 0dc354e..057d1eb 100644 --- a/machinery/src/webrtc/main.go +++ b/machinery/src/webrtc/main.go @@ -179,6 +179,9 @@ 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) { @@ -186,6 +189,9 @@ func InitializeWebRTCConnection(configuration *models.Configuration, communicati return } + candidatesMux.Lock() + defer candidatesMux.Unlock() + // Create a config map valueMap := make(map[string]interface{}) candateJSON := candidate.ToJSON()