Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make DLNA port configurable #4836

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions graphql/schema/types/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ input ConfigDLNAInput {
serverName: String
"True if DLNA service should be enabled by default"
enabled: Boolean
"Defaults to 1338"
port: Int
"List of IPs whitelisted for DLNA service"
whitelistedIPs: [String!]
"List of interfaces to run DLNA on. Empty for all"
Expand All @@ -481,6 +483,8 @@ type ConfigDLNAResult {
serverName: String!
"True if DLNA service should be enabled by default"
enabled: Boolean!
"Defaults to 1338"
port: Int!
"List of IPs whitelisted for DLNA service"
whitelistedIPs: [String!]!
"List of interfaces to run DLNA on. Empty for all"
Expand Down
4 changes: 4 additions & 0 deletions internal/api/resolver_mutation_configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ func (r *mutationResolver) ConfigureDlna(ctx context.Context, input ConfigDLNAIn
c.Set(config.DLNAVideoSortOrder, input.VideoSortOrder)
}

if input.Port != nil {
c.Set(config.DLNAPort, *input.Port)
}

refresh := false
if input.Enabled != nil {
c.Set(config.DLNADefaultEnabled, *input.Enabled)
Expand Down
1 change: 1 addition & 0 deletions internal/api/resolver_query_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func makeConfigDLNAResult() *ConfigDLNAResult {
return &ConfigDLNAResult{
ServerName: config.GetDLNAServerName(),
Enabled: config.GetDLNADefaultEnabled(),
Port: config.GetDLNAPort(),
WhitelistedIPs: config.GetDLNADefaultIPWhitelist(),
Interfaces: config.GetDLNAInterfaces(),
VideoSortOrder: config.GetVideoSortOrder(),
Expand Down
5 changes: 3 additions & 2 deletions internal/dlna/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type Config interface {
GetDLNAServerName() string
GetDLNADefaultIPWhitelist() []string
GetVideoSortOrder() string
GetDLNAPortAsString() string
}

type Service struct {
Expand Down Expand Up @@ -138,7 +139,7 @@ func (s *Service) init() error {
var dmsConfig = &dmsConfig{
Path: "",
IfNames: s.config.GetDLNADefaultIPWhitelist(),
Http: ":1338",
Http: s.config.GetDLNAPortAsString(),
FriendlyName: friendlyName,
LogHeaders: false,
NotifyInterval: 30 * time.Second,
Expand Down Expand Up @@ -241,7 +242,7 @@ func (s *Service) Start(duration *time.Duration) error {
}

go func() {
logger.Info("Starting DLNA")
logger.Info("Starting DLNA " + s.server.HTTPConn.Addr().String())
if err := s.server.Serve(); err != nil {
logger.Error(err)
}
Expand Down
19 changes: 19 additions & 0 deletions internal/manager/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"

"sync"
Expand Down Expand Up @@ -237,6 +238,9 @@ const (
DLNAVideoSortOrder = "dlna.video_sort_order"
dlnaVideoSortOrderDefault = "title"

DLNAPort = "dlna.port"
DLNAPortDefault = 1338

// Logging options
LogFile = "logFile"
LogOut = "logOut"
Expand Down Expand Up @@ -1477,6 +1481,21 @@ func (i *Config) GetDLNAInterfaces() []string {
return i.getStringSlice(DLNAInterfaces)
}

// GetDLNAPort returns the port to run the DLNA server on. If empty, 1338
// will be used.
func (i *Config) GetDLNAPort() int {
ret := i.getInt(DLNAPort)
if ret == 0 {
ret = DLNAPortDefault
}
return ret
}

// GetDLNAPortAsString returns the port to run the DLNA server on as a string.
func (i *Config) GetDLNAPortAsString() string {
return ":" + strconv.Itoa(i.GetDLNAPort())
}

// GetVideoSortOrder returns the sort order to display videos. If
// empty, videos will be sorted by titles.
func (i *Config) GetVideoSortOrder() string {
Expand Down
1 change: 1 addition & 0 deletions internal/manager/config/config_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestConcurrentConfigAccess(t *testing.T) {
i.Set(DLNADefaultEnabled, i.GetDLNADefaultEnabled())
i.Set(DLNADefaultIPWhitelist, i.GetDLNADefaultIPWhitelist())
i.Set(DLNAInterfaces, i.GetDLNAInterfaces())
i.Set(DLNAPort, i.GetDLNAPort())
i.Set(LogFile, i.GetLogFile())
i.Set(LogOut, i.GetLogOut())
i.Set(LogLevel, i.GetLogLevel())
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/graphql/data/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ fragment ConfigInterfaceData on ConfigInterfaceResult {
fragment ConfigDLNAData on ConfigDLNAResult {
serverName
enabled
port
whitelistedIPs
interfaces
videoSortOrder
Expand Down
12 changes: 12 additions & 0 deletions ui/v2.5/src/components/Settings/SettingsServicesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
StringListSetting,
StringSetting,
SelectSetting,
NumberSetting,
} from "./Inputs";
import { useSettings } from "./context";
import {
Expand All @@ -31,6 +32,8 @@ import {
faUserClock,
} from "@fortawesome/free-solid-svg-icons";

const defaultDLNAPort = 1338;

export const SettingsServicesPanel: React.FC = () => {
const intl = useIntl();
const Toast = useToast();
Expand Down Expand Up @@ -417,6 +420,15 @@ export const SettingsServicesPanel: React.FC = () => {
onChange={(v) => saveDLNA({ serverName: v })}
/>

<NumberSetting
headingID="config.dlna.server_port"
subHeading={intl.formatMessage({
id: "config.dlna.server_port_desc",
})}
value={dlna.port ?? undefined}
onChange={(v) => saveDLNA({ port: v ? v : defaultDLNAPort })}
/>

<BooleanSetting
id="dlna-enabled-by-default"
headingID="config.dlna.enabled_by_default"
Expand Down
2 changes: 2 additions & 0 deletions ui/v2.5/src/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@
"recent_ip_addresses": "Recent IP addresses",
"server_display_name": "Server Display Name",
"server_display_name_desc": "Display name for the DLNA server. Defaults to {server_name} if empty.",
"server_port": "Server Port",
"server_port_desc": "Port to run the DLNA server on. Requires DLNA restart after changing.",
"successfully_cancelled_temporary_behaviour": "Successfully cancelled temporary behaviour",
"until_restart": "until restart",
"video_sort_order": "Default Video Sort Order",
Expand Down
Loading