simplewebrtc / SimpleWebRTC

Simplest WebRTC ever
Other
4.65k stars 1.19k forks source link

screen share #734

Closed supun19 closed 6 years ago

supun19 commented 6 years ago

could you share screen share sample code with me

cmar0ck commented 6 years ago
// Enable Screen Sharing
var button = $('#screenShareButton'),
setButton = function (bool) {
    button.text(bool ? 'share screen' : 'stop sharing');
};
webrtc.on('localScreenStopped', function () {
    setButton(true);
});

setButton(true);

button.click(function () {
    if (webrtc.getLocalScreen()) {
        webrtc.stopScreenShare();
        setButton(true);
    } else {
        webrtc.shareScreen(function (err) {
            if (err) {
                setButton(true);
            } else {
                setButton(false);
            }
        });

    }
});

Note that this only works out of the box in Firefox and over SSL. Chrome needs to be started with certain parameters ( "--enable-usermedia-screen-capturing") or needs to use plugins for screen sharing to work properly.

supun19 commented 6 years ago

thank you your reply @cmar0ck

supun19 commented 6 years ago

i am using this extension https://github.com/otalk/getScreenMedia

this is a manifest.json

{ "name": "Screensharing Sample", "description": "Screensharing utility sample for getscreenmedia", "version": "0.0.1", "manifest_version": 2, "minimum_chrome_version": "34", "icons": { }, "permissions": [ "desktopCapture" ], "background": { "scripts": ["background.js"] }, "content_scripts": [ { "js": [ "content.js" ], "matches": [ "http://localhost:8000/*" ] }], "externally_connectable": { "matches": [ "http://localhost:8000/*" ] } }

i also get this error screen share error: HTTPS_REQUIRED Error: NavigatorUserMediaError at module.exports (getscreenmedia.js:11) at WebRTC.LocalMedia.startScreenShare (localmedia.js:148) at SimpleWebRTC.shareScreen (simplewebrtc.js:410) at WebRTCComponent.screenShare (WebRTCComponent.js:333) at HTMLUnknownElement.callCallback (react-dom.development.js:100) at Object.invokeGuardedCallbackDev (react-dom.development.js:138) at Object.invokeGuardedCallback (react-dom.development.js:187) at Object.invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:201) at executeDispatch (react-dom.development.js:461) at executeDispatchesInOrder (react-dom.development.js:483)

can you help for fixing this issue

supun19 commented 6 years ago

I also enable flag "Allow invalid certificates for resources loaded from localhost." in chrome

cmar0ck commented 6 years ago

You need to use ssl / https (not http). It's also possible that chrome rejects self-signed certs

supun19 commented 6 years ago

Thank You @cmar0ck it worked.