Skip to content

Commit 9af67d9

Browse files
committed
fix: critical issues found by claude
1 parent 96006fd commit 9af67d9

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

guides/socket-io-integration-guide.mdx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ description: Complete guide for integrating Socket.IO real-time communication wi
44
icon: plug
55
---
66

7-
# Socket.IO Integration with Eliza - Complete Guide
8-
97
## Overview
108

119
This guide explains how Socket.IO works in the Eliza NextJS starter and provides solutions for integrating external clients (like browser extensions) with the Eliza server.
@@ -118,7 +116,7 @@ const roomId = 'your-room-id'; // This should match the agent/channel ID
118116

119117
// 2. CRITICAL: Join the room when connected
120118
socket.on('connect', function() {
121-
console.log(' Connected to Eliza, socket ID:', socket.id);
119+
console.log('[SUCCESS] Connected to Eliza, socket ID:', socket.id);
122120

123121
// JOIN THE ROOM - This is required to receive broadcasts!
124122
socket.emit('message', {
@@ -129,31 +127,31 @@ socket.on('connect', function() {
129127
}
130128
});
131129

132-
console.log('📨 Sent room join request for room:', roomId);
130+
console.log('[SENT] Room join request for room:', roomId);
133131
});
134132

135133
// 3. LISTEN FOR THE CORRECT EVENT: "messageBroadcast" (not "message")
136134
socket.on('messageBroadcast', function(data) {
137-
console.log('📩 Received broadcast:', data);
135+
console.log('[RECEIVED] Broadcast:', data);
138136

139137
// Check if this message is for your room
140138
if (data.roomId === roomId || data.channelId === roomId) {
141-
console.log(' Message is for our room!');
139+
console.log('[SUCCESS] Message is for our room!');
142140
console.log('Sender:', data.senderName);
143141
console.log('Text:', data.text);
144142
console.log('Full data:', JSON.stringify(data, null, 2));
145143
} else {
146-
console.log(' Message is for different room:', data.roomId || data.channelId);
144+
console.log('[ERROR] Message is for different room:', data.roomId || data.channelId);
147145
}
148146
});
149147

150148
// 4. Listen for other important events
151149
socket.on('messageComplete', function(data) {
152-
console.log(' Message processing complete:', data);
150+
console.log('[SUCCESS] Message processing complete:', data);
153151
});
154152

155153
socket.on('connection_established', function(data) {
156-
console.log(' Connection established:', data);
154+
console.log('[SUCCESS] Connection established:', data);
157155
});
158156

159157
// 5. Send a message (make sure format is exact)
@@ -172,7 +170,7 @@ function sendMessageToEliza(text) {
172170
}
173171
};
174172

175-
console.log('📤 Sending message:', messagePayload);
173+
console.log('[SENDING] Message:', messagePayload);
176174
socket.emit('message', messagePayload);
177175
}
178176

@@ -188,24 +186,24 @@ function generateUUID() {
188186
// 6. Debug: Log ALL events (remove in production)
189187
const originalEmit = socket.emit;
190188
socket.emit = function() {
191-
console.log('⬆️ Emitting:', arguments[0], arguments[1]);
189+
console.log('[EMIT] Event:', arguments[0], arguments[1]);
192190
return originalEmit.apply(socket, arguments);
193191
};
194192

195193
// For Socket.IO v1.3.0, use this to catch all events:
196194
const onevent = socket.onevent;
197195
socket.onevent = function(packet) {
198-
console.log('⬇️ Received event:', packet.data);
196+
console.log('[RECEIVE] Event:', packet.data);
199197
onevent.call(socket, packet);
200198
};
201199

202200
// Connection error handling
203201
socket.on('connect_error', function(error) {
204-
console.error(' Connection error:', error);
202+
console.error('[ERROR] Connection error:', error);
205203
});
206204

207205
socket.on('disconnect', function(reason) {
208-
console.log('🔌 Disconnected:', reason);
206+
console.log('[DISCONNECTED] Reason:', reason);
209207
});
210208

211209
// Test the connection
@@ -221,10 +219,10 @@ socket.on('connect', function() {
221219

222220
### 1. Event Name
223221
```javascript
224-
// WRONG
222+
// [WRONG]
225223
socket.on('message', handler)
226224

227-
// CORRECT
225+
// [CORRECT]
228226
socket.on('messageBroadcast', handler)
229227
```
230228

0 commit comments

Comments
 (0)