Skip to content

Commit de80d48

Browse files
committed
feat: add WebSocket document as default content on canvas page
- Set placeholder text to 'How do WebSockets work?' - Initialize canvas with comprehensive WebSocket explanation document - Document includes handshake process, persistent connections, frames, HTTP comparison, and use cases - Provides starting point for user to ask agent to generate Excalidraw diagram
1 parent b8619ce commit de80d48

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

apps/app/src/app/canvas/page.tsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,46 @@ interface AgentState {
106106
document: string;
107107
}
108108

109+
const DEFAULT_DOCUMENT = `# How do WebSockets Work?
110+
111+
## 1. The Handshake (HTTP Upgrade)
112+
113+
It starts as a regular HTTP request. The client sends a special header asking to "upgrade" the connection:
114+
115+
- GET /chat HTTP/1.1
116+
- Upgrade: websocket
117+
- Connection: Upgrade
118+
119+
The server responds with 101 Switching Protocols, and from that point on, the connection is no longer HTTP — it's a WebSocket.
120+
121+
## 2. The Persistent Connection
122+
123+
Unlike HTTP (where each request opens and closes a connection), the WebSocket connection stays open. Both sides can now send messages to each other at any time without waiting for the other to ask first.
124+
125+
## 3. Frames, Not Requests
126+
127+
Data is sent as lightweight "frames" — small packets that can carry text, binary data, or control signals (like ping/pong to keep the connection alive).
128+
129+
## HTTP vs WebSocket
130+
131+
| Aspect | HTTP | WebSocket |
132+
|--------|------|-----------|
133+
| Direction | One-way (request → response) | Two-way (either side) |
134+
| Connection | Opens and closes each time | Stays open |
135+
| Overhead | Headers sent every request | Minimal after handshake |
136+
| Use case | Loading pages, REST APIs | Chat, live feeds, games |
137+
138+
## A simple mental model
139+
140+
Think of HTTP like sending letters — you write one, wait for a reply, then write another. WebSocket is like a phone call — once connected, both people can speak freely at any time without hanging up between each sentence.
141+
142+
## Common use cases
143+
144+
- Chat apps — messages appear instantly without polling
145+
- Live dashboards — stock prices, sports scores, analytics
146+
- Multiplayer games — real-time position and state sync
147+
- Collaborative tools — like Google Docs, where edits appear live`;
148+
109149
const DocumentEditor = () => {
110150
const editor = useEditor({
111151
extensions,
@@ -117,10 +157,17 @@ const DocumentEditor = () => {
117157

118158
const [placeholderVisible, setPlaceholderVisible] = useState(false);
119159
const [isFocused, setIsFocused] = useState(false);
120-
const [currentDocument, setCurrentDocument] = useState("");
160+
const [currentDocument, setCurrentDocument] = useState(DEFAULT_DOCUMENT);
121161
const wasRunning = useRef(false);
122162
const isMountedRef = useRef(true);
123163

164+
// Initialize editor with default document on mount
165+
useEffect(() => {
166+
if (editor && currentDocument) {
167+
editor.commands.setContent(fromMarkdown(currentDocument));
168+
}
169+
}, [editor]);
170+
124171
// Cleanup on unmount to prevent state updates after component is removed
125172
useEffect(() => {
126173
return () => {
@@ -301,7 +348,7 @@ const DocumentEditor = () => {
301348
<div className="relative h-full w-full flex flex-col overflow-hidden">
302349
{placeholderVisible && (
303350
<div className="absolute top-6 left-10 pointer-events-none text-sm" style={{ color: "var(--text-tertiary)" }}>
304-
Write whatever you want here in Markdown format...
351+
How do WebSockets work?
305352
</div>
306353
)}
307354
<div className="flex-1 overflow-hidden flex flex-col" style={{ cursor: "text" }}>

0 commit comments

Comments
 (0)