1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 16:45:58 +01:00

Create a connection interface, use it in gotICE.

This commit is contained in:
Juliusz Chroboczek 2020-05-22 22:36:47 +02:00
parent 6d6cb6caf2
commit 6005ad9eb4
2 changed files with 28 additions and 11 deletions

View file

@ -654,6 +654,18 @@ func getDownConn(c *client, id string) *downConnection {
return conn return conn
} }
func getConn(c *client, id string) connection {
up := getUpConn(c, id)
if up != nil {
return up
}
down := getDownConn(c, id)
if down != nil {
return down
}
return nil
}
func addDownConn(c *client, id string, remote *upConnection) (*downConnection, error) { func addDownConn(c *client, id string, remote *upConnection) (*downConnection, error) {
pc, err := groups.api.NewPeerConnection(iceConfiguration()) pc, err := groups.api.NewPeerConnection(iceConfiguration())
if err != nil { if err != nil {
@ -1065,18 +1077,11 @@ func gotAnswer(c *client, id string, answer webrtc.SessionDescription) error {
} }
func gotICE(c *client, candidate *webrtc.ICECandidateInit, id string) error { func gotICE(c *client, candidate *webrtc.ICECandidateInit, id string) error {
var pc *webrtc.PeerConnection conn := getConn(c, id)
down := getDownConn(c, id) if conn == nil {
if down != nil {
pc = down.pc
} else {
up := getUpConn(c, id)
if up == nil {
return errors.New("unknown id in ICE") return errors.New("unknown id in ICE")
} }
pc = up.pc return conn.getPC().AddICECandidate(*candidate)
}
return pc.AddICECandidate(*candidate)
} }
func (c *client) setRequested(requested map[string]uint32) error { func (c *client) setRequested(requested map[string]uint32) error {

12
conn.go
View file

@ -16,6 +16,10 @@ import (
"github.com/pion/webrtc/v2" "github.com/pion/webrtc/v2"
) )
type connection interface {
getPC() *webrtc.PeerConnection
}
type upTrack struct { type upTrack struct {
track *webrtc.Track track *webrtc.Track
label string label string
@ -95,6 +99,10 @@ type upConnection struct {
iceCandidates []*webrtc.ICECandidateInit iceCandidates []*webrtc.ICECandidateInit
} }
func (up *upConnection) getPC() *webrtc.PeerConnection {
return up.pc
}
func getUpMid(pc *webrtc.PeerConnection, track *webrtc.Track) string { func getUpMid(pc *webrtc.PeerConnection, track *webrtc.Track) string {
for _, t := range pc.GetTransceivers() { for _, t := range pc.GetTransceivers() {
if t.Receiver() != nil && t.Receiver().Track() == track { if t.Receiver() != nil && t.Receiver().Track() == track {
@ -189,3 +197,7 @@ type downConnection struct {
tracks []*downTrack tracks []*downTrack
iceCandidates []*webrtc.ICECandidateInit iceCandidates []*webrtc.ICECandidateInit
} }
func (down *downConnection) getPC() *webrtc.PeerConnection {
return down.pc
}