Skip to content

Commit

Permalink
Chore: fix varnamelen issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeTurki committed Jan 3, 2025
1 parent 075cd1b commit 875f2bb
Show file tree
Hide file tree
Showing 68 changed files with 1,034 additions and 1,033 deletions.
24 changes: 12 additions & 12 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,38 @@ type API struct {
// It uses the default Codecs and Interceptors unless you customize them
// using WithMediaEngine and WithInterceptorRegistry respectively.
func NewAPI(options ...func(*API)) *API {
a := &API{
api := &API{
interceptor: &interceptor.NoOp{},
settingEngine: &SettingEngine{},
}

for _, o := range options {
o(a)
o(api)
}

if a.settingEngine.LoggerFactory == nil {
a.settingEngine.LoggerFactory = logging.NewDefaultLoggerFactory()
if api.settingEngine.LoggerFactory == nil {
api.settingEngine.LoggerFactory = logging.NewDefaultLoggerFactory()
}

logger := a.settingEngine.LoggerFactory.NewLogger("api")
logger := api.settingEngine.LoggerFactory.NewLogger("api")

if a.mediaEngine == nil {
a.mediaEngine = &MediaEngine{}
err := a.mediaEngine.RegisterDefaultCodecs()
if api.mediaEngine == nil {
api.mediaEngine = &MediaEngine{}
err := api.mediaEngine.RegisterDefaultCodecs()
if err != nil {
logger.Errorf("Failed to register default codecs %s", err)
}
}

if a.interceptorRegistry == nil {
a.interceptorRegistry = &interceptor.Registry{}
err := RegisterDefaultInterceptors(a.mediaEngine, a.interceptorRegistry)
if api.interceptorRegistry == nil {
api.interceptorRegistry = &interceptor.Registry{}
err := RegisterDefaultInterceptors(api.mediaEngine, api.interceptorRegistry)
if err != nil {
logger.Errorf("Failed to register default interceptors %s", err)
}
}

return a
return api
}

// WithMediaEngine allows providing a MediaEngine to the API.
Expand Down
18 changes: 9 additions & 9 deletions certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ func NewCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*Certificate,

// Equals determines if two certificates are identical by comparing both the
// secretKeys and x509Certificates.
func (c Certificate) Equals(o Certificate) bool {
func (c Certificate) Equals(cert Certificate) bool {
switch cSK := c.privateKey.(type) {
case *rsa.PrivateKey:
if oSK, ok := o.privateKey.(*rsa.PrivateKey); ok {
if oSK, ok := cert.privateKey.(*rsa.PrivateKey); ok {
if cSK.N.Cmp(oSK.N) != 0 {
return false
}
return c.x509Cert.Equal(o.x509Cert)
return c.x509Cert.Equal(cert.x509Cert)
}
return false
case *ecdsa.PrivateKey:
if oSK, ok := o.privateKey.(*ecdsa.PrivateKey); ok {
if oSK, ok := cert.privateKey.(*ecdsa.PrivateKey); ok {
if cSK.X.Cmp(oSK.X) != 0 || cSK.Y.Cmp(oSK.Y) != 0 {
return false
}
return c.x509Cert.Equal(o.x509Cert)
return c.x509Cert.Equal(cert.x509Cert)
}
return false
default:
Expand Down Expand Up @@ -213,11 +213,11 @@ func CertificateFromPEM(pems string) (*Certificate, error) {
// certificate and the other for the private key
func (c Certificate) PEM() (string, error) {
// First write the X509 certificate
var o strings.Builder
var builder strings.Builder
xcertBytes := make(
[]byte, base64.StdEncoding.EncodedLen(len(c.x509Cert.Raw)))
base64.StdEncoding.Encode(xcertBytes, c.x509Cert.Raw)
err := pem.Encode(&o, &pem.Block{Type: "CERTIFICATE", Bytes: xcertBytes})
err := pem.Encode(&builder, &pem.Block{Type: "CERTIFICATE", Bytes: xcertBytes})
if err != nil {
return "", fmt.Errorf("failed to pem encode the X certificate: %w", err)
}
Expand All @@ -226,9 +226,9 @@ func (c Certificate) PEM() (string, error) {
if err != nil {
return "", fmt.Errorf("failed to marshal private key: %w", err)
}
err = pem.Encode(&o, &pem.Block{Type: "PRIVATE KEY", Bytes: privBytes})
err = pem.Encode(&builder, &pem.Block{Type: "PRIVATE KEY", Bytes: privBytes})
if err != nil {
return "", fmt.Errorf("failed to encode private key: %w", err)
}
return o.String(), nil
return builder.String(), nil
}
4 changes: 2 additions & 2 deletions configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestConfiguration_getICEServers(t *testing.T) {
}

func TestConfigurationJSON(t *testing.T) {
j := `{
config := `{
"iceServers": [{"urls": ["turn:turn.example.org"],
"username": "jch",
"credential": "topsecret"
Expand All @@ -67,7 +67,7 @@ func TestConfigurationJSON(t *testing.T) {
}

var conf2 Configuration
assert.NoError(t, json.Unmarshal([]byte(j), &conf2))
assert.NoError(t, json.Unmarshal([]byte(config), &conf2))
assert.Equal(t, conf, conf2)

j2, err := json.Marshal(conf2)
Expand Down
12 changes: 6 additions & 6 deletions datachannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (api *API) newDataChannel(params *DataChannelParameters, sctpTransport *SCT
return nil, &rtcerr.TypeError{Err: ErrStringSizeLimit}
}

d := &DataChannel{
dataChannel := &DataChannel{
sctpTransport: sctpTransport,
statsID: fmt.Sprintf("DataChannel-%d", time.Now().UnixNano()),
label: params.Label,
Expand All @@ -107,8 +107,8 @@ func (api *API) newDataChannel(params *DataChannelParameters, sctpTransport *SCT
log: log,
}

d.setReadyState(DataChannelStateConnecting)
return d, nil
dataChannel.setReadyState(DataChannelStateConnecting)
return dataChannel, nil
}

// open opens the datachannel over the sctp transport
Expand Down Expand Up @@ -399,11 +399,11 @@ func (d *DataChannel) readLoop() {
return
}

m := DataChannelMessage{Data: make([]byte, n), IsString: isString}
copy(m.Data, buffer[:n])
msg := DataChannelMessage{Data: make([]byte, n), IsString: isString}
copy(msg.Data, buffer[:n])

// NB: Why was DataChannelMessage not passed as a pointer value?
d.onMessage(m) // nolint:staticcheck
d.onMessage(msg) // nolint:staticcheck
}
}

Expand Down
8 changes: 4 additions & 4 deletions datachannel_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,14 @@ func TestDataChannelBufferedAmount(t *testing.T) {

done := make(chan bool)

answerPC.OnDataChannel(func(d *DataChannel) {
answerPC.OnDataChannel(func(dataChannel *DataChannel) {
// Make sure this is the data channel we were looking for. (Not the one
// created in signalPair).
if d.Label() != expectedLabel {
if dataChannel.Label() != expectedLabel {
return
}
var nPacketsReceived int
d.OnMessage(func(DataChannelMessage) {
dataChannel.OnMessage(func(DataChannelMessage) {
nPacketsReceived++

if nPacketsReceived == 10 {
Expand All @@ -318,7 +318,7 @@ func TestDataChannelBufferedAmount(t *testing.T) {
}()
}
})
assert.True(t, d.Ordered(), "Ordered should be set to true")
assert.True(t, dataChannel.Ordered(), "Ordered should be set to true")
})

dc, err := offerPC.CreateDataChannel(expectedLabel, nil)
Expand Down
8 changes: 4 additions & 4 deletions dtlstransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type simulcastStreamPair struct {
// This constructor is part of the ORTC API. It is not
// meant to be used together with the basic WebRTC API.
func (api *API) NewDTLSTransport(transport *ICETransport, certificates []Certificate) (*DTLSTransport, error) {
t := &DTLSTransport{
trans := &DTLSTransport{
iceTransport: transport,
api: api,
state: DTLSTransportStateNew,
Expand All @@ -84,7 +84,7 @@ func (api *API) NewDTLSTransport(transport *ICETransport, certificates []Certifi
if !x509Cert.Expires().IsZero() && now.After(x509Cert.Expires()) {
return nil, &rtcerr.InvalidAccessError{Err: ErrCertificateExpired}
}
t.certificates = append(t.certificates, x509Cert)
trans.certificates = append(trans.certificates, x509Cert)
}
} else {
sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
Expand All @@ -95,10 +95,10 @@ func (api *API) NewDTLSTransport(transport *ICETransport, certificates []Certifi
if err != nil {
return nil, err
}
t.certificates = []Certificate{*certificate}
trans.certificates = []Certificate{*certificate}
}

return t, nil
return trans, nil
}

// ICETransport returns the currently-configured *ICETransport or nil
Expand Down
18 changes: 9 additions & 9 deletions examples/bandwidth-estimation-from-disk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func main() {
}
}

i := &interceptor.Registry{}
m := &webrtc.MediaEngine{}
if err := m.RegisterDefaultCodecs(); err != nil {
interceptorRegistry := &interceptor.Registry{}
mediaEngine := &webrtc.MediaEngine{}
if err := mediaEngine.RegisterDefaultCodecs(); err != nil {
panic(err)
}

Expand All @@ -81,17 +81,17 @@ func main() {
estimatorChan <- estimator
})

i.Add(congestionController)
if err = webrtc.ConfigureTWCCHeaderExtensionSender(m, i); err != nil {
interceptorRegistry.Add(congestionController)
if err = webrtc.ConfigureTWCCHeaderExtensionSender(mediaEngine, interceptorRegistry); err != nil {
panic(err)
}

if err = webrtc.RegisterDefaultInterceptors(m, i); err != nil {
if err = webrtc.RegisterDefaultInterceptors(mediaEngine, interceptorRegistry); err != nil {
panic(err)
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.NewAPI(webrtc.WithInterceptorRegistry(i), webrtc.WithMediaEngine(m)).NewPeerConnection(webrtc.Configuration{
peerConnection, err := webrtc.NewAPI(webrtc.WithInterceptorRegistry(interceptorRegistry), webrtc.WithMediaEngine(mediaEngine)).NewPeerConnection(webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:stun.l.google.com:19302"},
Expand Down Expand Up @@ -141,8 +141,8 @@ func main() {

// Set the handler for Peer connection state
// This will notify you when the peer has connected/disconnected
peerConnection.OnConnectionStateChange(func(s webrtc.PeerConnectionState) {
fmt.Printf("Peer Connection State has changed: %s\n", s.String())
peerConnection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
fmt.Printf("Peer Connection State has changed: %s\n", state.String())
})

// Wait for the offer to be pasted
Expand Down
18 changes: 9 additions & 9 deletions examples/broadcast/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ func main() {
},
}

m := &webrtc.MediaEngine{}
if err := m.RegisterDefaultCodecs(); err != nil {
mediaEngine := &webrtc.MediaEngine{}
if err := mediaEngine.RegisterDefaultCodecs(); err != nil {
panic(err)
}

// Create a InterceptorRegistry. This is the user configurable RTP/RTCP Pipeline.
// This provides NACKs, RTCP Reports and other features. If you use `webrtc.NewPeerConnection`
// this is enabled by default. If you are manually managing You MUST create a InterceptorRegistry
// for each PeerConnection.
i := &interceptor.Registry{}
interceptorRegistry := &interceptor.Registry{}

// Use the default set of Interceptors
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
if err := webrtc.RegisterDefaultInterceptors(mediaEngine, interceptorRegistry); err != nil {
panic(err)
}

Expand All @@ -66,10 +66,10 @@ func main() {
if err != nil {
panic(err)
}
i.Add(intervalPliFactory)
interceptorRegistry.Add(intervalPliFactory)

// Create a new RTCPeerConnection
peerConnection, err := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithInterceptorRegistry(i)).NewPeerConnection(peerConnectionConfig)
peerConnection, err := webrtc.NewAPI(webrtc.WithMediaEngine(mediaEngine), webrtc.WithInterceptorRegistry(interceptorRegistry)).NewPeerConnection(peerConnectionConfig)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -225,9 +225,9 @@ func decode(in string, obj *webrtc.SessionDescription) {
// httpSDPServer starts a HTTP Server that consumes SDPs
func httpSDPServer(port int) chan string {
sdpChan := make(chan string)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
fmt.Fprintf(w, "done") //nolint: errcheck
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
body, _ := io.ReadAll(req.Body)
fmt.Fprintf(res, "done") //nolint: errcheck
sdpChan <- string(body)
})

Expand Down
26 changes: 13 additions & 13 deletions examples/custom-logger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ func main() {

// Set the handler for Peer connection state
// This will notify you when the peer has connected/disconnected
offerPeerConnection.OnConnectionStateChange(func(s webrtc.PeerConnectionState) {
fmt.Printf("Peer Connection State has changed: %s (offerer)\n", s.String())
offerPeerConnection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
fmt.Printf("Peer Connection State has changed: %s (offerer)\n", state.String())

if s == webrtc.PeerConnectionStateFailed {
if state == webrtc.PeerConnectionStateFailed {
// Wait until PeerConnection has had no network activity for 30 seconds or another failure. It may be reconnected using an ICE Restart.
// Use webrtc.PeerConnectionStateDisconnected if you are interested in detecting faster timeout.
// Note that the PeerConnection may come back from PeerConnectionStateDisconnected.
fmt.Println("Peer Connection has gone to failed exiting")
os.Exit(0)
}

if s == webrtc.PeerConnectionStateClosed {
if state == webrtc.PeerConnectionStateClosed {
// PeerConnection was explicitly closed. This usually happens from a DTLS CloseNotify
fmt.Println("Peer Connection has gone to closed exiting")
os.Exit(0)
Expand All @@ -111,10 +111,10 @@ func main() {

// Set the handler for Peer connection state
// This will notify you when the peer has connected/disconnected
answerPeerConnection.OnConnectionStateChange(func(s webrtc.PeerConnectionState) {
fmt.Printf("Peer Connection State has changed: %s (answerer)\n", s.String())
answerPeerConnection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
fmt.Printf("Peer Connection State has changed: %s (answerer)\n", state.String())

if s == webrtc.PeerConnectionStateFailed {
if state == webrtc.PeerConnectionStateFailed {
// Wait until PeerConnection has had no network activity for 30 seconds or another failure. It may be reconnected using an ICE Restart.
// Use webrtc.PeerConnectionStateDisconnected if you are interested in detecting faster timeout.
// Note that the PeerConnection may come back from PeerConnectionStateDisconnected.
Expand All @@ -125,19 +125,19 @@ func main() {

// Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate
// send it to the other peer
answerPeerConnection.OnICECandidate(func(i *webrtc.ICECandidate) {
if i != nil {
if iceErr := offerPeerConnection.AddICECandidate(i.ToJSON()); iceErr != nil {
answerPeerConnection.OnICECandidate(func(candidate *webrtc.ICECandidate) {
if candidate != nil {
if iceErr := offerPeerConnection.AddICECandidate(candidate.ToJSON()); iceErr != nil {
panic(iceErr)
}
}
})

// Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate
// send it to the other peer
offerPeerConnection.OnICECandidate(func(i *webrtc.ICECandidate) {
if i != nil {
if iceErr := answerPeerConnection.AddICECandidate(i.ToJSON()); iceErr != nil {
offerPeerConnection.OnICECandidate(func(candidate *webrtc.ICECandidate) {
if candidate != nil {
if iceErr := answerPeerConnection.AddICECandidate(candidate.ToJSON()); iceErr != nil {
panic(iceErr)
}
}
Expand Down
Loading

0 comments on commit 875f2bb

Please sign in to comment.