Example #1
0
def on_leave_floor(data):
	log.sock(events.LEAVE_FLOOR)
	current_floor = getFloor(data['floor_id'])
	current_floor.rm_member(data['member_id'])
	current_floor = getFloor(data['floor_id'])
	leave_room(data['floor_id'])
	# socket.emit('member left', {'floor':current_floor.to_list()}, room=data['floor_id'])
	socket.emit('member list update', {'floor members': current_floor.to_list()['floor_members']},room=data['floor_id'])
	if not current_floor.isActive():
		current_floor.set_songlist(thread_holder.find_thread(current_floor.floor_id).songlist)
		thread_holder.update_thread_status(current_floor.floor_id,current_floor.isActive())
Example #2
0
def on_new_message(data):
	log.sock(
		events.MESSAGE_SEND+"\n"+
		log.get_json(data)
	)
	floor_id = data['floor']
	member_id = data['from']
	text = data['message']

	add_message(floor_id, member_id, text)
	log.emit(events.MESSAGE_LIST_UPDATE)
	# print("floor messages", getFloorMessages(floor_id))
	socket.emit(events.MESSAGE_LIST_UPDATE, {
				'floor_messages': getFloorMessages(floor_id)}, room=floor_id)
Example #3
0
def on_login(data):
	log.sock(events.LOGIN)
	if 'fb_t' not in data:
		# print('google_t: ')
		# print(data)
		response = requests.get(
			'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=' + data['google_t'])
		json = response.json()
		# print(json)
		fname = json['given_name'] 
		lname = json['family_name']
		link = json['picture']
		email = json['email']
		mem_found = memberExists_by_email(email)
		# print(mem_found)
		if mem_found:
			mem = getMemberObject_by_email(email)
			log.emit(events.LOGIN_STATUS)
			socket.emit(events.LOGIN_STATUS, userEmit(mem), room=request.sid)
		else:
			new_mem = registerMember(fname,lname,email,link)
			log.emit(events.LOGIN_STATUS)
			socket.emit(events.LOGIN_STATUS, userEmit(new_mem), room=request.sid)

#
	if 'google_t' not in data:
		graph = facebook.GraphAPI(access_token=data['fb_t'],version='2.7')
		js = graph.get_object(id='me', fields='first_name,last_name,email,picture')
		print("js:",js)
		fname = js['first_name']
		lname = js['last_name']
		email = js['email']
		print("***************************EMAIL************************")
		link = js['picture']['data']['url']
		mem_found = memberExists_by_email(email)
		print(mem_found)
		if mem_found:
			mem = getMemberObject_by_email(email)
			log.emit(events.LOGIN_STATUS)
			socket.emit(events.LOGIN_STATUS, userEmit(mem), room=request.sid)
		else:
			new_mem = registerMember(fname,lname,email,link)
			log.emit(events.LOGIN_STATUS)
			socket.emit(events.LOGIN_STATUS, userEmit(new_mem), room=request.sid)
Example #4
0
def on_join_floor(data):
	floor_id = data['floor_id']
	member_id = data['member_id']
	log.sock(events.JOIN_FLOOR+'\n'+
		log.get_mapf(data, log.BOLD, log.CYAN)
	)
	join_room(floor_id)
	floor_to_join = getFloor(floor_id)
	floor_to_join.add_member(member_id)
	# print(floor_to_join.to_list())
	#need to check if floor exists before creating thread.
	if thread_holder.find_thread(floor_id) is None:
		#create a new songlist update thread
		print("thread is none")
		floor_to_join = getFloor(floor_id)
		floor_list = floor_to_join.to_list()
		new_thread = thread_holder.add_thread(floor_to_join.floor_name,floor_to_join.floor_id,floor_list['songlist'])
		#refresh floor object
		time.sleep(2)
		floor_to_join.set_songlist(new_thread.songlist)
		floor_to_join = getFloor(floor_id)
		floor_list = floor_to_join.to_list()
		socket.emit('floor joined', {'floor':floor_list}, room=request.sid)
		# print("floor",json.dumps(floor_list[0:4],indent=4))
		# print("***memlist update***")
		# print(floor_to_join.to_list()['floor_members'])
		socket.emit('member list update', {'floor members': floor_list['floor_members']},room=floor_to_join.floor_id)

	else:
		print("thread is active")
		floor_to_join.set_songlist(thread_holder.find_thread(floor_to_join.floor_id).songlist)
		#refresh floor object after new songlist has been updated
		floor_to_join = getFloor(floor_id)
		print("****floor songlist***")
		floor_list = floor_to_join.to_list()
		# print(json.dumps(floor_list['songlist'][0:3],indent=4))
		socket.emit('floor joined', {'floor':floor_to_join.to_list()}, room=request.sid)
		# print("***memlist update***")
		# print(floor_list['floor_members'])
		socket.emit('member list update', {'floor members': floor_list['floor_members']},room=floor_to_join.floor_id)
Example #5
0
def on_get_floor_list(data):
	log.sock(events.GET_FLOOR_LIST)
	log.emit(events.FLOOR_LIST_UPDATE)
	socket.emit(events.FLOOR_LIST_UPDATE, getPublicFloors())