var screencastConstraints =
{
audio: false,
video: {
mandatory: {
maxWidth: 640,
maxHeight: 480,
maxFrameRate: 15,
minFrameRate: 15
}
}
};
window.addEventListener('message', function (msg) {
if (msg.data.state === 'completed') {
//alert('state: ' + msg.data.streamId);
if (msg.data.streamId != undefined) {
screencastConstraints.video.mandatory.chromeMediaSource = 'desktop';
screencastConstraints.video.mandatory.chromeMediaSourceId = msg.data.streamId;
self.streamScreen();
}
}
});
self.streamScreen = function () {
$log.debug('Stream screen');
kurentoUtils.WebRtcPeer.startSendOnly(null, function (offerSdp, wp) {
webRtcPeerScreencast = wp;
$log.debug('Invoking SDP offer callback function');
var message = {
id: 'screencast',
from: userID,
to: observerID,
sdpOffer: offerSdp
};
self.sendMessage(message);
}, function (error) {
$log.error('Stream screen error: ', error);
}, screencastConstraints);
};
--
You received this message because you are subscribed to the Google Groups "kurento" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kurento+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
function shareScreen(){ var audioConstraints = { audio: false, //turn this true in case you want to share this in a single stream video: true, }; navigator.getUserMedia(audioConstraints, function(stream) { initiateScreenSharing(stream); }, function(error) { console.error("Could not get audio stream! " + error); });}function initiateScreenSharing(audioStream){ getScreenId(function (error, sourceId, screen_constraints) { navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia; navigator.getUserMedia(screen_constraints, function (stream) { var constraints = { audio: true, video: { frameRate: { min: 1, ideal: 15, max: 30 }, width: { min: 32, ideal: 50, max: 320 }, height: { min: 32, ideal: 50, max: 320 } } }; var localParticipant = new Participant(sessionId); participants[sessionId] = localParticipant; localVideo = document.getElementById("local_video"); var video = localVideo;
// bind function so that calling 'this' in that function will receive the current instance var options = { localVideo: video, videoStream: stream, mediaConstraints: constraints, onicecandidate: localParticipant.onIceCandidate.bind(localParticipant), sendSource: 'desktop' };
localParticipant.rtcPeer = new kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function (error) { if (error) { return console.error(error); }
// Set localVideo to new object if on IE/Safari localVideo = document.getElementById("local_video");
// initial main video to local first localVideoCurrentId = sessionId; localVideo.muted = true;
console.log("local participant id : " + sessionId); this.generateOffer(localParticipant.offerToReceiveVideo.bind(localParticipant)); }); }, function (error) { console.error(error); }); });}function shareScreen(){ getScreenId(function(error, sourceId, screen_constraints) { if(error == 'not-installed') { alert('Please install Chrome extension. See the link below.'); return; }
if(error == 'installed-disabled') { alert('Please install or enable Chrome extension. Please check "chrome://extensions" page.'); return; }
if(error == 'permission-denied') { alert('Please make sure you are using HTTPs. Because HTTPs is required.'); return; }
console.info('getScreenId callback \n(error, sourceId, screen_constraints) =>\n', error, sourceId, screen_constraints);
var participant = participants[name];
participant.screenShareConstraints =screen_constraints; participant.screenShare = true; var startTime = new Date(); navigator.getUserMedia(screen_constraints,function(videoStream){ console.info(new Date().getTime()); participant.getVideoElement().src = URL.createObjectURL(videoStream); navigator.getUserMedia({video:false,audio:true}, function (audioStream) {// audioStream.addTrack(videoStream.getVideoTracks()[0]) var options = {// localVideo: document.querySelector('video'), audioStream:audioStream, videoStream:videoStream, onicecandidate: participant.onIceCandidate.bind(participant) }
participant.rtcPeer = new kurentoUtils.WebRtcPeer.WebRtcPeerSendonly(options, function (error) { if(error) { return console.error(error); } this.generateOffer (participant.offerToReceiveVideo.bind(participant)); }); },function (error) { console.error(error); }); },function(error){ console.error(error); }) });}for (final UserSession participant : room.getParticipants()) { try { if(!participant.getName().equals(this.getName())){ this.outgoingMedia.connect(participant.incomingMedia.get(this.getName())); } } catch (final Exception e) { log.debug("ROOM {}: participant {} could not be notified", name, participant.getName(), e); } }this.outgoingMedia.addOnIceGatheringDoneListener(new EventListener<OnIceGatheringDoneEvent>() {
@Override public void onEvent(OnIceGatheringDoneEvent event) { log.info("ice candidate gathering done after {} ms ",new Date().getTime()-startTime); } }); this.outgoingMedia.addMediaFlowInStateChangeListener(new EventListener<MediaFlowInStateChangeEvent>() {
@Override public void onEvent(MediaFlowInStateChangeEvent event) { log.info("media flow in state changed : {}",event.getState()); } }); this.outgoingMedia.addIceComponentStateChangeListener(new EventListener<IceComponentStateChangeEvent>() {
@Override public void onEvent(IceComponentStateChangeEvent event) { log.info("ice candidate state changed : {}",event.getState()); } }); this.outgoingMedia.addMediaFlowOutStateChangeListener(new EventListener<MediaFlowOutStateChangeEvent>() {
@Override public void onEvent(MediaFlowOutStateChangeEvent event) { log.info("media flow out state changed : {}",event.getState()); } });var options = { localVideo: video, videoStream: stream, mediaConstraints: constraints, onicecandidate: localParticipant.onIceCandidate.bind(localParticipant), sendSource: 'desktop' };
localParticipant.rtcPeer = new kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function (error)this.outgoingMedia.release();
public void receiveVideoFrom(UserSession sender, String sdpOffer,JsonObject jsonMessage,Room room) throws IOException {
log.info("USER {}: connecting with {} in room {}", this.name, sender.getName(), this.roomName);
log.debug("USER {}: SdpOffer for {} is {}", this.name, sender.getName(), sdpOffer);
final String ipSdpAnswer;
long startTime=new Date().getTime();
if(jsonMessage.has("screenShare")&&jsonMessage.get("screenShare")!=null){
log.info("screen share");
this.outgoingMedia.release();
this.outgoingMedia = new WebRtcEndpoint.Builder(pipeline).build();
this.outgoingMedia.addIceCandidateFoundListener(new EventListener<IceCandidateFoundEvent>() {
@Override
public void onEvent(IceCandidateFoundEvent event) {
JsonObject response = new JsonObject();
response.addProperty("id", "iceCandidate");
response.addProperty("name", name);
response.add("candidate", JsonUtils.toJsonObject(event.getCandidate()));
try {
synchronized (session) {
session.sendMessage(new TextMessage(response.toString()));
}
} catch (IOException e) {
log.debug(e.getMessage());
}
}
});
this.outgoingMedia.addOnIceGatheringDoneListener(new EventListener<OnIceGatheringDoneEvent>() {
@Override
public void onEvent(OnIceGatheringDoneEvent event) {
log.info("ice candidate gathering done after {} ms ",new Date().getTime()-startTime);
}
});
this.outgoingMedia.addMediaFlowInStateChangeListener(new EventListener<MediaFlowInStateChangeEvent>() {
@Override
public void onEvent(MediaFlowInStateChangeEvent event) {
log.info("media flow in state changed : {}",event.getState());
}
});
this.outgoingMedia.addIceComponentStateChangeListener(new EventListener<IceComponentStateChangeEvent>() {
@Override
public void onEvent(IceComponentStateChangeEvent event) {
log.info("ice candidate state changed : {}",event.getState());
}
});
this.outgoingMedia.addMediaFlowOutStateChangeListener(new EventListener<MediaFlowOutStateChangeEvent>() {
@Override
public void onEvent(MediaFlowOutStateChangeEvent event) {
log.info("media flow out state changed : {}",event.getState());
}
});
ipSdpAnswer=this.outgoingMedia.processOffer(sdpOffer);
this.outgoingMedia.gatherCandidates();
for (final UserSession participant : room.getParticipants()) {
try {
if(!participant.getName().equals(this.getName())){
this.outgoingMedia.connect(participant.incomingMedia.get(this.getName()));
}
} catch (final Exception e) {
log.debug("ROOM {}: participant {} could not be notified", name, participant.getName(), e);
}
}
}
else{
ipSdpAnswer = this.getEndpointForUser(sender).processOffer(sdpOffer);
this.getEndpointForUser(sender).gatherCandidates();
}
log.debug("ipSdpAnswer : "+ipSdpAnswer);
final JsonObject scParams = new JsonObject();
scParams.addProperty("id", "receiveVideoAnswer");
scParams.addProperty("name", sender.getName());
scParams.addProperty("sdpAnswer", ipSdpAnswer);
log.debug("USER {}: SdpAnswer for {} is {}", this.name, sender.getName(), ipSdpAnswer);
this.sendMessage(scParams);
log.debug("gather candidates");
}
peer.dispose()