how to add screen sharing using JSSIP

549 views
Skip to first unread message

Athira AR

unread,
Nov 2, 2020, 1:25:16 AM11/2/20
to SIP.js
Hi,
I am trying to add screen share in jssip i see the code available using sip.js but that not working with jssip please provide me a solution

sam.v...@everdelta.com

unread,
Nov 3, 2020, 6:09:11 AM11/3/20
to SIP.js


This method is working in 0.15.11 which replaces the local video track with the screen sharing video track. I haven't tested in later versions:

https://groups.google.com/g/sip_js/c/Jv8HS9VGBcw/m/LL9jpbdUCQAJ


We are looking to add a screen sharing track in addition to the local video. Unfortunately I haven't had success with yet in 0.15.11 or 0.17.1. peerConnection.addTrack(screenSharing) track does not appear to trigger a reinvite... Any help greatly appreciated.

Michael Sila

unread,
Apr 26, 2021, 3:31:09 PM4/26/21
to SIP.js
Hey All, I know I'm late to the party but you can actually do this by implementing a custom sessionDescriptionHandlerFactory in the UserAgent. After implementing a custom one, just set the video constraint to 'screen' and you'll be in business. Note that for this to work navigator.mediaDevices.getDisplayMedia has to be supported.

const mediaStreamFactory = (constraints, sessionDescriptionHandler) => {
    return navigator.mediaDevices.enumerateDevices()
    .then(devices => {
        const hasVideo = devices.some(d => d.kind === 'videoinput');
        const hasAudio = devices.some(d => d.kind === 'audioinput');
        if (constraints.video === 'screen') {
            return navigator.mediaDevices.getDisplayMedia();
        }
       if (!hasVideo && !hasAudio) {
           return Promise.resolve(_getCanvasStream());
       };
       if (!hasVideo & hasAudio) {
            return navigator.mediaDevices.getUserMedia({
            video: false,
            audio: constraints.audio
            }).then(stream => {
                const canvasStream = _getCanvasStream();
                stream.addTrack(canvasStream.getVideoTracks()[0]);
               return stream;
           })
       }
if (hasVideo && !hasAudio) {
return navigator.mediaDevices.getUserMedia({
video: constraints.video,
audio: false
})
}
return navigator.mediaDevices.getUserMedia(constraints);
})
};
const sessionDescriptionHandlerFactory = SIP.Web.defaultSessionDescriptionHandlerFactory(mediaStreamFactory);
screenShareCallNumber = participantId;
const transportOptions = {
wsServers: websocketUrls
};
const userAgentOptions = {
transportOptions,
uri: SIP.UserAgent.makeURI(`sip:${webrtcId}@example.com`),
authorizationUsername: sipUserName,
authorizationPassword: sipPassword,
displayName: `${participantId}`,
delegate: {
onMessage: (msg) => {
console.log('Message Recieved');
console.log(msg.request);
msg.accept();
},
onDisconnect: (error) => {
if (error) {
}
}
},
sessionDescriptionHandlerFactory: sessionDescriptionHandlerFactory
}
userAgent = new SIP.UserAgent(userAgentOptions);
Reply all
Reply to author
Forward
0 new messages