Websockets in NestJs (Real-Time Chat App)

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 มิ.ย. 2024
  • We learn how to setup a websocket gateway in Nesjts, to subscribe to events, and emit messages. We learn different ways to broadcast messages, and consume them from a client, while building a simple chatting app
    Donations: buymeacoffee.com/computerix
    Timestamps:
    --------------------
    0:00- Creating the Websocket Gateway
    2:38- Listening to events
    5:37- Emitting Messages to the client
    7:55- Brodcasting messages + Websocket Server Instance
    10:45- Handling Socket Connections / Disconnect
    14:10- Chat App Client Side + Enhancements
    17:35- Testing the Real time Chat App
    19:50- Side Notes
    20:45- Recap

ความคิดเห็น • 22

  • @piyumalchandrarathna5169
    @piyumalchandrarathna5169 6 วันที่ผ่านมา

    Thank you bro. subscribed

  • @Naya-ss7vs
    @Naya-ss7vs หลายเดือนก่อน

    We missed seeing content from you! So helpful and informative as usual. Keep up the good work 🤝🏻

    • @Computerix
      @Computerix  หลายเดือนก่อน

      Thank you !! :)

  • @codexamofficial
    @codexamofficial หลายเดือนก่อน

    Thanks bro! Well Explained ✅
    Subscribed and looking forward to more of your videos. 💌

    • @Computerix
      @Computerix  หลายเดือนก่อน +1

      I'm glad if was helpful 🤝🏻
      More coming soon !

  • @abdulrahmanarmashi6954
    @abdulrahmanarmashi6954 หลายเดือนก่อน

    Very awesome and easy to understand, i hope you implement more features like creating a group, adding people to the group, and storing in database and more ....
    Thank you

    • @Computerix
      @Computerix  หลายเดือนก่อน +3

      Thanks for the feedback! I'm planning on making a part 2, with authentication, rooms, and a database!

    • @abdulrahmanarmashi6954
      @abdulrahmanarmashi6954 หลายเดือนก่อน +1

      @Computerix That is very good, so i am waiting for part 2 🤩

    • @ismaeltinta6118
      @ismaeltinta6118 14 วันที่ผ่านมา

      @@Computerix waiting for part 2. subscribed. thanks for your content. your teaching style is great.

  • @joeatallah338
    @joeatallah338 หลายเดือนก่อน

    Super informative 💯

    • @Computerix
      @Computerix  หลายเดือนก่อน

      I'm glad!

  • @smileVideos-mb1yy
    @smileVideos-mb1yy หลายเดือนก่อน

    very nice thank

  • @quangluu79
    @quangluu79 หลายเดือนก่อน

    Top!!!

    • @Computerix
      @Computerix  หลายเดือนก่อน

      Thank you for your continuous support! 😁

  • @Naya-ss7vs
    @Naya-ss7vs หลายเดือนก่อน

    *grabs my notebook*

    • @Computerix
      @Computerix  หลายเดือนก่อน

      😂💪

  • @Naya-ss7vs
    @Naya-ss7vs หลายเดือนก่อน

    Can you please tell us how we can use it practically? What are situations we might need this in?

    • @Computerix
      @Computerix  หลายเดือนก่อน

      Websockets are mostly used for chatting apps / Live feeds - dashboards/ Multiplayer games / Real time editing tools that allow multiple users to edit at the same time (like figma).. You can basically use websockets for anything that requires real-time communication

  • @AHMED-nd7zt
    @AHMED-nd7zt หลายเดือนก่อน

    so what if i want it happend in privet chat between just to user

    • @Computerix
      @Computerix  หลายเดือนก่อน

      You can send a message directly to one user by sending it to their socket Id, as such : socket.to(otherSocket.id).emit('event name', 'message')

    • @AHMED-nd7zt
      @AHMED-nd7zt หลายเดือนก่อน

      @@Computerix
      so if i have user in my data base with id of 1
      how can i know which socket.id is related to him

    • @Computerix
      @Computerix  หลายเดือนก่อน +1

      @@AHMED-nd7zt Typically, you'd be logged in as a user and will possess a JWT token that you will send in the headers when connecting to the websockets server from your client.
      The backend will validate that JWT token from "socket.handshake.headers.authorization" (for example), and the token will include the userId when decoded.. You can then attach that userId on that specific socket using socket.data.userId = userId
      You can also store the socketId in your database if needed for the duration of that session.
      I am gonna make a video soon that will include users and authentication and rooms, etc.. So if you have any more confusions, they should be sorted in the video!