Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GoogleChrome/webrtc into …
Browse files Browse the repository at this point in the history
…closure
  • Loading branch information
Jiayang Liu committed Jan 21, 2015
2 parents aa385fc + f6c7d1a commit 9c515e2
Show file tree
Hide file tree
Showing 25 changed files with 914 additions and 138 deletions.
14 changes: 10 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ module.exports = function(grunt) {
jscs: {
src: 'samples/web/content/**/*.js',
options: {
config: 'google', // as per Google style guide – could use '.jscsrc' instead
preset: 'google', // as per Google style guide – could use '.jscsrc' instead
'excludeFiles': [
'samples/web/content/manual-test/**/*',
'samples/web/content/apprtc/js/compiled/*.js',
'samples/web/content/apprtc/js/vr.js',
'samples/web/content/apprtc/js/stereoscopic.js',
'samples/web/content/getusermedia/desktopcapture/extension/content-script.js',
'samples/web/content/testrtc/bower_components/**'
],
requireCurlyBraces: ['if']
'samples/web/content/testrtc/bower_components/**',
// TODO (chuckhays) : remove these exclusions after code passes.
'samples/web/content/testrtc/**/*.js',
'samples/web/content/getusermedia/**/*.js',
'samples/web/content/peerconnection/**/*.js',
'samples/web/content/datachannel/**/*.js'
]
}
},

Expand Down Expand Up @@ -135,9 +139,11 @@ module.exports = function(grunt) {
'samples/web/content/apprtc/js/call.js',
'samples/web/content/apprtc/js/infobox.js',
'samples/web/content/apprtc/js/peerconnectionclient.js',
'samples/web/content/apprtc/js/roomselection.js',
'samples/web/content/apprtc/js/sdputils.js',
'samples/web/content/apprtc/js/signalingchannel.js',
'samples/web/content/apprtc/js/stats.js',
'samples/web/content/apprtc/js/storage.js',
'samples/web/content/apprtc/js/util.js',
]
},
Expand Down
28 changes: 17 additions & 11 deletions samples/web/content/apprtc/apprtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def get_room_parameters(request, room_id, client_id, is_initiator):
username = client_id if client_id is not None else generate_random(9)
if len(turn_base_url) > 0:
turn_url = constants.TURN_URL_TEMPLATE % (turn_base_url, username, constants.CEOD_KEY)

pc_config = make_pc_config(ice_transports)
pc_constraints = make_pc_constraints(dtls, dscp, ipv6)
offer_constraints = { 'mandatory': {}, 'optional': [] }
Expand Down Expand Up @@ -371,7 +371,7 @@ def add_client_to_room(host, room_id, client_id, is_loopback):
room.add_client(client_id, Client(is_initiator))
other_client.clear_messages()

if memcache_client.cas(key, room):
if memcache_client.cas(key, room, constants.ROOM_MEMCACHE_EXPIRATION_SEC):
logging.info('Added client %s in room %s, retries = %d' \
%(client_id, room_id, retries))
success = True
Expand Down Expand Up @@ -404,7 +404,7 @@ def remove_client_from_room(host, room_id, client_id):
else:
room = None

if memcache_client.cas(key, room):
if memcache_client.cas(key, room, constants.ROOM_MEMCACHE_EXPIRATION_SEC):
logging.info('Removed client %s from room %s, retries=%d' \
%(client_id, room_id, retries))
return {'error': None, 'room_state': str(room)}
Expand Down Expand Up @@ -434,7 +434,7 @@ def save_message_from_client(host, room_id, client_id, message):

client = room.get_client(client_id)
client.add_message(text)
if memcache_client.cas(key, room):
if memcache_client.cas(key, room, constants.ROOM_MEMCACHE_EXPIRATION_SEC):
logging.info('Saved message for client %s:%s in room %s, retries=%d' \
%(client_id, str(client), room_id, retries))
return {'error': None, 'saved': True}
Expand Down Expand Up @@ -515,13 +515,18 @@ def post(self, room_id):
logging.info('Room ' + room_id + ' has state ' + result['room_state'])

class MainPage(webapp2.RequestHandler):
def write_response(self, target_page, params={}):
template = jinja_environment.get_template(target_page)
content = template.render(params)
self.response.out.write(content)

def get(self):
"""Redirects to a room page."""
room_id = generate_random(8)
redirect = '/r/' + room_id
redirect = append_url_arguments(self.request, redirect)
self.redirect(redirect)
logging.info('Redirecting visitor to base URL to ' + redirect)
"""Renders index.html."""
# Parse out parameters from request.
params = get_room_parameters(self.request, None, None, None)
# room_id/room_link will not be included in the returned parameters
# so the client will show the landing page for room selection.
self.write_response('index.html', params)

class RoomPage(webapp2.RequestHandler):
def write_response(self, target_page, params={}):
Expand All @@ -542,14 +547,15 @@ def get(self, room_id):
return
# Parse out room parameters from request.
params = get_room_parameters(self.request, room_id, None, None)
# room_id/room_link will be included in the returned parameters
# so the client will launch the requested room.
self.write_response('index.html', params)

class ParamsPage(webapp2.RequestHandler):
def get(self):
# Return room independent room parameters.
params = get_room_parameters(self.request, None, None, None)
self.response.write(json.dumps(params))


app = webapp2.WSGIApplication([
('/', MainPage),
Expand Down
12 changes: 8 additions & 4 deletions samples/web/content/apprtc/apprtc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ def verifyRegisterSuccessResponse(self, response, is_initiator, room_id):
self.assertEqual([], params['error_messages'])
return caller_id

def testConnectingWithoutRoomIdRedirectsToGeneratedRoom(self):
def testConnectingWithoutRoomIdServesIndex(self):
response = self.makeGetRequest('/')
self.assertEqual(response.status_int, 302)
redirect_location = response.headers['Location']
self.assertRegexpMatches(redirect_location, '^http://localhost/r/[\d]+$')
self.assertEqual(response.status_int, 200)
self.assertNotRegexpMatches(response.body, 'roomId:')

def testConnectingWithRoomIdServesIndex(self):
response = self.makeGetRequest('/r/testRoom')
self.assertEqual(response.status_int, 200)
self.assertRegexpMatches(response.body, 'roomId: \'testRoom\'')

def testRegisterAndBye(self):
room_id = 'foo'
# Register the caller.
Expand Down
1 change: 1 addition & 0 deletions samples/web/content/apprtc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
This module contains the constants used in AppRTC Python modules.
"""
ROOM_MEMCACHE_EXPIRATION_SEC = 60 * 60 * 24

LOOPBACK_CLIENT_ID = 'LOOPBACK_CLIENT_ID'

Expand Down
63 changes: 63 additions & 0 deletions samples/web/content/apprtc/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ body {
margin: 0;
padding: 0;
width: 100%;
color: #fff;
}

#remote-canvas {
Expand Down Expand Up @@ -164,6 +165,68 @@ label {
z-index: 1;
}

/*////// room selection start ///////////////////*/
#recent-rooms-list {
list-style-type: none;
}

button {
background-color: #69b;
border: none;
border-radius: 2px;
color: white;
font-size: 0.8em;
margin: 0 10px 20px 0;
width: 90px;
padding: 0.5em 0.7em 0.6em 0.7em;
}

button:active {
background-color: #7ac;
}

button:hover {
background-color: #7ac;
}

button[disabled] {
color: #ccc;
}

button[disabled]:hover {
background-color: #69b;
}

input[type=text] {
border: 3px solid #444;
border-radius: 2px;
font-size: 0.8em;
background-color: #000000;
color: #fff;
font-weight: 300;
padding:.4em;
margin-right: 20px;
}

h1 {
font-weight: 300;
margin: 0 0 0.8em 0;
padding: 0 0 0.2em 0;
}

div#room-selection {
margin: 0 auto 0 auto;
padding: 1em 1.5em 1.3em 1.5em;
}

p {
color: #eee;
font-weight: 300;
line-height: 1.6em;
}

/*////// room selection end /////////////////////*/

/*////// icons CSS start ////////////////////////*/

#icons {
Expand Down
19 changes: 17 additions & 2 deletions samples/web/content/apprtc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<meta name="mobile-web-app-capable" content="yes">
<meta id="theme-color" name="theme-color" content="#362A6C">

<link rel="icon" sizes="192x192" href="images/webrtc-icon-192x192.png">
<link rel="icon" sizes="192x192" href="/images/webrtc-icon-192x192.png">
{% if not chromeapp %}
<link rel="canonical" href="{{ room_link }}">
{% endif %}
Expand All @@ -39,6 +39,20 @@
<video id="local-video" autoplay muted></video>
</div>

<div id="room-selection" class="hidden">
<h1>AppRTC</h1>
<p id="instructions">Please enter a room name.</p>
<div>
<input type="text" id="room-id-input"/>
<button id="join-button">Join</button>
<button id="random-button">Random</button>
</div>
<div id="recent-rooms">
<p>Recently used rooms:</p>
<ul id="recent-rooms-list"></ul>
</div>
</div>

<footer>
<div id="sharing-div">
<div id="room-link">Waiting for someone to join this room: <a id="room-link-href" href="{{ room_link }}" target="_blank">{{ room_link }}</a></div>
Expand Down Expand Up @@ -98,9 +112,10 @@
var loadingParams = {
errorMessages: {{ error_messages }},
isLoopback: {{ is_loopback }},

{% if room_id %}
roomId: '{{ room_id }}',
roomLink: '{{ room_link }}',
{% endif %}

mediaConstraints: {{ media_constraints | safe }},
offerConstraints: {{ offer_constraints | safe }},
Expand Down
6 changes: 5 additions & 1 deletion samples/web/content/apprtc/js/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Javascript object hierarchy #

AppController: The controller that connects the UI and the model "Call". It owns
Call and InfoBox.
Call, InfoBox and RoomSelection.

Call: Manages everything needed to make a call. It owns SignalingChannel and
PeerConnectionClient.
Expand All @@ -11,3 +11,7 @@ SignalingChannel: Wrapper of the WebSocket connection.
PeerConnectionClient: Wrapper of RTCPeerConnection.

InfoBox: Wrapper of the info div utilities.

RoomSelection: Wrapper for the room selection UI. It owns Storage.

Storage: Wrapper for localStorage/Chrome app storage API.
Loading

0 comments on commit 9c515e2

Please sign in to comment.