async def ritualPage(req): if 'facebookexternalhit' in req.headers.get('User-Agent', ''): return web.Response(status=403) name = req.match_info.get('name', 'error') if name not in active: return web.Response(text="Not Found", status=404) islead = req.url.path.endswith('/lead') if hasattr(active[name], 'participants'): foundLogin = connectUserRitual(req, active[name], islead) if not foundLogin: res = web.Response(body=tpl('html/login.html', errorhandler=error_handler), content_type='text/html') res.set_cookie('LastRitual', name) return res clientId = random_token() active[name].clients[clientId] = struct( chatQueue=asyncio.Queue(), lastSeen=datetime.now(), isStreamer=('streamer' in req.query), room=None, name='NotYetNamed', ) if active[name].welcome: active[name].clients[clientId].welcomed = False if 'fake' in req.query: active[name].clients[clientId].lastSeen = datetime(9999, 9, 9, 9, 9, 9) active[name].clients[clientId].welcomed = True for datum in active[name].allChats[-50:]: active[name].clients[clientId].chatQueue.put_nowait(datum) if hasattr(active[name], 'current_video_room'): await assign_twilio_room(active[name], clientId) else: video_room_id = '' video_token = '' if hasattr(active[name], 'participants') or hasattr( active[name], 'current_video_room'): for i, task in active[name].reqs.items(): task.cancel() return web.Response(body=tpl( 'html/client.html', name=name, clientId=clientId, errorhandler=error_handler, cclass=('shrunk' if hasattr(active[name], 'participants') or hasattr(active[name], 'current_video_room') else ''), ratio=str(active[name].ratio), breserve=active[name].breserve, islead=str(islead).lower(), bkgAll=str(active[name].bkgAll).lower(), rotate=str(active[name].rotate).lower(), videos=''.join( f'<video class="hidden" src="{video}" playsinline preload="auto"></video>' for video in active[name].videos), intercomappid=intercom_app_id, ), content_type='text/html', charset='utf8')
async def homepage(req): if 'RITUAL_NAME' in secrets and 'controlpanel' not in req.query: ritual_name = secrets['RITUAL_NAME'] if ritual_name in active: raise web.HTTPFound(f'/{ritual_name}/partake') else: return web.Response(text=tpl('html/notready.html'), content_type='text/html') l = '\n'.join([ '<li><a href="/%s/partake">%s (%s)</a>'%(x,x,active[x].script) for x in active.keys() ]) s = '\n'.join([ '<option>%s</option>'%(x.replace('examples/','')) for x in glob('examples/*') ]) html = tpl('html/index.html', list=l, scripts=s) return web.Response(text=html, content_type='text/html')
async def ritualPage(req): name = req.match_info.get('name', 'error') if name not in active: return web.Response(text="Not Found", status=404) islead = req.url.path.endswith('/lead') if hasattr(active[name], 'participants'): foundLogin = connectUserRitual(req, active[name], islead) if not foundLogin: res = web.Response(body=open('html/login.html').read(), content_type='text/html') res.set_cookie('LastRitual', name) return res clientId = random_token() active[name].clients[clientId] = struct(chatQueue=asyncio.Queue()) for datum in active[name].allChats[-50:]: active[name].clients[clientId].chatQueue.put_nowait(datum) if hasattr(active[name], 'current_video_room'): async with active[name].video_room_lock: if not active[name].current_video_room: active[name].current_video_room = await asyncio.get_event_loop( ).run_in_executor(None, twilio_client.video.rooms.create) video_room_id = active[name].current_video_room.unique_name active[name].population_of_current_video_room += 1 if active[name].population_of_current_video_room == 26: active[name].current_video_room = None active[name].population_of_current_video_room = 0 token_builder = twilio_access_token.AccessToken( account_sid=secrets['TWILIO_ACCOUNT_SID'], signing_key_sid=secrets['TWILIO_API_KEY'], secret=secrets['TWILIO_API_SECRET'], identity=clientId, ) token_builder.add_grant(twilio_grants.VideoGrant(room=video_room_id)) active[name].clients[clientId].video_token = token_builder.to_jwt( ).decode() active[name].clients[clientId].room = video_room_id else: video_room_id = '' video_token = '' if hasattr(active[name], 'participants') or hasattr( active[name], 'current_video_room'): for i, task in active[name].reqs.items(): task.cancel() return web.Response(body=tpl( 'html/client.html', name=name, clientId=clientId, cclass=('shrunk' if hasattr(active[name], 'participants') or video_room_id else ''), ratio=str(active[name].ratio), islead=str(islead).lower(), bkgAll=str(active[name].bkgAll).lower(), rotate=str(active[name].rotate).lower()), content_type='text/html', charset='utf8')
async def homepage(req): l = '\n'.join([ '<li><a href="/%s/partake">%s (%s)</a>' % (x, x, active[x].script) for x in active.keys() ]) s = '\n'.join([ '<option>%s</option>' % (x.replace('examples/', '')) for x in glob('examples/*') ]) html = tpl('html/index.html', list=l, scripts=s) return web.Response(text=html, content_type='text/html')
async def ritualPage(req): name = req.match_info.get('name','error') if name not in active: return web.Response(text="Not Found", status=404) islead = req.url.path.endswith('/lead') if hasattr(active[name],'participants'): foundLogin = connectUserRitual(req, active[name], islead) if not foundLogin: res = web.Response(body=open('html/login.html').read(), content_type='text/html') res.set_cookie('LastRitual', name) return res return web.Response(body=tpl('html/client.html', name=name, cclass=hasattr(active[name],'participants') and 'shrunk' or '', ratio=str(active[name].ratio), islead=str(islead).lower(), bkgAll=str(active[name].bkgAll).lower(), rotate=str(active[name].rotate).lower()), content_type='text/html', charset='utf8')
async def manageLogins(req): return web.Response(body=tpl('html/manage.html', errorhandler=error_handler.replace( '%clientId%', '')), content_type='text/html')
async def manageLogins(req): return web.Response(body=tpl('html/manage.html', errorhandler=error_handler), content_type='text/html')