Files
plexus/docs/functions.md

1.7 KiB

⚙️ Functions & API

Plexus communicates primarily through WebSockets (Socket.io) for real-time interaction.

🔌 Socket Events

📥 Client to Server

  • join({ walletAddress, username }): Register or login a user.
  • sendMessage({ channelId, walletAddress, content, txId }): Send a message to a channel.
  • toggleReaction({ messageId, walletAddress, emoji }): Toggle a reaction on a message.
  • updateUsername({ walletAddress, newUsername, txId }): Change username (simulated cost).
  • getProfile(walletAddress): Fetch user profile and wall posts.
  • updateProfile({ walletAddress, bio, bannerColor }): Update profile details.
  • createPost({ walletAddress, content }): Post a message to the user's wall.

📤 Server to Client

  • userList(users): Broadcast the updated list of online/offline users.
  • newMessage(message): Broadcast a new message to all clients.
  • updateReactions({ messageId, reactions }): Broadcast updated reactions for a message.
  • usernameUpdated({ username }): Confirm a username change to the specific user.
  • profileData(data): Send requested profile data to a user.
  • profileUpdated(data): Confirm profile update.
  • postCreated(post): Confirm post creation.
  • error({ message }): Send error messages to the client.

🌐 REST API

  • GET /api/channels: List all available chat channels.
  • GET /api/messages/:channelId: Fetch the last 100 messages and reactions for a channel.

🛠 Internal Logic

  • Username Authority: The server validates and ensures unique usernames, appending suffixes if necessary.
  • Transaction Simulation: The client simulates a 1.5s delay and a 5% failure rate for "blockchain" transactions.