Skip to content

nodejs + express + socket.io + redis + mongodb

Notifications You must be signed in to change notification settings

vking34/messenger

Repository files navigation

CZ Messenger

Techstack

  • Nodejs: Runtime Environment
  • Express: Web framework
  • Socket.io: Socket library
  • Redis (for scalability): pub/sub events and socket ids between the instances.
  • MongoDB: Message store

API

Rest API

Socket

  1. Handshake:

    • Namespace: /v1/conversations/events

    • Path: /v1/conversations/sockets

    • Query:

      • token
      • user_id
      • user_role: BUYER / SELLER
    • Example:

        let socket = io('https://api.chozoi.com/v1/conversations/events', {
            path: '/v1/conversations/sockets',
            transports: ['websocket'],
            query: {
                token: 'access_token',
                user_id: 'user_id',
                user_role: 'BUYER'
        }});
    
  2. Events:

    • create_room:

      • client:

        • type: Room type. Value: BS
        • buyer: Buyer ID
        • seller: Seller ID
        • shop_id: Shop ID
        • creator: Buyer ID or Seller ID
      • server:

        • room_id: Room ID. Value: <BuyerID>.<SellerID>
        • type: Room type. Value: BS
        • buyer: Buyer ID
        • seller: Seller ID
        • shop_id: Shop ID
        • creator: Buyer ID or Seller ID
    • new_message:

      • client:

        • room_id: Room ID. Value: <BuyerID>.<SellerID>
        • from: Sender ID
        • to: Receiver ID
        • type: TEXT | IMAGE | EMOJI
        • content: Message content
        • client_message_id: (optional) Client generator unique id for server to comfirm
      • server:

        • _id: Message Id generated by server.
        • room_id: Room ID. Value: <BuyerID>.<SellerID>
        • from: Sender ID
        • to: Receiver ID
        • type: TEXT | IMAGE | EMOJI
        • content: Message content
        • client_message_id: (optional) Client generator unique id for server to comfirm
        • created_at: Created time
    • room_deletion:

      • server:
        • room_id
        • seller
        • buyer
        • deletion_role: SELLER | BUYER. Who deleted room.
    • typing:

      • client:
        • room_id: Room ID. Value: <BuyerID>.<SellerID>
        • from: Sender ID
        • to: Receiver ID
      • server:
        • room_id: Room ID. Value: <BuyerID>.<SellerID>
        • from: Sender ID
        • to: Receiver ID
    • stop_typing:

      • client:
        • room_id: Room ID. Value: <BuyerID>.<SellerID>
        • from: Sender ID
        • to: Receiver ID
      • server:
        • room_id: Room ID. Value: <BuyerID>.<SellerID>
        • from: Sender ID
        • to: Receiver ID
    • seen_messages:

      • client:

        • room_id: Room ID. Value: <BuyerID>.<SellerID>
        • from: Sender ID
        • to: Receiver ID
        • last_message_id: ID of the last message
        • last_message_created_at: the created time of the last message
      • server:

        • room_id: Room ID. Value: <BuyerID>.<SellerID>
        • from: Sender ID
        • to: Receiver ID
        • last_message_id: ID of the last message
        • last_message_created_at: the created time of the last message
    • active_user_list: get list of active users

      • server:
        • user_id
        • user_role
        • rooms: Array
          • room_id
          • status: Boolean
    • user_status_change:

      • server:
        • user_id
        • user_role
        • room_id
        • status: Boolean
    • reconnect:

      • client: emit event verify_user:
        • token
        • user_id
        • user_role: BUYER / SELLER
    • verify_user:

      • client:
        • token
        • user_id
        • user_role: BUYER / SELLER
      • server:
        • status: boolean

DB Schema

References

  1. Socket.io

  2. Kafka

About

nodejs + express + socket.io + redis + mongodb

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •