from .objects import Feed # from sanic_jwt.decorators import protected feeds = {} def get_feed(feed_name, app): if feed_name in feeds: return feeds.get(feed_name) else: feed = Feed(app=app, feed_name=feed_name) feeds[feed_name] = feed return feed def startup(app): @app.websocket('/feed/') # @protected() async def feed(request, ws, feed_name): # TODO: # - In order to protect the view to authenticated users: # - V1 # - Upon subscription, store the client with a token # - Send the token to the browser through the client # - Client receives the token and submits AJAX call with token # - Endpoint receives the token and using existing authentication to update client as authenticated # - V2 # - Before opening WebSocket, send HTTP request # - Generate ticket with the access credentials # - Return to be stored in browser # - Open WebSocket, send the ticket # - Attach the client connection to the ticket and access credentials channel_name = feed_name.split('__')[-1] print(f'The feed_name: {feed_name}') print(f'The channel_name: {channel_name}') print(ws.__class__.__name__) print(hash(ws)) print(dir(request)) print(request.token) print(request.headers) feed = get_feed(channel_name, request.app) await feed.run(ws)