-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Expose Connection environment variables to the app start #1430
Expose Connection environment variables to the app start #1430
Conversation
…Zammuto/Sunshine-1 into connection-environment-variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add something to the docs about environment variables as well?
We could also update these do command examples to use the environment variables: https://github.com/LizardByte/Sunshine/blob/nightly/docs/source/about/app_examples.rst?plain=1#L131-L183
Linux Example: https://docs.lizardbyte.dev/projects/sunshine/en/nightly/about/app_examples.html#changing-resolution-and-refresh-rate-linux-x11
macOS Example: https://docs.lizardbyte.dev/projects/sunshine/en/nightly/about/app_examples.html#changing-resolution-and-refresh-rate-macos
And we could remove this section (don't think it will be useful after this is merged): https://github.com/LizardByte/Sunshine/blob/nightly/docs/source/about/app_examples.rst?plain=1#L188-L189
Ideally all parameters of the client should be accessible, anyone opposed to something like that? I’m guessing it would be documentation and more code changes? |
Specifically there is a bunch of moonlight variables logged when the log level as set to debug, which gives a lot of useful information. I’ve been wanting to make those accessible but it appears those are logged after the stream starts, not beforehand. |
Yup, the app starts when a /launch command is issued on the client side, so we can only access the variables sent using this endpoint. Do you have any specific variable you want to be passed? |
Co-authored-by: ReenigneArcher <[email protected]>
Co-authored-by: ReenigneArcher <[email protected]>
…Zammuto/Sunshine-1 into connection-environment-variables
All of the parameters logged that start with a=nv-video would be great
But I suppose just having HDR, fps and resolution is fine for my use cases though. What's the option for figuring out if user has enabled/disabled the feature to close games on stream end? I could use that for my playnite watcher script. |
Unfortunately these are passed on the RTSP stage, so they cannot be passed on the app start
It seems that it's a client-only option EDIT: I think the best thing is to make in a future PR a named-pipe to handle all of these cases, so the integration can be completed |
Update upstream
Co-authored-by: ReenigneArcher <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a macOS example?
Also, how about adding a section about the env variables to the docs? I could take care of this in a separate PR in order to get this moving along.
Co-authored-by: ReenigneArcher <[email protected]>
launch_session.unique_id = (get_arg(args, "uniqueid")); | ||
launch_session.uuid = (get_arg(args, "uuid")); | ||
launch_session.appid = util::from_view(get_arg(args, "appid")); | ||
launch_session.enable_sops = util::from_view(get_arg(args, "sops")); | ||
launch_session.surround_info = util::from_view(get_arg(args, "surroundAudioInfo")); | ||
launch_session.gcmap = util::from_view(get_arg(args, "gcmap")); | ||
launch_session.enable_hdr = 0; | ||
if (args.find("enableHdr"s) != std::end(args)) { | ||
launch_session.enable_hdr = util::from_view(get_arg(args, "enableHdr")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we set a default value to empty/null if the client doesn't provide it? I'm thinking something similar to Python's os.getenv
method. os.getenv(key, "some default value")
Apparently, Moonlight on Apple doesn't provide UUID (and who knows about every possible homebrew moonlight client). https://discord.com/channels/804382334370578482/1074377411069747250/1135639228613664858
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps something like
std::string
get_arg(const args_t &args, const char *name, const char *default_value = nullptr) {
auto it = args.find(name);
if (it == std::end(args)) {
if (default_value != NULL) {
return std::string(default_value);
}
throw std::out_of_range(name);
}
return it->second;
}
Used as such:
launch_session.gcm_key = util::from_hex<crypto::aes_t>(get_arg(args, "rikey", "0"), true);
std::stringstream mode = std::stringstream(get_arg(args, "mode", "0x0x0"));
// Split mode by the char "x", to populate width/height/fps
int x = 0;
std::string segment;
while (std::getline(mode, segment, 'x')) {
if (x == 0) launch_session.width = atoi(segment.c_str());
if (x == 1) launch_session.height = atoi(segment.c_str());
if (x == 2) launch_session.fps = atoi(segment.c_str());
x++;
}
launch_session.unique_id = (get_arg(args, "uniqueid", "0123456789ABCDEF"));
launch_session.uuid = (get_arg(args, "uuid", "00000000000000000000000000000000"));
launch_session.appid = util::from_view(get_arg(args, "appid", "0123456789"));
launch_session.enable_sops = util::from_view(get_arg(args, "sops", "0"));
launch_session.surround_info = util::from_view(get_arg(args, "surroundAudioInfo", "0"));
launch_session.gcmap = util::from_view(get_arg(args, "gcmap", "0"));
launch_session.enable_hdr = 0;
if (args.find("enableHdr"s) != std::end(args)) {
launch_session.enable_hdr = util::from_view(get_arg(args, "enableHdr", "0"));
}
uint32_t prepend_iv = util::endian::big<uint32_t>(util::from_view(get_arg(args, "rikeyid", "0")));
…1430) Co-authored-by: ReenigneArcher <[email protected]>
…1430) Co-authored-by: ReenigneArcher <[email protected]>
Description
When starting apps, some environment variables releated to the connection are passed to the commands (pre/detatched/do)
Instead of #1096 that relies on text replacement, this uses the environment variables system, which should be more robust and secure (Although I haven't tested cmd injection techinques). I've also documented inside the Web UI which vars are exposed and how to consume them in a standard cmd command on Windows (other platform suggestions are welcome!)
This should make scripts more elegant instead of relying on parsing log files.
Screenshot
Type of Change
.github/...
)Checklist
Branch Updates
LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch
must be updated before it can be merged. You must also
Allow edits from maintainers.