mirror of
https://gitlab.com/comunic/ComunicRTCProxy
synced 2024-12-25 13:08:54 +00:00
Better wait for new tracks
This commit is contained in:
parent
698132b070
commit
6e07514c44
37
relay.go
37
relay.go
@ -8,6 +8,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -192,7 +193,16 @@ func processCloseRequests() {
|
||||
/// Start new call
|
||||
func newCall(mainOffer receivedSignal, r *activeRelay) {
|
||||
|
||||
log.Printf("Starting new call: %s / id: %d", r.callHash, r.id)
|
||||
// I am not sure this is a strong way to determine whether we are having
|
||||
// a video call or not, but I have not found any better way yet...
|
||||
isVideoCall := strings.Contains(mainOffer.sdp.SDP, "m=video") || strings.Contains(mainOffer.sdp.SDP, "mid:video")
|
||||
print(mainOffer.sdp.SDP)
|
||||
numberTracks := 1
|
||||
if isVideoCall {
|
||||
numberTracks = 2
|
||||
}
|
||||
|
||||
log.Printf("Starting new call: %s / id: %d / number of tracks: %d", r.callHash, r.id, numberTracks)
|
||||
|
||||
// Ice candidates mutex
|
||||
var candidatesMux sync.Mutex
|
||||
@ -279,7 +289,7 @@ func newCall(mainOffer receivedSignal, r *activeRelay) {
|
||||
return
|
||||
}
|
||||
|
||||
localTrackChan := make(chan *webrtc.Track)
|
||||
localTrackChan := make(chan *webrtc.Track, numberTracks)
|
||||
|
||||
// Set a handler for when a new remote track starts, this just distributes all our packets
|
||||
// to connected peers
|
||||
@ -400,17 +410,6 @@ func newCall(mainOffer receivedSignal, r *activeRelay) {
|
||||
// Enter messags loop
|
||||
for {
|
||||
|
||||
// Receive new channels
|
||||
stopCheck := len(localTracks) >= 2 // Stop check if we got all the channel
|
||||
for !stopCheck {
|
||||
select {
|
||||
case t := <-localTrackChan:
|
||||
localTracks = append(localTracks, t)
|
||||
case <-time.After(time.Millisecond * 100):
|
||||
stopCheck = true
|
||||
}
|
||||
}
|
||||
|
||||
newMessage, ok := <-r.channel
|
||||
|
||||
if !ok {
|
||||
@ -426,6 +425,18 @@ func newCall(mainOffer receivedSignal, r *activeRelay) {
|
||||
val.Close()
|
||||
}
|
||||
|
||||
// First, we must make sure that we got all the tracks we need, before
|
||||
// creating an offer (in order not to miss a track while building the offer)
|
||||
stopCheck := len(localTracks) >= numberTracks // Stop check if we got all the channel
|
||||
for !stopCheck {
|
||||
select {
|
||||
case t := <-localTrackChan:
|
||||
localTracks = append(localTracks, t)
|
||||
case <-time.After(time.Millisecond * 1000):
|
||||
stopCheck = true
|
||||
}
|
||||
}
|
||||
|
||||
// Ice candidates mutex
|
||||
var newCandidatesMux sync.Mutex
|
||||
newPendingCandidates := make([]*webrtc.ICECandidate, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user