Skip to content

Commit

Permalink
Simplify copyCandidate
Browse files Browse the repository at this point in the history
We can use Marshal/Unmarshal now
  • Loading branch information
Sean-Der committed Oct 9, 2020
1 parent 5cc522b commit 9f7fab6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
8 changes: 4 additions & 4 deletions examples/ping-pong/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/pion/randutil"
)

//nolint
var (
isControlling bool
iceAgent *ice.Agent
Expand All @@ -29,7 +30,6 @@ func remoteAuth(w http.ResponseWriter, r *http.Request) {

remoteAuthChannel <- r.PostForm["ufrag"][0]
remoteAuthChannel <- r.PostForm["pwd"][0]

}

// HTTP Listener to get ICE Candidate from remote Peer
Expand All @@ -48,7 +48,7 @@ func remoteCandidate(w http.ResponseWriter, r *http.Request) {
}
}

func main() {
func main() { //nolint
var (
err error
conn *ice.Conn
Expand Down Expand Up @@ -97,7 +97,7 @@ func main() {
return
}

_, err = http.PostForm(fmt.Sprintf("http://localhost:%d/remoteCandidate", remoteHTTPPort),
_, err = http.PostForm(fmt.Sprintf("http://localhost:%d/remoteCandidate", remoteHTTPPort), //nolint
url.Values{
"candidate": {c.Marshal()},
})
Expand All @@ -121,7 +121,7 @@ func main() {
panic(err)
}

_, err = http.PostForm(fmt.Sprintf("http://localhost:%d/remoteAuth", remoteHTTPPort),
_, err = http.PostForm(fmt.Sprintf("http://localhost:%d/remoteAuth", remoteHTTPPort), //nolint
url.Values{
"ufrag": {localUfrag},
"pwd": {localPwd},
Expand Down
39 changes: 1 addition & 38 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,44 +304,7 @@ func pipeWithTimeout(disconnectTimeout time.Duration, iceKeepalive time.Duration
}

func copyCandidate(o Candidate) (c Candidate) {
candidateID := o.ID()
var err error
switch orig := o.(type) {
case *CandidateHost:
config := CandidateHostConfig{
CandidateID: candidateID,
Network: udp,
Address: orig.address,
Port: orig.port,
Component: orig.component,
}
c, err = NewCandidateHost(&config)
case *CandidateServerReflexive:
config := CandidateServerReflexiveConfig{
CandidateID: candidateID,
Network: udp,
Address: orig.address,
Port: orig.port,
Component: orig.component,
RelAddr: orig.relatedAddress.Address,
RelPort: orig.relatedAddress.Port,
}
c, err = NewCandidateServerReflexive(&config)
case *CandidateRelay:
config := CandidateRelayConfig{
CandidateID: candidateID,
Network: udp,
Address: orig.address,
Port: orig.port,
Component: orig.component,
RelAddr: orig.relatedAddress.Address,
RelPort: orig.relatedAddress.Port,
}
c, err = NewCandidateRelay(&config)
default:
panic("Tried to copy unsupported candidate type")
}

c, err := UnmarshalCandidate(o.Marshal())
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 9f7fab6

Please sign in to comment.