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

How get the screen share stream id not use chooseDesktopMedia? #4459

Closed
sean220 opened this issue Feb 26, 2016 · 16 comments
Closed

How get the screen share stream id not use chooseDesktopMedia? #4459

sean220 opened this issue Feb 26, 2016 · 16 comments
Assignees

Comments

@sean220
Copy link

sean220 commented Feb 26, 2016

The chooseDesktopMedia() callback streamId can be used only once and expires after a few seconds when it is not used. But in 0.12 the streamId can always be reused,
Is there any way get a streamId, not by calling chooseDesktopMedia()?

@sean220
Copy link
Author

sean220 commented Feb 29, 2016

OK,I found the stream id can be get without GUI by Screen.DesktopCaptureMonitor.
But,unfortunately,The stream id obtained in this way is incorrect in 0.13beta7.
e.g. The primary screen stream Id get from chooseDesktopMedia looks like "5wAQj7o/czfAqRJs2uKUHQ==", and DesktopCaptureMonitor returns "screen:0"(like old one in version 0.12).

@rogerwang rogerwang self-assigned this Feb 29, 2016
@rogerwang
Copy link
Member

are you using the nw.Screen API? does chrome.desktopCapture work for you? https://developer.chrome.com/extensions/desktopCapture

@sean220
Copy link
Author

sean220 commented Feb 29, 2016

Yes,I using nw.Screen.chooseDesktopMedia,And I test chrome.desktopCapture too, Both run the same results and the stream Id work fine with getUserMedia(),But I do not need to display the screen selection GUI Window,So the problem is the DesktopCaptureMonitor does not return the correct stream id.

@sean220
Copy link
Author

sean220 commented Feb 29, 2016

Of course, if the stream Id is reusable like in version 0.12, can also solve the problem.
In 0.12 version, chooseDesktopMedia always returns "screen:0" for the primary screen,just like DesktopCaptureMonitor's 'added' event returns in version 0.13beta7.

@rogerwang
Copy link
Member

Could you please provide a sample?

@sean220
Copy link
Author

sean220 commented Feb 29, 2016

screenshare-demo.zip

@rogerwang rogerwang assigned ghostoy and unassigned rogerwang Feb 29, 2016
@sean220
Copy link
Author

sean220 commented Feb 29, 2016

I think reusable stream id like version 0.12 is more friendly for Desktop Application, After tests also found a temporary stream Id pass to other windows's getUserMedia() is not work。

ghostoy pushed a commit to ghostoy/nw.js that referenced this issue Mar 1, 2016
Stream id obtained internally should be registered with
`DesktopStreamsRegistry`, which returns an randomly generated
stream id valid for 10s, before passing to `getUserMedia()`.

Fixed nwjs#4459
ghostoy pushed a commit to ghostoy/nw.js that referenced this issue Mar 1, 2016
Stream id obtained internally should be registered with
`DesktopStreamsRegistry`, which returns an randomly generated
stream id valid for 10s, before passing to `getUserMedia()`.

Fixed nwjs#4459
@ghostoy
Copy link
Member

ghostoy commented Mar 1, 2016

In Chrome, the stream id used by getUserMedia() is limited to be one-time and only valid for 10s in the same frame that requesting it. These constrains must be for some reason, such as security concerns. So we'd better not to break it.

I'm proposing to add a new API Screen.DesktopCaptureMonitor.registerStream() to obtain the stream id used by getUserMedia(). The usage then should be slightly changed into following:

var dcm = nw.Screen.DesktopCaptureMonitor;
dcm.on("added",function(id, name, order, type, primary){
    // `id` is valid anywhere anytime and can be passed to any frame or window
    var conf = {
        mandatory: {
            chromeMediaSource: 'desktop',
            // register `id` to obtain a valid stream id before passing to `getUserMedia()`
            chromeMediaSourceId: dcm.registerStream(id),
            maxWidth: 1280,
            maxHeight: 720
        },
        optional: []
    };
    // ...
    navigator.webkitGetUserMedia(conf, callback);
});

Is the new API good for you? @sean220

@sean220
Copy link
Author

sean220 commented Mar 1, 2016

Thanks for support,I have a few questions about the new API.
(1)Dose registerStream just translate id into the chrome's temporary stream id?
(2)Is the 'added' event return id reusable just like in version 0.12?
(3)Can I call this method directly outside the event callback function?

@ghostoy

@ghostoy
Copy link
Member

ghostoy commented Mar 1, 2016

  1. Yes
  2. Yes. The id returned by added can be used anywhere anytime as 0.12 until the source is removed.
  3. Yes.

@sean220
Copy link
Author

sean220 commented Mar 1, 2016

Sorry,I found the comments in the code now.
It's good enough for my case,Thanks.
Can I try this API from the last live build?

@ghostoy
Copy link
Member

ghostoy commented Mar 1, 2016

We are rebasing on CR49. I will let you know once it's available in live build.

@sean220
Copy link
Author

sean220 commented Mar 1, 2016

OK,We are looking forward to the CR49 version.

ghostoy pushed a commit to ghostoy/nw.js that referenced this issue Mar 1, 2016
Media source id returned by `added` event should be registered
before using with `getUserMedia()`. Media source id, e.g.
"screen:0", is permanent until removed, while registered stream id
is a temporary one-time random string accessible only from the
frame that requesting it.

Fixed nwjs#4459
@rogerwang
Copy link
Member

@sean220
Copy link
Author

sean220 commented Mar 3, 2016

Well Done! It's works.
By the way,Is it possible to get rid of the 'Screen is sharing' prompt window?
@rogerwang

@rogerwang
Copy link
Member

Sure, we'll see it. Please file another issue for that.

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

3 participants