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

Prevent screen blanking/screensaver #777

Open
dmke opened this issue Feb 16, 2024 · 6 comments
Open

Prevent screen blanking/screensaver #777

dmke opened this issue Feb 16, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@dmke
Copy link

dmke commented Feb 16, 2024

Describe the problem

On my machine, the screen blanks (and actually locks) after 5min of inactivity (i.e. no mouse or keyboard input). For company policy reasons, I cannot disable that behaviour.

It is a bit of an annoyance, when my monitor goes into sleep mode in the middle of a sentence, as it takes a moment to recover from that...

Describe the proposed solution

Browsers usually prevent screensavers from activating, when they play media (and NoSleep.js promises to provide such a functionality).

I'm not sure why the video/audio tracks of LiveKit itself don't count towards this behaviour.

Speculation

I presume this is because the tracks don't actually originate from a user input event, such as a button click?

For example, the local video track already exists in the <PreJoin/> prefab, even before I click on the "Join" button. And remote tracks of course are added without user interaction at all.

There's also the Screen Wake Lock API, but Firefox support is missing:

image

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

@Ocupe Ocupe added the enhancement New feature or request label Feb 16, 2024
@lukasIO
Copy link
Contributor

lukasIO commented Feb 16, 2024

I think whether or not this is desired behaviour would greatly depend on the use case. I'm not sure whether the library (components) is the right place for this. I guess adding a wakelock to github.com/livekit-examples/meet might make sense

@dmke
Copy link
Author

dmke commented Feb 16, 2024

That's fine with me :)

I'll try to hook into <PreJoin onSubmit/> and report back.

@dmke dmke closed this as completed Feb 16, 2024
@dmke
Copy link
Author

dmke commented Feb 16, 2024

I've added use-stay-awake1 and called preventSleeping in the <PreJoin onSubmit/> callback, and allowSleeping to <LiveKitRoom onDisconnect/>:

export function JoinRoom(props: { token: string, url: string }) {
  const screen = useStayAwake()

  function onJoin(choices: LocalUserChoices) {
    screen.preventSleeping()
  }

  function onLeave() {
    screen.allowSleeping()
  }

  if (preJoinChoices === null) {
    return <PreJoin onSubmit={onJoin} />
  }
  return <LiveKitRoom onDisconnected={onLeave}>
    <VideoConference chatMessageFormatter={formatChatMessageLinks} />
  </LiveKitRoom>
}

AFAICT, this seems to work.

(Here, I've omitted handling of LocalUserOptions and transforming it into RoomOptions and a new Room instance, before passing it to the <LiveKitRoom/>.)

Footnotes

  1. The NPM package depends on React v16, but the source code can easily be vendored.

@dmke
Copy link
Author

dmke commented Feb 27, 2024

I'll withdraw my previous comment: While the background media inserted by use-stay-awake does indeed play, it doesn't prevent the screen from blanking. I suspect the <PreJoin onSubmit /> callback isn't detected properly as a user-initiated action - maybe this needs to be implemented closer to the click handler of the "Join" button? 🤔

With Firefox 124 (scheduled for release mid-March) to enable the Screen Wake Lock API by default, would you accept a PR which adds that to the <PreJoin /> component directly (maybe even behind an off-by-default switch)?

@dmke dmke reopened this Feb 27, 2024
@lukasIO
Copy link
Contributor

lukasIO commented Feb 28, 2024

Have you confirmed that it's working in isolation?

If we were to add screen lock wake, then the livekit/client-sdk-js repo would be the best place for it. However, I'm not sure if this is the right approach. It's unexpected that your screen blanks in the first place while video is being played back.

@dmke
Copy link
Author

dmke commented Feb 28, 2024

I don't have hard evidence, just some observations when screen blanking does not occur on my machine:

I do however have quite an old installation of Debian 11/Gnome 3.38.5 which might play into this (upgrading is a problem of finding a bit of time to do so :)).

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

No branches or pull requests

3 participants