Right now I can easily unpublish webcam video and share screen and also after stopping I can start my webcam. But the problem is whenever I’m doing unpublish(publisher), my video elements are still there.
as you can see publisher2 video elements are still there,
again I publish my publisher with new video elements, but the old one is still there.
Mycode:-
--------
continue
-------
> // added screen sharing feature
$(document).ready(function() {
$('#share').click(function() {
session.unpublish(publisher);
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');
session.unpublish(publisher);
publisher = OV.initPublisher('video-container',publisherConfig);
publisher.on('videoElementCreated', (event) => {
var userData = {
nickName: nickName,
userName: userName
};
initMainVideo(event.element, userData);
appendUserData(event.element, userData);
$(event.element).prop('muted', true); // Mute local video
});
session.publish(publisher);
});
session.publish(publisher);
});
publisher.once('accessDenied', (event) => {
publisher = OV.initPublisher('video-container',publisherConfig);
publisher.on('videoElementCreated', (event) => {
var userData = {
nickName: nickName,
userName: userName
};
initMainVideo(event.element, userData);
appendUserData(event.element, userData);
$(event.element).prop('muted', true); // Mute local video
});
session.publish(publisher);
console.warn('ScreenShare: Access Denied');
});
$(this).toggleClass("fa-video-slash");
$(this).toggleClass("fa-laptop");
});
});