Skip to content

bnlang/bnlang-simple-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bnlang Simple Chat

A minimal real-time chat built with Bnlang, RouteOn, and bnlang-web-socket. UI uses Tailwind (via CDN).

Features

  • Start a chat from the homepage
  • Share the /chat/1 link to chat in real time
  • No REST endpoints; rooms are handled purely via WebSocket
  • Tailwind CSS via CDN, no build step
  • In-memory/ephemeral state

Requirements

  • Bnlang v1.0.0+ recommended
  • BNLang runtime CLI available on PATH (the bnl command)

Install & Run

bpm install
bpm run start
  • HTTP server: http://localhost:3000
  • WebSocket server: ws://127.0.0.1:8080/ws

Usage

  1. Open http://localhost:3000/
  2. Enter your display name and click "Start Chat"
  3. You will be redirected to /chat/1
  4. Open the same URL in another browser/device to chat in real time

Notes

  • State is in-memory; restarting the server clears connections and messages.
  • Tailwind is loaded via CDN in templates; no local CSS build required.

WebSocket Protocol (JSON)

  • URL: ws://127.0.0.1:8080/ws
  • Client joins a room after connect:
    { "type": "join", "roomId": "1", "name": "<displayName>" }
    
  • Client sends a message:
    { "type": "message", "roomId": "1", "text": "Hello" }
    
  • Server broadcasts to all peers in the room:
    • Chat: { type: "message", roomId, name, text, ts }
    • System: { type: "system", roomId, text, ts }

Project Structure

  • index.bnl — HTTP server and routes
  • chat.bnl — WebSocket server and room broadcasting
  • views/ — BHTML templates (index.bhtml, chat.bhtml)
  • public/ — static assets (served at /)

About

A simple chat application built with bnlang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published