Allow ?audio=false&video=false to be used in combination to instantiate a recv-only client.

R=braveyao@webrtc.org, juberti@google.com

Review URL: https://webrtc-codereview.appspot.com/6819004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5425 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andresp@webrtc.org 2014-01-24 12:25:50 +00:00
parent fd0f267bb1
commit 24999d44c2

View File

@ -1,6 +1,7 @@
var localVideo; var localVideo;
var miniVideo; var miniVideo;
var remoteVideo; var remoteVideo;
var hasLocalStream;
var localStream; var localStream;
var remoteStream; var remoteStream;
var channel; var channel;
@ -43,9 +44,18 @@ function initialize() {
// changing here. // changing here.
openChannel(); openChannel();
maybeRequestTurn(); maybeRequestTurn();
doGetUserMedia();
// Caller is always ready to create peerConnection. // Caller is always ready to create peerConnection.
signalingReady = initiator; signalingReady = initiator;
if (mediaConstraints.audio === false &&
mediaConstraints.video === false) {
hasLocalStream = false;
maybeStart();
} else {
hasLocalStream = true;
doGetUserMedia();
}
} }
function openChannel() { function openChannel() {
@ -159,13 +169,18 @@ function createPeerConnection() {
} }
function maybeStart() { function maybeStart() {
if (!started && signalingReady && if (!started && signalingReady && channelReady && turnDone &&
localStream && channelReady && turnDone) { (localStream || !hasLocalStream)) {
setStatus('Connecting...'); setStatus('Connecting...');
console.log('Creating PeerConnection.'); console.log('Creating PeerConnection.');
createPeerConnection(); createPeerConnection();
console.log('Adding local stream.');
pc.addStream(localStream); if (hasLocalStream) {
console.log('Adding local stream.');
pc.addStream(localStream);
} else {
console.log('Not sending any stream.');
}
started = true; started = true;
if (initiator) if (initiator)
@ -222,7 +237,19 @@ function setRemote(message) {
message.sdp = addStereo(message.sdp); message.sdp = addStereo(message.sdp);
message.sdp = maybePreferAudioSendCodec(message.sdp); message.sdp = maybePreferAudioSendCodec(message.sdp);
pc.setRemoteDescription(new RTCSessionDescription(message), pc.setRemoteDescription(new RTCSessionDescription(message),
onSetSessionDescriptionSuccess, onSetSessionDescriptionError); onSetRemoteDescriptionSuccess, onSetSessionDescriptionError);
function onSetRemoteDescriptionSuccess() {
console.log("Set remote session description success.");
// By now all addstream events for the setRemoteDescription have fired.
// So we can know if the peer is sending any stream or is only receiving.
if (remoteStream) {
waitForRemoteVideo();
} else {
console.log("Not receiving any stream.");
transitionToActive();
}
}
} }
function sendMessage(message) { function sendMessage(message) {
@ -301,10 +328,13 @@ function onUserMediaSuccess(stream) {
} }
function onUserMediaError(error) { function onUserMediaError(error) {
console.log('Failed to get access to local media. Error code was ' + var msg = 'Failed to get access to local media. Error code was ' +
error.code); error.code + '. Continuing without sending a stream.';
alert('Failed to get access to local media. Error code was ' + console.log(msg);
error.code + '.'); alert(msg);
hasLocalStream = false;
maybeStart();
} }
function onCreateSessionDescriptionError(error) { function onCreateSessionDescriptionError(error) {
@ -343,10 +373,8 @@ function onIceCandidate(event) {
function onRemoteStreamAdded(event) { function onRemoteStreamAdded(event) {
console.log('Remote stream added.'); console.log('Remote stream added.');
reattachMediaStream(miniVideo, localVideo);
attachMediaStream(remoteVideo, event.stream); attachMediaStream(remoteVideo, event.stream);
remoteStream = event.stream; remoteStream = event.stream;
waitForRemoteVideo();
} }
function onRemoteStreamRemoved(event) { function onRemoteStreamRemoved(event) {
@ -384,6 +412,7 @@ function stop() {
isVideoMuted = false; isVideoMuted = false;
pc.close(); pc.close();
pc = null; pc = null;
remoteStream = null;
msgQueue.length = 0; msgQueue.length = 0;
} }
@ -398,6 +427,7 @@ function waitForRemoteVideo() {
} }
function transitionToActive() { function transitionToActive() {
reattachMediaStream(miniVideo, localVideo);
remoteVideo.style.opacity = 1; remoteVideo.style.opacity = 1;
card.style.webkitTransform = 'rotateY(180deg)'; card.style.webkitTransform = 'rotateY(180deg)';
setTimeout(function() { localVideo.src = ''; }, 500); setTimeout(function() { localVideo.src = ''; }, 500);