Skip to content

damvr007z/BroCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 

Repository files navigation

{ BroCode } โ€” Real-Time Collaborative Code Editor

Built for Macondo ร— Hack Club Where bros (and everyone else) code together in real time โ€” no accounts, no servers, no nonsense.


๐Ÿ–ผ๏ธ Preview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  { BroCode }  JavaScript  main.js   โ— Connected โœ“  [Alice] [Bob] โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  CONNECTION    โ”‚  โ†ฉ Undo  โ†ช Redo  โ‡ฅ Indent  // Comment  A+  Aโˆ’  โ”‚
โ”‚  cs-BR0C0D3 โŽ˜ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Name: Alice   โ”‚  1  // โœฆ Welcome to BroCode ๐Ÿ’ฏ                  โ”‚
โ”‚  Partner IDโ€ฆ   โ”‚  2                                              โ”‚
โ”‚  [Connect]     โ”‚  3  function greet(name) {                      โ”‚
โ”‚  [Disconnect]  โ”‚  4    return `What's good, ${name}!`  โ† Alice ๐ŸŸขโ”‚
โ”‚                โ”‚  5  }                                           โ”‚
โ”‚  CHAT          โ”‚  6                                              โ”‚
โ”‚  Alice: Yo bro โ”‚  7  const squad = ["Alice", "Bob"];             โ”‚
โ”‚  Bob: On it ๐Ÿ‘€ โ”‚  8  squad.forEach(bro => {           Bob ๐Ÿ”ด     โ”‚
โ”‚  Alice: ๐Ÿ˜ค     โ”‚  9    console.log(greet(bro)); โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“         โ”‚
โ”‚  Bob: ๐Ÿ’ฏ       โ”‚ 10  });                                         โ”‚
โ”‚  [Type hereโ€ฆ]  โ”‚ 11                                             โ”‚
โ”‚                โ”‚ 12  // No server. No login. Just share an ID ๐Ÿค โ”‚
โ”‚                โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                โ”‚  JavaScript  โ€ข  12 lines  โ€ข  Latency: 14ms      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Live Demo

โ†’ Open BroCode here

  1. Open in two browser tabs or two devices
  2. Copy your Peer ID โ†’ paste it into your partner's field โ†’ hit Connect
  3. Type anywhere โ€” the other screen updates in real time

โœจ Features

Feature What It Does
๐ŸŸข Real-time code sync Every keystroke broadcasts as a compact delta to your partner โ€” no lag, no full-page snapshots
๐Ÿ–ฑ๏ธ Dual live cursors Your cursor is teal, your partner's is coral โ€” both visible with floating name labels
๐Ÿ”ต Remote selection highlight See exactly what text your partner has selected
๐Ÿ’ฌ Built-in bro chat Side-panel chat so you never have to switch tabs
๐ŸŒ 5 languages JavaScript, Python, HTML, CSS, C++ with full syntax highlighting
๐Ÿ”— One-click ID share Copy your 9-char Peer ID and send it via WhatsApp, Discord, anything
โ†ฉ๏ธ Undo / Redo Full per-user edit history
๐Ÿ’ฌ Comment toggle Ctrl+/ or the toolbar button
๐Ÿ”  Font size controls A+ / Aโˆ’ for any screen size
๐Ÿ“‹ Copy code Grab the whole editor content in one click
โšก Latency meter Live ping/pong latency displayed in the status bar
๐Ÿ”„ Auto-resync If edits ever drift, a full snapshot resync fires automatically
๐Ÿ“ก Zero backend 100% peer-to-peer WebRTC โ€” the PeerJS relay only handles the initial handshake

๐Ÿ› ๏ธ Tech Stack

Layer Technology Why
Networking PeerJS v1.5.4 WebRTC wrapper โ€” direct P2P data channel
Signalling 0.peerjs.com (free) Exchanges connection metadata; never sees your code
NAT traversal Google STUN servers Lets peers behind routers find each other
Editor CodeMirror 5 Professional in-browser editor with syntax highlighting
Fonts JetBrains Mono + Space Grotesk Mono for code, humanist sans for UI
Hosting GitHub Pages Free, instant, zero-config static hosting
Build tools None Single HTML file โ€” no npm, no webpack, no Node.js

๐Ÿ“ก How Real-Time Sync Works

You type a character
        โ”‚
        โ–ผ
CodeMirror fires 'change' event
โ†’ {from: {line:3,ch:4}, to: {line:3,ch:4}, text: ["x"]}
        โ”‚
        โ–ผ
PeerJS DataConnection.send(delta)
        โ”‚
   WebRTC data channel โ€” direct P2P, ~5โ€“50ms latency
        โ”‚
        โ–ผ
Partner receives delta
        โ”‚
        โ–ผ
editor.replaceRange(text, from, to, '+remote')
   (applying flag prevents echo loop)
        โ”‚
        โ–ผ
Cursor position broadcast follows immediately

Message protocol

Type Direction Payload Purpose
delta both โ†” {from, to, text} Incremental keystroke change
full-sync either โ†’ {code, lang} Full snapshot on connect or resync
cursor both โ†” {line, ch, label} Remote cursor position
selection both โ†” {anchor, head} Remote text selection highlight
chat both โ†” {text, name} Chat message
meta both โ†” {name} User display name announcement
lang both โ†” {lang} Language change sync
ping / pong both โ†” {ts} Round-trip latency measurement
request-sync either โ†’ โ€” Trigger a full resync after drift

๐Ÿ“ Project Structure

brocode/
โ”œโ”€โ”€ index.html        โ† Entire application (HTML + CSS + JS in one file)
โ”œโ”€โ”€ README.md         โ† This file
โ””โ”€โ”€ SETUP_GUIDE.md    โ† Step-by-step GitHub Pages deployment guide

The entire app lives in index.html. No dependencies to install, no build step, no config files.


โšก Quick Start

Local โ€” 30 seconds

# No installation needed โ€” just open the file
open index.html       # macOS
start index.html      # Windows
xdg-open index.html   # Linux

Open a second browser tab with the same file and connect.

Deploy to GitHub Pages โ€” 5 minutes

See SETUP_GUIDE.md for the full walkthrough, or:

# 1. Clone / create your repo
git clone https://github.com/YOUR_USERNAME/brocode.git
cd brocode

# 2. Push
git add index.html README.md SETUP_GUIDE.md
git commit -m "feat: BroCode real-time collaborative editor for Macondo"
git push origin main

# 3. Enable GitHub Pages
#    Repo โ†’ Settings โ†’ Pages โ†’ Deploy from main โ†’ / (root) โ†’ Save

# 4. Your live URL:
#    https://YOUR_USERNAME.github.io/brocode/

๐ŸŽฎ How to Use

Starting a session

  1. Open the URL in your browser
  2. Your Peer ID appears automatically (e.g. cs-BR0C0D3)
  3. Enter your Display Name in the sidebar
  4. Click ๐Ÿ”— Share ID โ†’ copy it โ†’ send to your partner via Discord, WhatsApp, etc.

Joining a session

  1. Open the same URL
  2. Paste your partner's Peer ID into "Partner's Peer ID"
  3. Enter your Display Name
  4. Click Connect โ€” green "Connected โœ“" means you're live

Coding together

  • Type normally โ€” every keystroke syncs to your partner instantly
  • Your teal cursor and their coral cursor are both visible at all times
  • Their selected text appears as a coral-tinted highlight on your screen
  • Use the Chat panel to talk without switching apps
  • Change the language from the dropdown โ€” it syncs to your partner too

Keyboard shortcuts

Shortcut Action
Ctrl+/ or Cmd+/ Toggle line comment
Tab Insert 2 spaces
Ctrl+Z Undo
Ctrl+Shift+I Copy your Peer ID to clipboard
Escape Close the share modal

๐Ÿ—๏ธ Architecture

Browser A                              Browser B
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€               โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
CodeMirror Editor                     CodeMirror Editor
      โ”‚  change events                      โ”‚  change events
      โ–ผ                                     โ–ผ
 Delta encoder  โ”€โ”€โ”€โ”€ WebRTC RTCDataChannel โ”€โ”€โ”€โ”€โ–บ  Delta decoder
 Delta decoder  โ—„โ”€โ”€โ”€โ”€ direct P2P, no relay โ”€โ”€โ”€โ”€โ”€โ”€ Delta encoder
      โ”‚                                     โ”‚
 Remote cursor render               Remote cursor render
 Remote selection render            Remote selection render
      โ”‚                                     โ”‚
 Chat panel  โ—„โ”€โ”€โ”€โ”€โ”€โ”€ chat messages โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  Chat panel
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€               โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
                           โ†‘
                     Signalling only
                    (0.peerjs.com)
                    Used ONCE during
                    connection setup โ€”
                    never sees your code

๐ŸŒ Browser Compatibility

Browser Support
Chrome / Edge 90+ โœ… Full
Firefox 85+ โœ… Full
Safari 15+ โœ… Full
Opera 76+ โœ… Full
Mobile Chrome / Safari โœ… Full
Internet Explorer โŒ WebRTC not supported

๐Ÿ› Troubleshooting

Problem Solution
peer-unavailable error Peer ID was mistyped โ€” always use copy-paste
Can't connect on public/school WiFi Some networks block WebRTC UDP. Switch to a mobile hotspot
Changes stopped syncing Click Disconnect โ†’ reconnect. A full sync fires on every new connection
Partner's cursor not visible Normal until they move โ€” just type or click to trigger a broadcast
peer-destroyed error Reload the page. A fresh Peer ID is generated on each load
GitHub Pages shows 404 Confirm the file is named exactly index.html (lowercase) in the repo root

๐Ÿ† Built for Macondo ร— Hack Club

Macondo is Hack Club's annual hackathon celebrating creative, technically interesting builds.

30-second pitch for judges

"It's Google Docs for code, but with zero backend. Share a 9-character ID with your bro โ€” they paste it, click Connect, and you're both in the same editor in real time. Two cursors, built-in chat, any browser, one HTML file."

What makes it technically interesting

  • Zero backend โ€” BroCode is a static file. The PeerJS relay only touches the initial ICE handshake, never your code
  • Delta sync โ€” only {from, to, text} diffs are transmitted (not full snapshots), making it fast even on 3G
  • Automatic resync โ€” if deltas ever drift, a full snapshot fallback restores consistency immediately
  • Real WebRTC โ€” actual RTCDataChannel with ordered, reliable delivery; not a simulation or polling hack
  • Pixel-accurate cursors โ€” CodeMirror bookmark widgets inject DOM nodes directly into the editor's text flow

๐Ÿ“œ License

MIT โ€” free to use, fork, remix, and ship to hackathons.


๐Ÿ™ Credits

Dependency License
PeerJS MIT
CodeMirror 5 MIT
JetBrains Mono OFL-1.1
Space Grotesk OFL-1.1

{ BroCode } โ€” because the best code is written with your crew. ๐Ÿค Made with โค๏ธ for Macondo ร— Hack Club.

About

it is a cool web based code editor where you and your bro can code togather at the same time!!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages