Beispiel #1
0
def request_stream (form):
	logging.debug("request")
	#FIXME: next line is a hack. os.envrion is not available from fastcgi
	db.log_event(10, form)
	hostname_without_port = str(settings.config["external_host_name_without_port"])

	if is_listener_in_range_of_stream(form):
		udid = ""
		if form.has_key('udid'):
			udid = form['udid']
		sessionid = db.create_session(udid)
		command = ['/usr/local/bin/streamscript', '--sessionid', str(sessionid)]

		for p in ['categoryid', 'subcategoryid', 'questionid', 'usertypeid', 'genderid', 'demographicid', 'ageid', 'latitude', 'longitude', 'audioformat']:
			if form.has_key(p) and form[p]:
				command.extend(['--' + p, form[p].replace("\t", ",")])

		if form.has_key('config'):
			command.extend(['--configfile', os.path.join(settings.configdir, form['config'])])

		audio_format = 'MP3'
		if form.has_key('audioformat'):
			audio_format = form['audioformat'].upper()

		apache_safe_daemon_subprocess(command)
		wait_for_stream(sessionid, audio_format)

		#TODO: must return streamurl and sessionid here
		#	do NOT brake scapes.py
		return {
			"SESSIONID" : sessionid,
			"STREAM_URL" : "http://" + hostname_without_port + ":" + \
				str(settings.config["icecast_port"]) + \
				icecast_mount_point(sessionid, audio_format),
		}
	else:
		msg = "This application is designed to be used in specific geographic locations.  Apparently your phone thinks you are not at one of those locations, so you will hear a sample audio stream instead of the real deal.  If you think your phone is incorrect, please restart Scapes and it will probably work.  Thanks for checking it out!"
		if form.has_key('out_of_range_message'):
			msg = form['out_of_range_message']
			
		url = "http://" + hostname_without_port + ":" + \
				str(settings.config["icecast_port"]) + \
				"/outofrange.mp3"
		if form.has_key('categoryid'):
			dburl = db.get_out_of_range_url_for_categoryid(form["categoryid"])
			if(dburl):
				url = dburl
		
		return {
			"SESSIONID" : "-1",		        
			'STREAM_URL' : url ,
			'USER_ERROR_MESSAGE' : msg
		}
Beispiel #2
0
def get_config(request):
	form = request.GET
	try:
		hostname_without_port = str(settings.config["external_host_name_without_port"])
	except KeyError:
		raise roundexception.RoundException("Roundware configuration file is missing 'external_host_name_without_port' key. ")
	#check params
	if not form.has_key('project_id'):
		raise roundexception.RoundException("a project_id is required for this operation")
	project = models.Project.objects.get(id=form.get('project_id'))

	if not form.has_key('device_id') or (form.has_key('device_id') and form['device_id']==""):
		device_id = str(uuid.uuid4())
	else:
		device_id = form.get('device_id')
		
		
	session_id = db.create_session(device_id,project)
	
	sharing_url = str.format("http://{0}/roundware/?operation=view_envelope&envelopeid=[id]", hostname_without_port)
	
	response = [ 
	        { "device":{"device_id":device_id}},
	        { "session":{"session_id":session_id}},
	        { "project":{
	                "project_id":project.id, 
	                "project_name":project.name,
	                "audio_format":project.audio_format,
	                "max_recording_length":project.max_recording_length,
	                "sharing_message":project.sharing_message,
	                "sharing_url":sharing_url,
	                "listen_questions_dynamic":project.listen_questions_dynamic,
	                "speak_questions_dynamic":project.speak_questions_dynamic,
	                }},
	        { "server":{	                
	                "version": "2.0"}}
	]	
	db.log_event('start_session',session_id,None)
	return response