enable legacy supprot if at least one legacy config entry is found.

This commit is contained in:
Miroslav Šedivý 2025-02-20 20:10:07 +01:00
parent 3ac462e197
commit 4eadf996ed
12 changed files with 152 additions and 8 deletions

View file

@ -81,6 +81,11 @@ func init() {
// set root config values
rootConfig.Set()
// legacy if explicitly enabled or if unspecified and legacy config is found
if viper.GetBool("legacy") || !viper.IsSet("legacy") {
rootConfig.SetV2()
}
//////
// logs
//////
@ -161,5 +166,12 @@ func init() {
log.Panic().Err(err).Msg("unable to run root command")
}
// legacy if explicitly enabled or if unspecified and legacy config is found
if viper.GetBool("legacy") || !viper.IsSet("legacy") {
if err := rootConfig.InitV2(root); err != nil {
log.Panic().Err(err).Msg("unable to run root command")
}
}
root.SetVersionTemplate(neko.Version.Details())
}

View file

@ -88,8 +88,8 @@ func (c *serve) Init(cmd *cobra.Command) error {
return err
}
// V2 configuration
if viper.GetBool("legacy") {
// legacy if explicitly enabled or if unspecified and legacy config is found
if viper.GetBool("legacy") || !viper.IsSet("legacy") {
if err := c.configs.Desktop.InitV2(cmd); err != nil {
return err
}
@ -124,7 +124,8 @@ func (c *serve) PreRun(cmd *cobra.Command, args []string) {
c.configs.Plugins.Set()
c.configs.Server.Set()
if viper.GetBool("legacy") {
// legacy if explicitly enabled or if unspecified and legacy config is found
if viper.GetBool("legacy") || !viper.IsSet("legacy") {
c.configs.Desktop.SetV2()
c.configs.Capture.SetV2()
c.configs.WebRTC.SetV2()

View file

@ -437,6 +437,8 @@ func (s *Capture) Set() {
}
func (s *Capture) SetV2() {
enableLegacy := false
var ok bool
//
@ -446,6 +448,7 @@ func (s *Capture) SetV2() {
if display := viper.GetString("display"); display != "" {
s.Display = display
log.Warn().Msg("you are using v2 configuration 'NEKO_DISPLAY' which is deprecated, please use 'NEKO_CAPTURE_VIDEO_DISPLAY' and/or 'NEKO_DESKTOP_DISPLAY' instead, also consider using 'DISPLAY' env variable if both should be the same")
enableLegacy = true
}
if videoCodec := viper.GetString("video_codec"); videoCodec != "" {
@ -455,20 +458,25 @@ func (s *Capture) SetV2() {
s.VideoCodec = codec.VP8()
}
log.Warn().Msg("you are using v2 configuration 'NEKO_VIDEO_CODEC' which is deprecated, please use 'NEKO_CAPTURE_VIDEO_CODEC' instead")
enableLegacy = true
}
if viper.GetBool("vp8") {
s.VideoCodec = codec.VP8()
log.Warn().Msg("you are using deprecated config setting 'NEKO_VP8=true', use 'NEKO_CAPTURE_VIDEO_CODEC=vp8' instead")
enableLegacy = true
} else if viper.GetBool("vp9") {
s.VideoCodec = codec.VP9()
log.Warn().Msg("you are using deprecated config setting 'NEKO_VP9=true', use 'NEKO_CAPTURE_VIDEO_CODEC=vp9' instead")
enableLegacy = true
} else if viper.GetBool("h264") {
s.VideoCodec = codec.H264()
log.Warn().Msg("you are using deprecated config setting 'NEKO_H264=true', use 'NEKO_CAPTURE_VIDEO_CODEC=h264' instead")
enableLegacy = true
} else if viper.GetBool("av1") {
s.VideoCodec = codec.AV1()
log.Warn().Msg("you are using deprecated config setting 'NEKO_AV1=true', use 'NEKO_CAPTURE_VIDEO_CODEC=av1' instead")
enableLegacy = true
}
videoHWEnc := HwEncUnset
@ -509,10 +517,11 @@ func (s *Capture) SetV2() {
}
if videoPipeline != "" {
log.Warn().Msg("you are using deprecated config setting 'NEKO_VIDEO' which is deprecated, please use 'NEKO_CAPTURE_VIDEO_PIPELINE' instead")
log.Warn().Msg("you are using v2 configuration 'NEKO_VIDEO' which is deprecated, please use 'NEKO_CAPTURE_VIDEO_PIPELINE' instead")
}
// TODO: add deprecated warning and proper alternative for HW enc, bitrate and max fps
enableLegacy = true
}
//
@ -522,6 +531,7 @@ func (s *Capture) SetV2() {
if audioDevice := viper.GetString("device"); audioDevice != "" {
s.AudioDevice = audioDevice
log.Warn().Msg("you are using v2 configuration 'NEKO_DEVICE' which is deprecated, please use 'NEKO_CAPTURE_AUDIO_DEVICE' instead")
enableLegacy = true
}
if audioCodec := viper.GetString("audio_codec"); audioCodec != "" {
@ -531,20 +541,25 @@ func (s *Capture) SetV2() {
s.AudioCodec = codec.Opus()
}
log.Warn().Msg("you are using v2 configuration 'NEKO_AUDIO_CODEC' which is deprecated, please use 'NEKO_CAPTURE_AUDIO_CODEC' instead")
enableLegacy = true
}
if viper.GetBool("opus") {
s.AudioCodec = codec.Opus()
log.Warn().Msg("you are using deprecated config setting 'NEKO_OPUS=true', use 'NEKO_CAPTURE_AUDIO_CODEC=opus' instead")
enableLegacy = true
} else if viper.GetBool("g722") {
s.AudioCodec = codec.G722()
log.Warn().Msg("you are using deprecated config setting 'NEKO_G722=true', use 'NEKO_CAPTURE_AUDIO_CODEC=g722' instead")
enableLegacy = true
} else if viper.GetBool("pcmu") {
s.AudioCodec = codec.PCMU()
log.Warn().Msg("you are using deprecated config setting 'NEKO_PCMU=true', use 'NEKO_CAPTURE_AUDIO_CODEC=pcmu' instead")
enableLegacy = true
} else if viper.GetBool("pcma") {
s.AudioCodec = codec.PCMA()
log.Warn().Msg("you are using deprecated config setting 'NEKO_PCMA=true', use 'NEKO_CAPTURE_AUDIO_CODEC=pcma' instead")
enableLegacy = true
}
audioBitrate := viper.GetUint("audio_bitrate")
@ -560,10 +575,11 @@ func (s *Capture) SetV2() {
}
if audioPipeline != "" {
log.Warn().Msg("you are using deprecated config setting 'NEKO_AUDIO' which is deprecated, please use 'NEKO_CAPTURE_AUDIO_PIPELINE' instead")
log.Warn().Msg("you are using v2 configuration 'NEKO_AUDIO' which is deprecated, please use 'NEKO_CAPTURE_AUDIO_PIPELINE' instead")
}
// TODO: add deprecated warning and proper alternative for audio bitrate
enableLegacy = true
}
//
@ -573,13 +589,22 @@ func (s *Capture) SetV2() {
if viper.IsSet("broadcast_pipeline") {
s.BroadcastPipeline = viper.GetString("broadcast_pipeline")
log.Warn().Msg("you are using v2 configuration 'NEKO_BROADCAST_PIPELINE' which is deprecated, please use 'NEKO_CAPTURE_BROADCAST_PIPELINE' instead")
enableLegacy = true
}
if viper.IsSet("broadcast_url") {
s.BroadcastUrl = viper.GetString("broadcast_url")
log.Warn().Msg("you are using v2 configuration 'NEKO_BROADCAST_URL' which is deprecated, please use 'NEKO_CAPTURE_BROADCAST_URL' instead")
enableLegacy = true
}
if viper.IsSet("broadcast_autostart") {
s.BroadcastAutostart = viper.GetBool("broadcast_autostart")
log.Warn().Msg("you are using v2 configuration 'NEKO_BROADCAST_AUTOSTART' which is deprecated, please use 'NEKO_CAPTURE_BROADCAST_AUTOSTART' instead")
enableLegacy = true
}
// set legacy flag if any V2 configuration was used
if !viper.IsSet("legacy") && enableLegacy {
log.Warn().Msg("legacy configuration is enabled because at least one V2 configuration was used, please migrate to V3 configuration, or set 'NEKO_LEGACY=true' to acknowledge this message")
viper.Set("legacy", true)
}
}

View file

@ -110,6 +110,8 @@ func (s *Desktop) Set() {
}
func (s *Desktop) SetV2() {
enableLegacy := false
if viper.IsSet("screen") {
r := regexp.MustCompile(`([0-9]{1,4})x([0-9]{1,4})@([0-9]{1,3})`)
res := r.FindStringSubmatch(viper.GetString("screen"))
@ -126,5 +128,12 @@ func (s *Desktop) SetV2() {
}
}
log.Warn().Msg("you are using v2 configuration 'NEKO_SCREEN' which is deprecated, please use 'NEKO_DESKTOP_SCREEN' instead")
enableLegacy = true
}
// set legacy flag if any V2 configuration was used
if !viper.IsSet("legacy") && enableLegacy {
log.Warn().Msg("legacy configuration is enabled because at least one V2 configuration was used, please migrate to V3 configuration, or set 'NEKO_LEGACY=true' to acknowledge this message")
viper.Set("legacy", true)
}
}

View file

@ -142,6 +142,8 @@ func (s *Member) Set() {
}
func (s *Member) SetV2() {
enableLegacy := false
if viper.IsSet("password") || viper.IsSet("password_admin") {
s.Provider = "multiuser"
if userPassword := viper.GetString("password"); userPassword != "" {
@ -155,5 +157,12 @@ func (s *Member) SetV2() {
s.Multiuser.AdminPassword = "admin"
}
log.Warn().Msg("you are using v2 configuration 'NEKO_PASSWORD' and 'NEKO_PASSWORD_ADMIN' which are deprecated, please use 'NEKO_MEMBER_MULTIUSER_USER_PASSWORD' and 'NEKO_MEMBER_MULTIUSER_ADMIN_PASSWORD' with 'NEKO_MEMBER_PROVIDER=multiuser' instead")
enableLegacy = true
}
// set legacy flag if any V2 configuration was used
if !viper.IsSet("legacy") && enableLegacy {
log.Warn().Msg("legacy configuration is enabled because at least one V2 configuration was used, please migrate to V3 configuration, or set 'NEKO_LEGACY=true' to acknowledge this message")
viper.Set("legacy", true)
}
}

View file

@ -34,8 +34,10 @@ func (Root) Init(cmd *cobra.Command) error {
return err
}
// whether legacy configs/api should be enabled (default: true, until v3.1)
cmd.PersistentFlags().BoolP("legacy", "l", true, "enable legacy mode")
// whether legacy configs and api should be enabled.
// - if not specified, it will be automatically enabled if at least one legacy config entry is found.
// - if it is specified, it will be enabled/disabled regardless of the presence of legacy config entries.
cmd.PersistentFlags().Bool("legacy", true, "enable legacy mode")
if err := viper.BindPFlag("legacy", cmd.PersistentFlags().Lookup("legacy")); err != nil {
return err
}
@ -80,6 +82,9 @@ func (Root) InitV2(cmd *cobra.Command) error {
func (s *Root) Set() {
s.Config = viper.GetString("config")
s.Legacy = viper.GetBool("legacy")
if s.Legacy {
log.Info().Msg("legacy configuration is enabled")
}
logLevel := viper.GetString("log.level")
level, err := zerolog.ParseLevel(logLevel)
@ -116,6 +121,8 @@ func (s *Root) Set() {
}
func (s *Root) SetV2() {
enableLegacy := false
if viper.IsSet("logs") {
if viper.GetBool("logs") {
logs := filepath.Join(".", "logs")
@ -127,5 +134,12 @@ func (s *Root) SetV2() {
s.LogDir = ""
}
log.Warn().Msg("you are using v2 configuration 'NEKO_LOGS' which is deprecated, please use 'NEKO_LOG_DIR=/path/to/logs' instead")
enableLegacy = true
}
// set legacy flag if any V2 configuration was used
if !viper.IsSet("legacy") && enableLegacy {
log.Warn().Msg("legacy configuration is enabled because at least one V2 configuration was used, please migrate to V3 configuration, or set 'NEKO_LEGACY=true' to acknowledge this message")
viper.Set("legacy", true)
}
}

View file

@ -128,29 +128,37 @@ func (s *Server) Set() {
}
func (s *Server) SetV2() {
enableLegacy := false
if viper.IsSet("cert") {
s.Cert = viper.GetString("cert")
log.Warn().Msg("you are using v2 configuration 'NEKO_CERT' which is deprecated, please use 'NEKO_SERVER_CERT' instead")
enableLegacy = true
}
if viper.IsSet("key") {
s.Key = viper.GetString("key")
log.Warn().Msg("you are using v2 configuration 'NEKO_KEY' which is deprecated, please use 'NEKO_SERVER_KEY' instead")
enableLegacy = true
}
if viper.IsSet("bind") {
s.Bind = viper.GetString("bind")
log.Warn().Msg("you are using v2 configuration 'NEKO_BIND' which is deprecated, please use 'NEKO_SERVER_BIND' instead")
enableLegacy = true
}
if viper.IsSet("proxy") {
s.Proxy = viper.GetBool("proxy")
log.Warn().Msg("you are using v2 configuration 'NEKO_PROXY' which is deprecated, please use 'NEKO_SERVER_PROXY' instead")
enableLegacy = true
}
if viper.IsSet("static") {
s.Static = viper.GetString("static")
log.Warn().Msg("you are using v2 configuration 'NEKO_STATIC' which is deprecated, please use 'NEKO_SERVER_STATIC' instead")
enableLegacy = true
}
if viper.IsSet("path_prefix") {
s.PathPrefix = path.Join("/", path.Clean(viper.GetString("path_prefix")))
log.Warn().Msg("you are using v2 configuration 'NEKO_PATH_PREFIX' which is deprecated, please use 'NEKO_SERVER_PATH_PREFIX' instead")
enableLegacy = true
}
if viper.IsSet("cors") {
s.CORS = viper.GetStringSlice("cors")
@ -159,6 +167,13 @@ func (s *Server) SetV2() {
s.CORS = []string{"*"}
}
log.Warn().Msg("you are using v2 configuration 'NEKO_CORS' which is deprecated, please use 'NEKO_SERVER_CORS' instead")
enableLegacy = true
}
// set legacy flag if any V2 configuration was used
if !viper.IsSet("legacy") && enableLegacy {
log.Warn().Msg("legacy configuration is enabled because at least one V2 configuration was used, please migrate to V3 configuration, or set 'NEKO_LEGACY=true' to acknowledge this message")
viper.Set("legacy", true)
}
}

View file

@ -171,6 +171,8 @@ func (s *Session) Set() {
}
func (s *Session) SetV2() {
enableLegacy := false
if viper.IsSet("locks") {
locks := viper.GetStringSlice("locks")
for _, lock := range locks {
@ -183,18 +185,28 @@ func (s *Session) SetV2() {
}
}
log.Warn().Msg("you are using v2 configuration 'NEKO_LOCKS' which is deprecated, please use 'NEKO_SESSION_LOCKED_CONTROLS' and 'NEKO_SESSION_LOCKED_LOGINS' instead")
enableLegacy = true
}
if viper.IsSet("implicit_control") {
s.ImplicitHosting = viper.GetBool("implicit_control")
log.Warn().Msg("you are using v2 configuration 'NEKO_IMPLICIT_CONTROL' which is deprecated, please use 'NEKO_SESSION_IMPLICIT_HOSTING' instead")
enableLegacy = true
}
if viper.IsSet("control_protection") {
s.ControlProtection = viper.GetBool("control_protection")
log.Warn().Msg("you are using v2 configuration 'NEKO_CONTROL_PROTECTION' which is deprecated, please use 'NEKO_SESSION_CONTROL_PROTECTION' instead")
enableLegacy = true
}
if viper.IsSet("heartbeat_interval") {
s.HeartbeatInterval = viper.GetInt("heartbeat_interval")
log.Warn().Msg("you are using v2 configuration 'NEKO_HEARTBEAT_INTERVAL' which is deprecated, please use 'NEKO_SESSION_HEARTBEAT_INTERVAL' instead")
enableLegacy = true
}
// set legacy flag if any V2 configuration was used
if !viper.IsSet("legacy") && enableLegacy {
log.Warn().Msg("legacy configuration is enabled because at least one V2 configuration was used, please migrate to V3 configuration, or set 'NEKO_LEGACY=true' to acknowledge this message")
viper.Set("legacy", true)
}
}

View file

@ -318,21 +318,27 @@ func (s *WebRTC) Set() {
}
func (s *WebRTC) SetV2() {
enableLegacy := false
if viper.IsSet("nat1to1") {
s.NAT1To1IPs = viper.GetStringSlice("nat1to1")
log.Warn().Msg("you are using v2 configuration 'NEKO_NAT1TO1' which is deprecated, please use 'NEKO_WEBRTC_NAT1TO1' instead")
enableLegacy = true
}
if viper.IsSet("tcpmux") {
s.TCPMux = viper.GetInt("tcpmux")
log.Warn().Msg("you are using v2 configuration 'NEKO_TCPMUX' which is deprecated, please use 'NEKO_WEBRTC_TCPMUX' instead")
enableLegacy = true
}
if viper.IsSet("udpmux") {
s.UDPMux = viper.GetInt("udpmux")
log.Warn().Msg("you are using v2 configuration 'NEKO_UDPMUX' which is deprecated, please use 'NEKO_WEBRTC_UDPMUX' instead")
enableLegacy = true
}
if viper.IsSet("icelite") {
s.ICELite = viper.GetBool("icelite")
log.Warn().Msg("you are using v2 configuration 'NEKO_ICELITE' which is deprecated, please use 'NEKO_WEBRTC_ICELITE' instead")
enableLegacy = true
}
if viper.IsSet("iceservers") {
@ -347,6 +353,7 @@ func (s *WebRTC) SetV2() {
s.ICEServersFrontend = iceServers
s.ICEServersBackend = iceServers
log.Warn().Msg("you are using v2 configuration 'NEKO_ICESERVERS' which is deprecated, please use 'NEKO_WEBRTC_ICESERVERS_FRONTEND' and/or 'NEKO_WEBRTC_ICESERVERS_BACKEND' instead")
enableLegacy = true
}
if viper.IsSet("iceserver") {
@ -356,6 +363,7 @@ func (s *WebRTC) SetV2() {
s.ICEServersBackend = append(s.ICEServersBackend, types.ICEServer{URLs: iceServerSlice})
}
log.Warn().Msg("you are using v2 configuration 'NEKO_ICESERVER' which is deprecated, please use 'NEKO_WEBRTC_ICESERVERS_FRONTEND' and/or 'NEKO_WEBRTC_ICESERVERS_BACKEND' instead")
enableLegacy = true
}
if viper.IsSet("ipfetch") {
@ -368,6 +376,7 @@ func (s *WebRTC) SetV2() {
s.NAT1To1IPs = append(s.NAT1To1IPs, ip)
}
log.Warn().Msg("you are using v2 configuration 'NEKO_IPFETCH' which is deprecated, please use 'NEKO_WEBRTC_IP_RETRIEVAL_URL' instead")
enableLegacy = true
}
if viper.IsSet("epr") {
@ -395,5 +404,12 @@ func (s *WebRTC) SetV2() {
s.EphemeralMax = max
}
log.Warn().Msg("you are using v2 configuration 'NEKO_EPR' which is deprecated, please use 'NEKO_WEBRTC_EPR' instead")
enableLegacy = true
}
// set legacy flag if any V2 configuration was used
if !viper.IsSet("legacy") && enableLegacy {
log.Warn().Msg("legacy configuration is enabled because at least one V2 configuration was used, please migrate to V3 configuration, or set 'NEKO_LEGACY=true' to acknowledge this message")
viper.Set("legacy", true)
}
}

View file

@ -4,6 +4,18 @@ sidebar_position: 8
# V2 Migration Guide
Currently, Neko is in compatibility mode, meaning that as soon as a single V2 configuration option is set, the legacy mode is enabled. This approach allows for a smooth transition from V2 to V3, where it does not expose the V2 API for new users but still allows existing users who use the old configuration to continue using it as before.
The legacy mode can be explicitly enabled or disabled by setting the `NEKO_LEGACY` environment variable to `true` or `false`.
:::tip
You can migrate to a new configuration even if you are using a V2 client. Just make sure to set the `NEKO_LEGACY` environment variable to `true`.
:::
:::info Built-in Client
When using Neko in a container with a built-in client, the client will always be compatible with the server regardless of what configuration is used.
:::
## Configuration
V3 is compatible with V2 configuration options when legacy support is enabled. You should be able to run V3 with the V2 configuration without any issues.
@ -14,7 +26,7 @@ In order to migrate from V2 to V3, you need to update the configuration to the n
| **V2 Configuration** | **V3 Configuration** |
|---------------------------------------|-----------------------------------------------------------|
| `NEKO_LOGS` *removed* | `NEKO_LOG_DIR=/path/to/logs` |
| `NEKO_LOGS=true` | `NEKO_LOG_DIR=/var/log/neko`, V3 allows specifying the log directory |
| `NEKO_CERT` | `NEKO_SERVER_CERT` |
| `NEKO_KEY` | `NEKO_SERVER_KEY` |
| `NEKO_BIND` | `NEKO_SERVER_BIND` |

View file

@ -1,4 +1,20 @@
[
{
"key": [
"legacy"
],
"type": "boolean",
"defaultValue": "true",
"description": "enable legacy mode"
},
{
"key": [
"logs"
],
"type": "boolean",
"defaultValue": "false",
"description": "save logs to file"
},
{
"key": [
"display"

View file

@ -1,4 +1,7 @@
--legacy enable legacy mode (default true)
--logs save logs to file
--display string XDisplay to capture
--video_codec string video codec to be used
--av1 DEPRECATED: use video_codec