From ef637050e2d05e3cbde89a20c8043e06232f002e Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 3 Jul 2023 09:33:37 +0200 Subject: [PATCH] Add GetRemoteCandidates() This is analogue to GetLocalCandidates() and provides the user with the ability to get a slice of previously added remote candidates without keeping track of them in the application code. --- agent.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/agent.go b/agent.go index 91eb784..3f06857 100644 --- a/agent.go +++ b/agent.go @@ -838,6 +838,24 @@ func (a *Agent) addCandidate(ctx context.Context, c Candidate, candidateConn net }) } +// GetRemoteCandidates returns the remote candidates +func (a *Agent) GetRemoteCandidates() ([]Candidate, error) { + var res []Candidate + + err := a.run(a.context(), func(ctx context.Context, agent *Agent) { + var candidates []Candidate + for _, set := range agent.remoteCandidates { + candidates = append(candidates, set...) + } + res = candidates + }) + if err != nil { + return nil, err + } + + return res, nil +} + // GetLocalCandidates returns the local candidates func (a *Agent) GetLocalCandidates() ([]Candidate, error) { var res []Candidate