You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: apps/app/src/app/canvas/page.tsx
+49-2Lines changed: 49 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -106,6 +106,46 @@ interface AgentState {
106
106
document: string;
107
107
}
108
108
109
+
constDEFAULT_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).
| 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`;
0 commit comments