mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Create a connection interface, use it in gotICE.
This commit is contained in:
parent
6d6cb6caf2
commit
6005ad9eb4
2 changed files with 28 additions and 11 deletions
27
client.go
27
client.go
|
@ -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 {
|
||||
|
|
12
conn.go
12
conn.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue