Skip to content

Commit

Permalink
Merge pull request webrtc#519 from webrtc/fixOverride
Browse files Browse the repository at this point in the history
Fix turn override for android and iOS
  • Loading branch information
KaptenJansson authored Jan 8, 2018
2 parents 15ca189 + d7b3293 commit c6af0c2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 102 deletions.
2 changes: 1 addition & 1 deletion build/ensure_gcloud_sdk_is_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# https://cloud.google.com/sdk/downloads#versioned

GCLOUD_DOWNLOAD_URL = 'https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/'
GCLOUD_SDK_TAR_FILE = 'google-cloud-sdk-138.0.0-linux-x86_64.tar.gz'
GCLOUD_SDK_TAR_FILE = 'google-cloud-sdk-183.0.0-linux-x86_64.tar.gz'
GCLOUD_SDK_INSTALL_FOLDER = 'google-cloud-sdk'
TEMP_DIR = 'temp'
GCLOUD_SDK_PATH = os.path.join(TEMP_DIR, GCLOUD_SDK_INSTALL_FOLDER)
Expand Down
14 changes: 5 additions & 9 deletions src/app_engine/apprtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ def get_hd_default(user_agent):
return 'true'

# iceServers will be filled in by the TURN HTTP request.
def make_pc_config(ice_transports):
def make_pc_config(ice_transports, ice_server_override):
config = {
'iceServers': [],
'bundlePolicy': 'max-bundle',
'rtcpMuxPolicy': 'require'
};
if ice_server_override:
config['iceServers'] = ice_server_override
if ice_transports:
config['iceTransports'] = ice_transports
return config
Expand Down Expand Up @@ -260,22 +262,18 @@ def get_room_parameters(request, room_id, client_id, is_initiator):
# TODO(tkchin): We want to provide a ICE request url on the initial get,
# but we don't provide client_id until a join. For now just generate
# a random id, but we should make this better.
# TODO(jansson): Remove this once CEOD is deprecated.
username = client_id if client_id is not None else generate_random(9)
if len(ice_server_base_url) > 0:
ice_server_url = constants.ICE_SERVER_URL_TEMPLATE % \
(ice_server_base_url, constants.ICE_SERVER_API_KEY)
else:
ice_server_url = ''

# TODO(jansson): Remove this once CEOD is deprecated.
turn_url = constants.TURN_URL_TEMPLATE % \
(constants.TURN_BASE_URL, username, constants.CEOD_KEY)
# If defined it will override the ICE server provider and use the specified
# turn servers directly.
turn_server_override = constants.TURN_SERVER_OVERRIDE
ice_server_override = constants.ICE_SERVER_OVERRIDE

pc_config = make_pc_config(ice_transports)
pc_config = make_pc_config(ice_transports, ice_server_override)
pc_constraints = make_pc_constraints(dtls, dscp, ipv6)
offer_options = {};
media_constraints = make_media_stream_constraints(audio, video,
Expand All @@ -293,8 +291,6 @@ def get_room_parameters(request, room_id, client_id, is_initiator):
'pc_constraints': json.dumps(pc_constraints),
'offer_options': json.dumps(offer_options),
'media_constraints': json.dumps(media_constraints),
'turn_server_override': turn_server_override,
'turn_url': turn_url,
'ice_server_url': ice_server_url,
'ice_server_transports': ice_server_transports,
'include_loopback_js' : include_loopback_js,
Expand Down
10 changes: 2 additions & 8 deletions src/app_engine/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@

# Turn/Stun server override. This allows AppRTC to connect to turn servers
# directly rather than retrieving them from an ICE server provider.
TURN_SERVER_OVERRIDE = []
ICE_SERVER_OVERRIDE = None
# Enable by uncomment below and comment out above, then specify turn and stun
# servers below.
# TURN_SERVER_OVERRIDE = [
# ICE_SERVER_OVERRIDE = [
# {
# "urls": [
# "turn:hostname/IpToTurnServer:19305?transport=udp",
Expand All @@ -39,11 +38,6 @@
# }
# ]

# TODO(jansson): Remove once AppRTCDemo on iOS supports ICE_SERVER.
TURN_BASE_URL = 'https://computeengineondemand.appspot.com'
TURN_URL_TEMPLATE = '%s/turn?username=%s&key=%s'
CEOD_KEY = '4080218913'

ICE_SERVER_BASE_URL = 'https://networktraversal.googleapis.com'
ICE_SERVER_URL_TEMPLATE = '%s/v1alpha/iceconfig?key=%s'
ICE_SERVER_API_KEY = os.environ.get('ICE_SERVER_API_KEY')
Expand Down
69 changes: 2 additions & 67 deletions src/app_engine/probers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""AppRTC Probers.
This module implements CEOD and collider probers.
This module implements collider prober.
"""

import json
Expand All @@ -23,7 +23,7 @@

def is_prober_enabled():
"""Check the application ID so that other projects hosting AppRTC code does
not hit CEOD/Collider unnecessarily."""
not hit Collider unnecessarily."""
return app_identity.get_application_id() == 'apprtc'

def send_alert_email(tag, message):
Expand Down Expand Up @@ -61,70 +61,6 @@ def get_collider_probe_success_key(instance_host):
return 'last_collider_probe_success_' + instance_host


class ProbeCEODPage(webapp2.RequestHandler):
"""Page to probe CEOD server."""

def handle_ceod_response(self, error_message, status_code):
self.response.set_status(status_code)
if error_message is not None:
send_alert_email('CEOD Error', error_message)

logging.warning('CEOD prober error: ' + error_message)
self.response.out.write(error_message)
else:
self.response.out.write('Success!')

def probe_ceod(self):
ceod_url = (constants.TURN_URL_TEMPLATE
% (constants.TURN_BASE_URL, 'prober', constants.CEOD_KEY))
sanitized_url = (constants.TURN_URL_TEMPLATE %
(constants.TURN_BASE_URL, 'prober', '<obscured>'))

error_message = None
result = None
try:
result = urlfetch.fetch(
url=ceod_url, method=urlfetch.GET, deadline=PROBER_FETCH_DEADLINE)
except urlfetch.Error as e:
error_message = ('urlfetch throws exception: %s' % str(e))
return (error_message, 500)

status_code = result.status_code
if status_code != 200:
error_message = ('Unexpected CEOD response: %d, requested URL: %s'
% (result.status_code, sanitized_url))
else:
try:
turn_server = json.loads(result.content)
if (not has_non_empty_string_value(turn_server, 'username') or
not has_non_empty_string_value(turn_server, 'password') or
not has_non_empty_array_value(turn_server, 'uris')):
error_message = ('CEOD response does not contain valid '
'username/password/uris: response = %s, url = %s'
% (result.content, sanitized_url))
status_code = 500
except ValueError as e:
error_message = """
CEOD response cannot be decoded as JSON:
exception = %s,
response = %s,
url = %s
""" % (str(e), result.content, sanitized_url)
status_code = 500
return (error_message, status_code)

def get(self):
if not is_prober_enabled():
return

error_message, status_code = self.probe_ceod()
if error_message is not None:
logging.info("Retry probing CEOD.")
error_message, status_code = self.probe_ceod()

self.handle_ceod_response(error_message, status_code)


class ProbeColliderPage(webapp2.RequestHandler):
"""Page to probe Collider instances."""

Expand Down Expand Up @@ -264,6 +200,5 @@ def probe_collider_instance(self, collider_instance):
error_message, status_code, collider_instance)

app = webapp2.WSGIApplication([
('/probe/ceod', ProbeCEODPage),
('/probe/collider', ProbeColliderPage),
], debug=True)
3 changes: 0 additions & 3 deletions src/web_app/html/index_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,15 @@ <h1>AppRTC</h1>
roomId: '{{ room_id }}',
roomLink: '{{ room_link }}',
{% endif %}

mediaConstraints: {{ media_constraints | safe }},
offerOptions: {{ offer_options | safe }},
peerConnectionConfig: {{ pc_config | safe }},
peerConnectionConstraints: {{ pc_constraints | safe }},
turnRequestUrl: '{{ turn_url }}',
iceServerRequestUrl: '{{ ice_server_url }}',
iceServerTransports: '{{ ice_server_transports }}',
wssUrl: '{{ wss_url }}',
wssPostUrl: '{{ wss_post_url }}',
bypassJoinConfirmation: {{ bypass_join_confirmation }},
turnServerOverride: {{ turn_server_override }},
versionInfo: {{ version_info }},
};

Expand Down
17 changes: 3 additions & 14 deletions src/web_app/js/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ Call.prototype.maybeGetIceServers_ = function() {
var shouldRequestIceServers =
(this.params_.iceServerRequestUrl &&
this.params_.iceServerRequestUrl.length > 0 &&
this.params_.turnServerOverride &&
this.params_.turnServerOverride.length === 0);
this.params_.peerConnectionConfig.iceServers &&
this.params_.peerConnectionConfig.iceServers.length === 0);

var iceServerPromise = null;
if (shouldRequestIceServers) {
Expand All @@ -414,18 +414,7 @@ Call.prototype.maybeGetIceServers_ = function() {
trace(error.message);
}.bind(this));
} else {
if (this.params_.turnServerOverride &&
this.params_.turnServerOverride.length === 0) {
iceServerPromise = Promise.resolve();
} else {
// if turnServerOverride is not empty it will be used for
// turn/stun servers.
iceServerPromise = new Promise(function(resolve) {
this.params_.peerConnectionConfig.iceServers =
this.params_.turnServerOverride;
resolve();
}.bind(this));
}
iceServerPromise = Promise.resolve();
}
return iceServerPromise;
};
Expand Down

0 comments on commit c6af0c2

Please sign in to comment.