mirror of
https://github.com/jech/galene.git
synced 2024-11-23 00:55:58 +01:00
Use mids instead of track ids for indexing labels.
It turns out that track ids are not necessarily the same on the local and remote sides. Thanks to Ines Klimann for noticing the issue.
This commit is contained in:
parent
cbff5067b2
commit
9575b80893
3 changed files with 67 additions and 7 deletions
37
client.go
37
client.go
|
@ -346,9 +346,28 @@ func addUpConn(c *client, id string) (*upConnection, error) {
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mid := getUpMid(pc, remote)
|
||||||
|
if mid == "" {
|
||||||
|
log.Printf("Couldn't get track's mid")
|
||||||
|
c.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
label, ok := u.labels[mid]
|
||||||
|
if !ok {
|
||||||
|
log.Printf("Couldn't get track's label")
|
||||||
|
isvideo := remote.Kind() == webrtc.RTPCodecTypeVideo
|
||||||
|
if isvideo {
|
||||||
|
label = "video"
|
||||||
|
} else {
|
||||||
|
label = "audio"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
track := &upTrack{
|
track := &upTrack{
|
||||||
track: remote,
|
track: remote,
|
||||||
label: u.labels[remote.ID()],
|
label: label,
|
||||||
cache: packetcache.New(96),
|
cache: packetcache.New(96),
|
||||||
rate: estimator.New(time.Second),
|
rate: estimator.New(time.Second),
|
||||||
jitter: jitter.New(remote.Codec().ClockRate),
|
jitter: jitter.New(remote.Codec().ClockRate),
|
||||||
|
@ -957,8 +976,20 @@ func negotiate(c *client, down *downConnection) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := make(map[string]string)
|
labels := make(map[string]string)
|
||||||
for _, t := range down.tracks {
|
for _, t := range down.pc.GetTransceivers() {
|
||||||
labels[t.track.ID()] = t.remote.label
|
var track *webrtc.Track
|
||||||
|
if t.Sender() != nil {
|
||||||
|
track = t.Sender().Track()
|
||||||
|
}
|
||||||
|
if track == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tr := range down.tracks {
|
||||||
|
if tr.track == track {
|
||||||
|
labels[t.Mid()] = tr.remote.label
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.write(clientMessage{
|
return c.write(clientMessage{
|
||||||
|
|
14
group.go
14
group.go
|
@ -96,11 +96,21 @@ type upConnection struct {
|
||||||
labels map[string]string
|
labels map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUpMid(pc *webrtc.PeerConnection, track *webrtc.Track) string {
|
||||||
|
for _, t := range pc.GetTransceivers() {
|
||||||
|
if t.Receiver() != nil && t.Receiver().Track() == track {
|
||||||
|
return t.Mid()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (up *upConnection) complete() bool {
|
func (up *upConnection) complete() bool {
|
||||||
for id, _ := range up.labels {
|
for mid, _ := range up.labels {
|
||||||
found := false
|
found := false
|
||||||
for _, t := range up.tracks {
|
for _, t := range up.tracks {
|
||||||
if t.track.ID() == id {
|
m := getUpMid(up.pc, t.track)
|
||||||
|
if m == mid {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ function Connection(id, pc) {
|
||||||
this.pc = pc;
|
this.pc = pc;
|
||||||
this.stream = null;
|
this.stream = null;
|
||||||
this.labels = {};
|
this.labels = {};
|
||||||
|
this.labelsByMid = {};
|
||||||
this.iceCandidates = [];
|
this.iceCandidates = [];
|
||||||
this.timers = [];
|
this.timers = [];
|
||||||
this.audioStats = {};
|
this.audioStats = {};
|
||||||
|
@ -647,12 +648,18 @@ async function gotOffer(id, labels, offer) {
|
||||||
};
|
};
|
||||||
|
|
||||||
c.pc.ontrack = function(e) {
|
c.pc.ontrack = function(e) {
|
||||||
|
let label = e.transceiver && c.labelsByMid[e.transceiver.mid];
|
||||||
|
if(label) {
|
||||||
|
c.labels[e.track.id] = label;
|
||||||
|
} else {
|
||||||
|
console.error("Couldn't find label for track");
|
||||||
|
}
|
||||||
c.stream = e.streams[0];
|
c.stream = e.streams[0];
|
||||||
setMedia(id);
|
setMedia(id);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
c.labels = labels;
|
c.labelsByMid = labels;
|
||||||
|
|
||||||
await c.pc.setRemoteDescription(offer);
|
await c.pc.setRemoteDescription(offer);
|
||||||
await addIceCandidates(c);
|
await addIceCandidates(c);
|
||||||
|
@ -1066,10 +1073,22 @@ async function negotiate(id) {
|
||||||
if(!offer)
|
if(!offer)
|
||||||
throw(new Error("Didn't create offer"));
|
throw(new Error("Didn't create offer"));
|
||||||
await c.pc.setLocalDescription(offer);
|
await c.pc.setLocalDescription(offer);
|
||||||
|
|
||||||
|
// mids are not known until this point
|
||||||
|
c.pc.getTransceivers().forEach(t => {
|
||||||
|
if(t.sender && t.sender.track) {
|
||||||
|
let label = c.labels[t.sender.track.id];
|
||||||
|
if(label)
|
||||||
|
c.labelsByMid[t.mid] = label;
|
||||||
|
else
|
||||||
|
console.error("Couldn't find label for track");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
send({
|
send({
|
||||||
type: 'offer',
|
type: 'offer',
|
||||||
id: id,
|
id: id,
|
||||||
labels: c.labels,
|
labels: c.labelsByMid,
|
||||||
offer: offer,
|
offer: offer,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue