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

Run DO - UNDO command when Client gets connected disconnected, not just Starting and Quitting Session #165

Open
RebelliousX opened this issue Dec 23, 2024 · 5 comments

Comments

@RebelliousX
Copy link

Related to audio switching issue from sunshine but different issue.
I created a similar issue on Sunshine main repo too. I hope either Apollo or Sunshine gets this implemented.

I downloaded SetVol app from here on github and added command for DO and Undo like

For Do:

C:\temp\SetVol mute

For Undo:

 C:\temp\SetVol unmute

Which works great. The issue is, the UNDO command doesn't run when the client gets disconnected, but only when session quits. That is, if I minimize Moonlight, the client disconnects, streaming stops, but Volume still muted. If I open Moonlight and force session to quit, the Undo command runs.

When I use sunshine, I also have similar issue when running VDD trying to run UNDO command when client disconnect, for example Moonlight on Shield TV (session is on, just Moonlight minimized). The Undo command to switch back to main display doesn't run until I force quit the session from Moonlight. The host's main displplay remains black until I force quit the session even if Moonlight is disconnected.

When I used Apollo, the virtual display doesn't change to physical display when client disconnects, just when session quits.

I would like to have an option to do that, that is to Run DO and UNDO commands when client gets connected and disconnected. if changing current behavior is not feasible, at least, add and option to do so on these events.

@ClassicOldSong
Copy link
Owner

The problem here is when you share your screen with multiple users, how would you treat the do and undos for the "connect" and "disconnect"s from other users?

I have plan to add webhook to connection events but that's in the future when I have better overall thoughts about the whole system. Sunshine is a total mess in its code structure and currently this is the best I can do...

@RebelliousX
Copy link
Author

RebelliousX commented Dec 24, 2024

@ClassicOldSong didn't you mention in the ReadMe that when sharing screen to multiple users, only one can handle the input? then treat the connect and disconnect only from the user who has input active.

And really, at that point, if someone wants to share his gameplay to many users at once, at that point, you probably should add a feature to stream to Twitch or something, lol. And others who want to watch can watch the stream from Twitch. I can say this is a very niche use case, I personally live alone and don't have to share with anyone except myself 😂

@ClassicOldSong
Copy link
Owner

I didn't, but users can have different permissions. Multiple users can input at the same time, just input permissions are disabled by default for devices that are paired later.

The permission system is for shared play, not for broadcasting purposes, and broadcasting requires different encoding setup so using OBS to stream might be better.

But sure, it is possible to use the permission system to add scripts for different users. I'll think about it.

@RebelliousX
Copy link
Author

RebelliousX commented Dec 24, 2024

With the help of ChatGPT, it wrote a PowerShell script within a minute that works beautifully

This is script will run a specific batch file when client is connected, and another when disconnected:

$logFilePath = "C:\Program Files\Sunshine\config\sunshine.log"
$connectedBatchFilePath = "C:\Temp\muteVolume.bat"
$disconnectedBatchFilePath = "C:\Temp\UnmuteVolume.bat"
$matchPatternClientConnected = "CLIENT CONNECTED"
$matchPatternClientDisconnected = "CLIENT DISCONNECTED"

# Check if the log file exists before proceeding
if (-Not (Test-Path $logFilePath)) {
    Write-Error "Log file does not exist: $logFilePath"
    exit
}

# Monitor the log file for new content
Get-Content $logFilePath -Wait | ForEach-Object {
    if ($_ -match $matchPatternClientConnected ) {
        # When the pattern is matched, execute the batch file
        Start-Process -WindowStyle hidden -FilePath $connectedBatchFilePath
    }

    if ($_ -match $matchPatternClientDisconnected ) {
        # When the pattern is matched, execute the batch file
        Start-Process -WindowStyle hidden -FilePath $disconnectedBatchFilePath
    }
}

Batch files just run SetVol.exe unmute or SetVol.exe mute preceded by @echo off and the program can be downloaded from github.

As executing the PowerShell script, probably Task Scheduler with "Run whether user logged in or not" will prevent terminal from showing up when executing the script at startup.

@ClassicOldSong
Copy link
Owner

Parsing logs is a clever idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants