10:35 am

PragetX

InfinityTalks

Solved some sync async issues.

Made handlers for chat logic

 
    async def chat_handler(self, event):
        await self.send_json(event["data"])
        
 
    async def chat_message(self, event):
        await self.send_json(event["data"])
 
    async def chat_accepted(self, event):
        print("chat_accepted event")
        print("event: ", event)
        await self.send_json(event["data"])
 
    async def chat_paused(self, event):
        await self.send_json(event["data"])
 
    async def chat_resumed(self, event):
        await self.send_json(event["data"])
 
    async def chat_request(self, event):
        await self.send_json(event["data"])
 
 

Lots of Confusion to set up a room for a user and a listener.

What to do

Try to remake the flow but stuck in midway. Cuz no clear room reference in this diagram.

Then I found about AuthMiddleWareStack which technically is the stack of AuthMiddleWare, SessionMiddleware, and CookieMiddleWare.

But that doesn’t matter. Cuz we’re using JWT Authemtication

But had to waste my time trying to authenticate the user due to misconfiguration of settings in setting.py

REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework_simplejwt.authentication.JWTAuthentication",
    ),
}
 
SIMPLE_JWT = {
    "ACCESS_TOKEN_LIFETIME": timedelta(days=1),
    "REFRESH_TOKEN_LIFETIME": timedelta(days=1),
}
 
CORS_ALLOW_ALL_ORIGINS = True
 
AUTH_USER_MODEL = "admin_panel.User"
 
REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "apps.admin_panel.customs.authentications.JWTAuthentication",
    )
}

I was using the first AuthenticationClass

While there’s a second one.

Now I have to setup Custom Authentication for my channels in websocket.

<<Yesterday Tomorrow>>


Links : Tags : Year : 2024 Month : March 24, March Date : 20th March, Wednesday, 2024, 20th March Category : Daily