Create a connection interface, use it in gotICE.
This commit is contained in:
1 parent
6d6cb6caf2
commit
6005ad9eb4
2 files changed
+28
-11
No files matched your search
@@ -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 {
|
return errors.New("unknown id in ICE")
|
||||||
pc = down.pc
|
|
||||||
} else {
|
|
||||||
up := getUpConn(c, id)
|
|
||||||
if up == nil {
|
|
||||||
return errors.New("unknown id in ICE")
|
|
||||||
}
|
|
||||||
pc = up.pc
|
|
||||||
}
|
}
|
||||||
return pc.AddICECandidate(*candidate)
|
return conn.getPC().AddICECandidate(*candidate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) setRequested(requested map[string]uint32) error {
|
func (c *client) setRequested(requested map[string]uint32) error {
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
Reference in new issue
Block a user