WebSocket handler¶
-
class
bachata.tornado.
MessagesHandler
(application, request, **kwargs)[source]¶ Base WebSocket handler for Tornado.
Default implementation works with authentication free channels, it just generates random channel identifier.
Redefine
get_channel()
in subclass if you want to have channels identifiers based on authenticated user.-
authenticate
()[source]¶ Authenticate and load current user, asyncio coroutine.
Default implementation is empty, so real authentication logic should be implemented in subclass.
-
get_channel
()[source]¶ Get channel string identifier for connection. Method must be defined in subclass.
Implementation example:
class MyMessagesHandler(talkie.tornado.MessagesHandler): def get_channel(self): if self.current_user: return 'channel:%s' % self.current_user.id
-
get_messages_center
()[source]¶ Get messages center for WebSocket. Method must be defined in subclass.
Implementation example:
def get_messages_center(self): # bachata.RedisMessagesCenter instance return self.application.messages
-
open
()[source]¶ Open WebSocket connection and add socket channel to messages center.
It also performs
authenticate()
coroutine call, soget_channel()
can rely on current authenticated user.
-