Commit 6005ad9e authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Create a connection interface, use it in gotICE.

parent 6d6cb6ca
......@@ -654,6 +654,18 @@ func getDownConn(c *client, id string) *downConnection {
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) {
pc, err := groups.api.NewPeerConnection(iceConfiguration())
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 {
var pc *webrtc.PeerConnection
down := getDownConn(c, id)
if down != nil {
pc = down.pc
} else {
up := getUpConn(c, id)
if up == nil {
return errors.New("unknown id in ICE")
}
pc = up.pc
conn := getConn(c, id)
if conn == nil {
return errors.New("unknown id in ICE")
}
return pc.AddICECandidate(*candidate)
return conn.getPC().AddICECandidate(*candidate)
}
func (c *client) setRequested(requested map[string]uint32) error {
......
......@@ -16,6 +16,10 @@ import (
"github.com/pion/webrtc/v2"
)
type connection interface {
getPC() *webrtc.PeerConnection
}
type upTrack struct {
track *webrtc.Track
label string
......@@ -95,6 +99,10 @@ type upConnection struct {
iceCandidates []*webrtc.ICECandidateInit
}
func (up *upConnection) getPC() *webrtc.PeerConnection {
return up.pc
}
func getUpMid(pc *webrtc.PeerConnection, track *webrtc.Track) string {
for _, t := range pc.GetTransceivers() {
if t.Receiver() != nil && t.Receiver().Track() == track {
......@@ -189,3 +197,7 @@ type downConnection struct {
tracks []*downTrack
iceCandidates []*webrtc.ICECandidateInit
}
func (down *downConnection) getPC() *webrtc.PeerConnection {
return down.pc
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment