Unable to share screen using Get a Room

Greetings all,

I’m new to OpenVidu and I can tell it’s amazing.

Unfortunately, I’m unable to Share Screen using OpenVidu Get a Room after following this link.

function shareMyScreen() {
OV = new OpenVidu();
var sessionScreen = OV.initSession();
console.log("ENTERED SHARE SCREEN FUNCTION")
getToken((token) => {
    sessionScreen.connect(token).then(() => {
        console.log('COMES TO TO THEN FUNCTION');
        var publisher = OV.initPublisher("html-element-id", {videoSource: "screen"});

        publisher.once('accessAllowed', (event) => {
            publisher.stream.getMediaStream().getVideoTracks()[0].addEventListener('ended', () => {
                console.log('User pressed the "Stop sharing" button');
            });
            sessionScreen.publish(publisher);

        });

        publisher.once('accessDenied', (event) => {
            console.warn('ScreenShare: Access Denied');
        });

    }).catch((error => {
        console.warn('There was an error connecting to the session:', error.code, error.message);

    }));
});
console.log("FINISHED SHARE SCREEN FUNCTION")
}

Capture

I think it might be skipping the getToken because I don’t know how to pass the token.

Thanks in advance.

Hello,

The code you pasted is bad formated and it’s difficult to read it. However, there could be a bug in the code… try with:

getToken().then((token) => {
   ...
})

Thank you. It has fixed my problem. Though, I’ve copied the code above from the OpenVidu share screen documentation.

You’re awesome.

Yes, I just fixed the code from docs.

Thank you