I want client share webcam and screen. I can now do it but the problem I can not catch stopping screen share. I throws the Cannot set property 'session' of undefined
error. Here is my code:
function shareScreen() {
OVS = new OpenVidu();
sessionScreen = OVS.initSession();
var nickName = $("#nickName").val();
getToken((token) => {
sessionScreen.connect(token, {
clientData: nickName + "_screen"
})
.then(() => {
var publisher = OVS.initPublisherAsync("", {
videoSource: "screen"
}).then(publisher => {
publisher.stream.getMediaStream().getVideoTracks()[0].addEventListener('ended', () => {
console.log('User pressed the "Stop sharing" button');
});
});
sessionScreen.publish(publisher);
})
.catch(error => {
console.warn('There was an error connecting to the session:', error.code, error.message);
});
});
}
Can you tell me whats wrong with this code? Thank you.