livekit / client-sdk-js

LiveKit browser client SDK (javascript)
https://livekit.io
Apache License 2.0
322 stars 135 forks source link

The stream is not restored when the shared window page is minimized and then zoomed in on the NW.js #1179

Open zesun96 opened 2 weeks ago

zesun96 commented 2 weeks ago

Describe the bug

expect: the stream track unmute and re-publish;

Reproduction

A share a window page; B view it good; then the window of A is minimized; B look black picture; then the window of A is zoomed in;

Logs

I add some logs at client-sdk-js:

  private handleTrackMuteEvent = () =>
    this.debouncedTrackMuteHandler().catch(() =>
      this.log.debug('track mute bounce got cancelled by an unmute event', this.logContext),
    );

  private debouncedTrackMuteHandler = debounce(async () => {
    this.log.debug('track mute event', this.logContext),
    await this.pauseUpstream();
  }, 5000);

  private handleTrackUnmuteEvent = async () => {
    this.log.debug('track unmute event', this.logContext),
    this.debouncedTrackMuteHandler.cancel('unmute');
    await this.resumeUpstream();
  };

but only recived "track mute event" on window  is minimized;

System Info

OS: Windows 10
NWjs version: 0.82.0
livekit client-sdk-js version: v1.15.13

Severity

annoyance

Additional Information

No response

zesun96 commented 2 weeks ago

I found that the following code was affected track unmute event: room/track/LovalTrack.ts

async pauseUpstream() {
    const unlock = await this.pauseUpstreamLock.lock();
    try {
      ...
      **await this.sender.replaceTrack(null);**
    } finally {
      unlock();
    }
  }

When I skip this code and run it again, it's fine.

lukasIO commented 2 weeks ago

Can you confirm that you don't receive a unmute event when maximising the window again?

Which browser are you on? Does the same behaviour reproduce with other browsers?

zesun96 commented 2 weeks ago

I didn't receive unmute event. It is ok on google browser.

zesun96 commented 2 weeks ago

image

this is google logs when share window is minimized. google version: 126.0.6478.127

zesun96 commented 2 weeks ago

When I commented out the following code in nwjs: await this.sender.replaceTrack(null); I can receive unmuteevent.

lukasIO commented 2 weeks ago

are you able to reproduce this in the sample app using pnpm sample in this repo?

zesun96 commented 2 weeks ago

no, adaptation is required to used sample in nwjs env.

lukasIO commented 2 weeks ago

I see. I'm not very familiar with NW.js, but then probably this should be reported to NW.js as a bug as it seems to be not emitting the unmute event on the track when a window is restored.

zesun96 commented 2 weeks ago

I only use nwjs run webrtc sample, the unmute event is emitted.

aimin-git commented 2 weeks ago

I see. I'm not very familiar with NW.js, but then probably this should be reported to NW.js as a bug as it seems to be not emitting the unmute event on the track when a window is restored. @lukasIO I thought the unmute event is emitted by webrtc, isn't it?

lukasIO commented 2 weeks ago

I'm guessing NW.js needs to wrap get display media APIs, similar to how electron has to. That could potentially explain why it works as expected in Chrome, but doesn't in NW.js.