apprtc: rationalize whitespace

- Remove ^M DOS line endings
- Remove trailing whitespace
- Remove leading 2-space indents from files that have carried this indent since   their contents was removed from within enclosing contexts that required it.
- Add a newline to avoid 82-column line.

R=vikasmarwaha@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4619 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
fischman@webrtc.org
2013-08-26 18:01:28 +00:00
parent 5a035b4279
commit 4498d013f6
4 changed files with 730 additions and 729 deletions

View File

@@ -46,7 +46,8 @@
<body>
<div id="container">
<div id="footer">
Sorry, this room is full. <a href="{{room_link}}">Click here</a> to try again.
Sorry, this room is full.
<a href="{{room_link}}">Click here</a> to try again.
</div>
</div>
<img id="logo" alt="WebRTC" src="images/webrtc_black_20p.png">

View File

@@ -1,27 +1,27 @@
var localVideo;
var miniVideo;
var remoteVideo;
var localStream;
var remoteStream;
var channel;
var pc;
var socket;
var xmlhttp;
var started = false;
var turnDone = false;
var channelReady = false;
var signalingReady = false;
var msgQueue = [];
// Set up audio and video regardless of what devices are present.
var sdpConstraints = {'mandatory': {
var localVideo;
var miniVideo;
var remoteVideo;
var localStream;
var remoteStream;
var channel;
var pc;
var socket;
var xmlhttp;
var started = false;
var turnDone = false;
var channelReady = false;
var signalingReady = false;
var msgQueue = [];
// Set up audio and video regardless of what devices are present.
var sdpConstraints = {'mandatory': {
'OfferToReceiveAudio': true,
'OfferToReceiveVideo': true }};
var isVideoMuted = false;
var isAudioMuted = false;
// Types of gathered ICE Candidates.
var gatheredIceCandidateTypes = { Local: {}, Remote: {} };
var isVideoMuted = false;
var isAudioMuted = false;
// Types of gathered ICE Candidates.
var gatheredIceCandidateTypes = { Local: {}, Remote: {} };
function initialize() {
function initialize() {
console.log('Initializing; room=' + roomKey + '.');
card = document.getElementById('card');
localVideo = document.getElementById('localVideo');
@@ -38,9 +38,9 @@
doGetUserMedia();
// Caller is always ready to create peerConnection.
signalingReady = initiator;
}
}
function openChannel() {
function openChannel() {
console.log('Opening channel.');
var channel = new goog.appengine.Channel(channelToken);
var handler = {
@@ -50,9 +50,9 @@
'onclose': onChannelClosed
};
socket = channel.open(handler);
}
}
function maybeRequestTurn() {
function maybeRequestTurn() {
// Skipping TURN Http request for Firefox version <=22.
// Firefox does not support TURN for version <=22.
if (webrtcDetectedBrowser === 'firefox' && webrtcDetectedVersion <=22) {
@@ -80,9 +80,9 @@
xmlhttp.onreadystatechange = onTurnResult;
xmlhttp.open('GET', turnUrl, true);
xmlhttp.send();
}
}
function onTurnResult() {
function onTurnResult() {
if (xmlhttp.readyState !== 4)
return;
@@ -103,18 +103,18 @@
// If TURN request failed, continue the call with default STUN.
turnDone = true;
maybeStart();
}
}
function resetStatus() {
function resetStatus() {
if (!initiator) {
setStatus('Waiting for someone to join: \
<a href=' + roomLink + '>' + roomLink + '</a>');
} else {
setStatus('Initializing...');
}
}
}
function doGetUserMedia() {
function doGetUserMedia() {
// Call into getUserMedia via the polyfill (adapter.js).
try {
getUserMedia(mediaConstraints, onUserMediaSuccess,
@@ -125,9 +125,9 @@
alert('getUserMedia() failed. Is this a WebRTC capable browser?');
console.log('getUserMedia failed with exception: ' + e.message);
}
}
}
function createPeerConnection() {
function createPeerConnection() {
try {
// Create an RTCPeerConnection via the polyfill (adapter.js).
pc = new RTCPeerConnection(pcConfig, pcConstraints);
@@ -143,9 +143,9 @@
}
pc.onaddstream = onRemoteStreamAdded;
pc.onremovestream = onRemoteStreamRemoved;
}
}
function maybeStart() {
function maybeStart() {
if (!started && signalingReady &&
localStream && channelReady && turnDone) {
setStatus('Connecting...');
@@ -160,48 +160,48 @@
else
calleeStart();
}
}
}
function setStatus(state) {
function setStatus(state) {
document.getElementById('footer').innerHTML = state;
}
}
function doCall() {
function doCall() {
var constraints = mergeConstraints(offerConstraints, sdpConstraints);
console.log('Sending offer to peer, with constraints: \n' +
' \'' + JSON.stringify(constraints) + '\'.')
pc.createOffer(setLocalAndSendMessage, null, constraints);
}
}
function calleeStart() {
function calleeStart() {
// Callee starts to process cached offer and other messages.
while (msgQueue.length > 0) {
processSignalingMessage(msgQueue.shift());
}
}
}
function doAnswer() {
function doAnswer() {
console.log('Sending answer to peer.');
pc.createAnswer(setLocalAndSendMessage, null, sdpConstraints);
}
}
function mergeConstraints(cons1, cons2) {
function mergeConstraints(cons1, cons2) {
var merged = cons1;
for (var name in cons2.mandatory) {
merged.mandatory[name] = cons2.mandatory[name];
}
merged.optional.concat(cons2.optional);
return merged;
}
}
function setLocalAndSendMessage(sessionDescription) {
function setLocalAndSendMessage(sessionDescription) {
// Set Opus as the preferred codec in SDP if Opus is present.
sessionDescription.sdp = preferOpus(sessionDescription.sdp);
pc.setLocalDescription(sessionDescription);
sendMessage(sessionDescription);
}
}
function sendMessage(message) {
function sendMessage(message) {
var msgString = JSON.stringify(message);
console.log('C->S: ' + msgString);
// NOTE: AppRTCClient.java searches & parses this line; update there when
@@ -210,9 +210,9 @@
var xhr = new XMLHttpRequest();
xhr.open('POST', path, true);
xhr.send(msgString);
}
}
function processSignalingMessage(message) {
function processSignalingMessage(message) {
if (!started) {
console.log('peerConnection has not been created yet!');
return;
@@ -237,14 +237,14 @@
} else if (message.type === 'bye') {
onRemoteHangup();
}
}
}
function onChannelOpened() {
function onChannelOpened() {
console.log('Channel opened.');
channelReady = true;
maybeStart();
}
function onChannelMessage(message) {
}
function onChannelMessage(message) {
console.log('S->C: ' + message.data);
var msg = JSON.parse(message.data);
// Since the turn response is async and also GAE might disorder the
@@ -264,15 +264,15 @@
} else {
processSignalingMessage(msg);
}
}
function onChannelError() {
}
function onChannelError() {
console.log('Channel error.');
}
function onChannelClosed() {
}
function onChannelClosed() {
console.log('Channel closed.');
}
}
function onUserMediaSuccess(stream) {
function onUserMediaSuccess(stream) {
console.log('User has granted access to local media.');
// Call the polyfill wrapper to attach the media stream to this element.
attachMediaStream(localVideo, stream);
@@ -280,16 +280,16 @@
localStream = stream;
// Caller creates PeerConnection.
maybeStart();
}
}
function onUserMediaError(error) {
function onUserMediaError(error) {
console.log('Failed to get access to local media. Error code was ' +
error.code);
alert('Failed to get access to local media. Error code was ' +
error.code + '.');
}
}
function iceCandidateType(candidateSDP) {
function iceCandidateType(candidateSDP) {
if (candidateSDP.indexOf("typ relay ") >= 0)
return "TURN";
if (candidateSDP.indexOf("typ srflx ") >= 0)
@@ -297,9 +297,9 @@
if (candidateSDP.indexOf("typ host ") >= 0)
return "HOST";
return "UNKNOWN";
}
}
function onIceCandidate(event) {
function onIceCandidate(event) {
if (event.candidate) {
sendMessage({type: 'candidate',
label: event.candidate.sdpMLineIndex,
@@ -309,37 +309,37 @@
} else {
console.log('End of candidates.');
}
}
}
function onRemoteStreamAdded(event) {
function onRemoteStreamAdded(event) {
console.log('Remote stream added.');
reattachMediaStream(miniVideo, localVideo);
attachMediaStream(remoteVideo, event.stream);
remoteStream = event.stream;
waitForRemoteVideo();
}
}
function onRemoteStreamRemoved(event) {
function onRemoteStreamRemoved(event) {
console.log('Remote stream removed.');
}
}
function onHangup() {
function onHangup() {
console.log('Hanging up.');
transitionToDone();
localStream.stop();
stop();
// will trigger BYE from server
socket.close();
}
}
function onRemoteHangup() {
function onRemoteHangup() {
console.log('Session terminated.');
initiator = 0;
transitionToWaiting();
stop();
}
}
function stop() {
function stop() {
started = false;
signalingReady = false;
isAudioMuted = false;
@@ -347,9 +347,9 @@
pc.close();
pc = null;
msgQueue.length = 0;
}
}
function waitForRemoteVideo() {
function waitForRemoteVideo() {
// Call the getVideoTracks method via adapter.js.
videoTracks = remoteStream.getVideoTracks();
if (videoTracks.length === 0 || remoteVideo.currentTime > 0) {
@@ -357,9 +357,9 @@
} else {
setTimeout(waitForRemoteVideo, 100);
}
}
}
function transitionToActive() {
function transitionToActive() {
remoteVideo.style.opacity = 1;
card.style.webkitTransform = 'rotateY(180deg)';
setTimeout(function() { localVideo.src = ''; }, 500);
@@ -368,9 +368,9 @@
window.onresize();
setStatus('<input type=\'button\' id=\'hangup\' value=\'Hang up\' \
onclick=\'onHangup()\' />');
}
}
function transitionToWaiting() {
function transitionToWaiting() {
card.style.webkitTransform = 'rotateY(0deg)';
setTimeout(function() {
localVideo.src = miniVideo.src;
@@ -379,32 +379,32 @@
miniVideo.style.opacity = 0;
remoteVideo.style.opacity = 0;
resetStatus();
}
}
function transitionToDone() {
function transitionToDone() {
localVideo.style.opacity = 0;
remoteVideo.style.opacity = 0;
miniVideo.style.opacity = 0;
setStatus('You have left the call. <a href=' + roomLink + '>\
Click here</a> to rejoin.');
}
}
function enterFullScreen() {
function enterFullScreen() {
container.webkitRequestFullScreen();
}
}
function noteIceCandidate(location, type) {
function noteIceCandidate(location, type) {
if (gatheredIceCandidateTypes[location][type])
return;
gatheredIceCandidateTypes[location][type] = 1;
updateInfoDiv();
}
}
function getInfoDiv() {
function getInfoDiv() {
return document.getElementById("infoDiv");
}
}
function updateInfoDiv() {
function updateInfoDiv() {
var contents = "<pre>Gathered ICE Candidates\n";
for (var endpoint in gatheredIceCandidateTypes) {
contents += endpoint + ":\n";
@@ -413,18 +413,18 @@
}
var div = getInfoDiv();
div.innerHTML = contents + "</pre>";
}
}
function toggleInfoDivDisplay() {
function toggleInfoDivDisplay() {
var div = getInfoDiv();
if (div.style.display == "block") {
div.style.display = "none";
} else {
div.style.display = "block";
}
}
}
function toggleVideoMute() {
function toggleVideoMute() {
// Call the getVideoTracks method via adapter.js.
videoTracks = localStream.getVideoTracks();
@@ -446,9 +446,9 @@
}
isVideoMuted = !isVideoMuted;
}
}
function toggleAudioMute() {
function toggleAudioMute() {
// Call the getAudioTracks method via adapter.js.
audioTracks = localStream.getAudioTracks();
@@ -470,15 +470,15 @@
}
isAudioMuted = !isAudioMuted;
}
}
// Mac: hotkey is Command.
// Non-Mac: hotkey is Control.
// <hotkey>-D: toggle audio mute.
// <hotkey>-E: toggle video mute.
// <hotkey>-I: toggle Info box.
// Return false to screen out original Chrome shortcuts.
document.onkeydown = function(event) {
// Mac: hotkey is Command.
// Non-Mac: hotkey is Control.
// <hotkey>-D: toggle audio mute.
// <hotkey>-E: toggle video mute.
// <hotkey>-I: toggle Info box.
// Return false to screen out original Chrome shortcuts.
document.onkeydown = function(event) {
var hotkey = event.ctrlKey;
if (navigator.appVersion.indexOf('Mac') != -1)
hotkey = event.metaKey;
@@ -497,10 +497,10 @@
default:
return;
}
}
}
// Set Opus as the default audio codec if it's present.
function preferOpus(sdp) {
// Set Opus as the default audio codec if it's present.
function preferOpus(sdp) {
var sdpLines = sdp.split('\r\n');
// Search for m line.
@@ -529,10 +529,10 @@
sdp = sdpLines.join('\r\n');
return sdp;
}
}
// Set Opus in stereo if stereo is enabled.
function addStereo(sdp) {
// Set Opus in stereo if stereo is enabled.
function addStereo(sdp) {
var sdpLines = sdp.split('\r\n');
// Find opus payload.
@@ -562,15 +562,15 @@
sdp = sdpLines.join('\r\n');
return sdp;
}
}
function extractSdp(sdpLine, pattern) {
function extractSdp(sdpLine, pattern) {
var result = sdpLine.match(pattern);
return (result && result.length == 2)? result[1]: null;
}
}
// Set the selected codec to the first in m line.
function setDefaultCodec(mLine, payload) {
// Set the selected codec to the first in m line.
function setDefaultCodec(mLine, payload) {
var elements = mLine.split(' ');
var newLine = new Array();
var index = 0;
@@ -581,10 +581,10 @@
newLine[index++] = elements[i];
}
return newLine.join(' ');
}
}
// Strip CN from sdp before CN constraints is ready.
function removeCN(sdpLines, mLineIndex) {
// Strip CN from sdp before CN constraints is ready.
function removeCN(sdpLines, mLineIndex) {
var mLineElements = sdpLines[mLineIndex].split(' ');
// Scan from end for the convenience of removing an item.
for (var i = sdpLines.length-1; i >= 0; i--) {
@@ -602,16 +602,16 @@
sdpLines[mLineIndex] = mLineElements.join(' ');
return sdpLines;
}
}
// Send BYE on refreshing(or leaving) a demo page
// to ensure the room is cleaned for next session.
window.onbeforeunload = function() {
// Send BYE on refreshing(or leaving) a demo page
// to ensure the room is cleaned for next session.
window.onbeforeunload = function() {
sendMessage({type: 'bye'});
}
}
// Set the video diplaying in the center of window.
window.onresize = function(){
// Set the video diplaying in the center of window.
window.onresize = function(){
var aspectRatio;
if (remoteVideo.style.opacity === '1') {
aspectRatio = remoteVideo.videoWidth/remoteVideo.videoHeight;
@@ -632,4 +632,4 @@
containerDiv.style.height = videoHeight + 'px';
containerDiv.style.left = (innerWidth - videoWidth) / 2 + 'px';
containerDiv.style.top = (innerHeight - videoHeight) / 2 + 'px';
};
};