diff --git a/api/bandwidth.go b/api/bandwidth.go index 683dbac..ad5b3d9 100644 --- a/api/bandwidth.go +++ b/api/bandwidth.go @@ -50,13 +50,14 @@ func formatWithRemainder(value uint64, divisor uint64, format string) string { // String returns the formatted bandwidth. func (b Bandwidth) String() string { - if b >= Gigabit { + switch { + case b >= Gigabit: return formatWithRemainder(b.Bits(), Gigabit.Bits(), "Gbps") - } else if b >= Megabit { + case b >= Megabit: return formatWithRemainder(b.Bits(), Megabit.Bits(), "Mbps") - } else if b >= Kilobit { + case b >= Kilobit: return formatWithRemainder(b.Bits(), Kilobit.Bits(), "Kbps") - } else { + default: return fmt.Sprintf("%d bps", b) } } diff --git a/api_proxy.go b/api_proxy.go index 1c332a5..7761f6d 100644 --- a/api_proxy.go +++ b/api_proxy.go @@ -329,13 +329,14 @@ type EventProxyServerBandwidth struct { } func (b *EventProxyServerBandwidth) String() string { - if b.Incoming != nil && b.Outgoing != nil { + switch { + case b.Incoming != nil && b.Outgoing != nil: return fmt.Sprintf("bandwidth: incoming=%.3f%%, outgoing=%.3f%%", *b.Incoming, *b.Outgoing) - } else if b.Incoming != nil { + case b.Incoming != nil: return fmt.Sprintf("bandwidth: incoming=%.3f%%, outgoing=unlimited", *b.Incoming) - } else if b.Outgoing != nil { + case b.Outgoing != nil: return fmt.Sprintf("bandwidth: incoming=unlimited, outgoing=%.3f%%", *b.Outgoing) - } else { + default: return "bandwidth: incoming=unlimited, outgoing=unlimited" } } diff --git a/clientsession.go b/clientsession.go index ee0fbd2..6ff26a3 100644 --- a/clientsession.go +++ b/clientsession.go @@ -835,22 +835,23 @@ func (s *ClientSession) IsAllowedToSend(data *MessageClientMessageData) error { s.mu.Lock() defer s.mu.Unlock() - if data != nil && data.RoomType == "screen" { + switch { + case data != nil && data.RoomType == "screen": if s.hasPermissionLocked(PERMISSION_MAY_PUBLISH_SCREEN) { return nil } return &PermissionError{PERMISSION_MAY_PUBLISH_SCREEN} - } else if s.hasPermissionLocked(PERMISSION_MAY_PUBLISH_MEDIA) { + case s.hasPermissionLocked(PERMISSION_MAY_PUBLISH_MEDIA): // Client is allowed to publish any media (audio / video). return nil - } else if data != nil && data.Type == "offer" { + case data != nil && data.Type == "offer": // Check what user is trying to publish and check permissions accordingly. if _, err := s.isSdpAllowedToSendLocked(data.offerSdp); err != nil { return err } return nil - } else { + default: // Candidate or unknown event, check if client is allowed to publish any media. if s.hasAnyPermissionLocked(PERMISSION_MAY_PUBLISH_AUDIO, PERMISSION_MAY_PUBLISH_VIDEO) { return nil diff --git a/mcu_janus_publisher.go b/mcu_janus_publisher.go index 225365b..7d907fd 100644 --- a/mcu_janus_publisher.go +++ b/mcu_janus_publisher.go @@ -319,7 +319,8 @@ func (p *mcuJanusPublisher) GetStreams(ctx context.Context) ([]PublisherStream, continue } - if strings.EqualFold(s.Type, "audio") { + switch { + case strings.EqualFold(s.Type, "audio"): s.Codec = answerCodec.Name if value, found := getFmtpValue(answerCodec.Fmtp, "useinbandfec"); found && value == "1" { s.Fec = true @@ -330,7 +331,7 @@ func (p *mcuJanusPublisher) GetStreams(ctx context.Context) ([]PublisherStream, if value, found := getFmtpValue(answerCodec.Fmtp, "stereo"); found && value == "1" { s.Stereo = true } - } else if strings.EqualFold(s.Type, "video") { + case strings.EqualFold(s.Type, "video"): s.Codec = answerCodec.Name // TODO: Determine if SVC is used. s.Svc = false @@ -384,9 +385,9 @@ func (p *mcuJanusPublisher) GetStreams(ctx context.Context) ([]PublisherStream, } } - } else if strings.EqualFold(s.Type, "data") { // nolint + case strings.EqualFold(s.Type, "data"): // Already handled above. - } else { + default: p.logger.Printf("Skip type %s", s.Type) continue } diff --git a/mcu_proxy.go b/mcu_proxy.go index 37ee0ff..c70c2a8 100644 --- a/mcu_proxy.go +++ b/mcu_proxy.go @@ -2086,18 +2086,20 @@ func (m *mcuProxy) NewPublisher(ctx context.Context, listener McuListener, id Pu incoming_b = bw.Incoming } - if incoming_a == nil && incoming_b == nil { + switch { + case incoming_a == nil && incoming_b == nil: return 0 - } else if incoming_a == nil && incoming_b != nil { + case incoming_a == nil && incoming_b != nil: return -1 - } else if incoming_a != nil && incoming_b == nil { + case incoming_a != nil && incoming_b == nil: return -1 - } else if *incoming_a < *incoming_b { + case *incoming_a < *incoming_b: return -1 - } else if *incoming_a > *incoming_b { + case *incoming_a > *incoming_b: return 1 + default: + return 0 } - return 0 }) publisher = m.createPublisher(ctx, listener, id, sid, streamType, settings, initiator, connections2, func(c *mcuProxyConnection) bool { return true @@ -2349,18 +2351,20 @@ func (m *mcuProxy) NewSubscriber(ctx context.Context, listener McuListener, publ outgoing_b = bw.Outgoing } - if outgoing_a == nil && outgoing_b == nil { + switch { + case outgoing_a == nil && outgoing_b == nil: return 0 - } else if outgoing_a == nil && outgoing_b != nil { + case outgoing_a == nil && outgoing_b != nil: return -1 - } else if outgoing_a != nil && outgoing_b == nil { + case outgoing_a != nil && outgoing_b == nil: return -1 - } else if *outgoing_a < *outgoing_b { + case *outgoing_a < *outgoing_b: return -1 - } else if *outgoing_a > *outgoing_b { + case *outgoing_a > *outgoing_b: return 1 + default: + return 0 } - return 0 }) subscriber = m.createSubscriber(ctx, listener, publisherInfo, publisher, streamType, connections2, func(c *mcuProxyConnection) bool { return true