Compare commits

...

3 Commits

Author SHA1 Message Date
semantic-release-bot
4c6eb01f1e chore(release): 3.6.1 [skip ci]
## [3.6.1](https://github.com/antialias/soroban-abacus-flashcards/compare/v3.6.0...v3.6.1) (2025-10-14)

### Bug Fixes

* join user socket channel to receive approval notifications ([7d08fdd](7d08fdd906))

### Code Refactoring

* remove redundant polling from approval notifications ([0d4f400](0d4f400dca))
2025-10-14 12:44:53 +00:00
Thomas Hallock
7d08fdd906 fix: join user socket channel to receive approval notifications
The socket wasn't receiving join-request-approved events because it hadn't
joined the user-specific channel. Now:

- Fetch viewer ID from /api/viewer endpoint
- Emit 'join-user-channel' with userId on socket connect
- Socket joins `user:${userId}` room to receive moderation events
- Approval notifications now trigger automatic room join

This completes the real-time approval notification flow.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 07:43:49 -05:00
Thomas Hallock
0d4f400dca refactor: remove redundant polling from approval notifications
Remove polling interval that checked every 5 seconds for approval status.
The socket.io listener provides real-time notifications, making polling
unnecessary and wasteful.

Now relies solely on socket.io for instant approval notifications, which:
- Reduces network traffic
- Simplifies code
- Provides faster response time

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 07:40:02 -05:00
4 changed files with 93 additions and 90 deletions

View File

@@ -1,3 +1,15 @@
## [3.6.1](https://github.com/antialias/soroban-abacus-flashcards/compare/v3.6.0...v3.6.1) (2025-10-14)
### Bug Fixes
* join user socket channel to receive approval notifications ([7d08fdd](https://github.com/antialias/soroban-abacus-flashcards/commit/7d08fdd90643920857eda09998ac01afbae74154))
### Code Refactoring
* remove redundant polling from approval notifications ([0d4f400](https://github.com/antialias/soroban-abacus-flashcards/commit/0d4f400dca02ad9497522c24fded8b6d07d85fd2))
## [3.6.0](https://github.com/antialias/soroban-abacus-flashcards/compare/v3.5.0...v3.6.0) (2025-10-14)

View File

@@ -352,58 +352,57 @@ export default function JoinRoomPage({ params }: { params: { code: string } }) {
}
}
// Socket listener and polling for approval notifications
// Socket listener for approval notifications
useEffect(() => {
if (!approvalRequested || !targetRoomData) return
console.log('[Join Page] Setting up approval listeners for room:', targetRoomData.id)
console.log('[Join Page] Setting up approval listener for room:', targetRoomData.id)
// Socket listener for real-time approval notification
const socket = io({ path: '/api/socket' })
let socket: ReturnType<typeof io> | null = null
socket.on('connect', () => {
console.log('[Join Page] Socket connected')
})
socket.on('join-request-approved', (data: { roomId: string; requestId: string }) => {
console.log('[Join Page] Request approved via socket!', data)
if (data.roomId === targetRoomData.id) {
console.log('[Join Page] Joining room automatically...')
handleJoin(targetRoomData.id)
}
})
socket.on('connect_error', (error) => {
console.error('[Join Page] Socket connection error:', error)
})
// Polling fallback - check every 5 seconds
const pollInterval = setInterval(async () => {
// Fetch viewer ID and set up socket
const setupSocket = async () => {
try {
console.log('[Join Page] Polling for approval status...')
const res = await fetch(`/api/arcade/rooms/${targetRoomData.id}/join-requests`)
if (res.ok) {
const data = await res.json()
// Check if any request for this user was approved
const approvedRequest = data.requests?.find(
(r: { status: string }) => r.status === 'approved'
)
if (approvedRequest) {
console.log('[Join Page] Request approved via polling! Joining room...')
clearInterval(pollInterval)
socket.disconnect()
// Get current user's viewer ID
const res = await fetch('/api/viewer')
if (!res.ok) {
console.error('[Join Page] Failed to get viewer ID')
return
}
const { viewerId } = await res.json()
console.log('[Join Page] Got viewer ID:', viewerId)
// Connect socket
socket = io({ path: '/api/socket' })
socket.on('connect', () => {
console.log('[Join Page] Socket connected, joining user channel')
// Join user-specific channel to receive moderation events
socket?.emit('join-user-channel', { userId: viewerId })
})
socket.on('join-request-approved', (data: { roomId: string; requestId: string }) => {
console.log('[Join Page] Request approved via socket!', data)
if (data.roomId === targetRoomData.id) {
console.log('[Join Page] Joining room automatically...')
handleJoin(targetRoomData.id)
}
}
} catch (err) {
console.error('[Join Page] Failed to poll join requests:', err)
})
socket.on('connect_error', (error) => {
console.error('[Join Page] Socket connection error:', error)
})
} catch (error) {
console.error('[Join Page] Error setting up socket:', error)
}
}, 5000)
}
setupSocket()
return () => {
console.log('[Join Page] Cleaning up approval listeners')
socket.disconnect()
clearInterval(pollInterval)
console.log('[Join Page] Cleaning up approval listener')
socket?.disconnect()
}
}, [approvalRequested, targetRoomData, handleJoin])

View File

@@ -143,53 +143,40 @@ export function JoinRoomModal({ isOpen, onClose, onSuccess }: JoinRoomModalProps
}
}
// Socket listener and polling for approval notifications
// Socket listener for approval notifications
useEffect(() => {
if (!approvalRequested || !roomInfo) return
console.log('[JoinRoomModal] Setting up approval listeners for room:', roomInfo.id)
console.log('[JoinRoomModal] Setting up approval listener for room:', roomInfo.id)
// Socket listener for real-time approval notification
const socket = io({ path: '/api/socket' })
let socket: ReturnType<typeof io> | null = null
socket.on('connect', () => {
console.log('[JoinRoomModal] Socket connected')
})
socket.on('join-request-approved', async (data: { roomId: string; requestId: string }) => {
console.log('[JoinRoomModal] Request approved via socket!', data)
if (data.roomId === roomInfo.id) {
console.log('[JoinRoomModal] Joining room automatically...')
try {
await joinRoom(roomInfo.id)
handleClose()
onSuccess?.()
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to join room')
setIsLoading(false)
}
}
})
socket.on('connect_error', (error) => {
console.error('[JoinRoomModal] Socket connection error:', error)
})
// Polling fallback - check every 5 seconds
const pollInterval = setInterval(async () => {
// Fetch viewer ID and set up socket
const setupSocket = async () => {
try {
console.log('[JoinRoomModal] Polling for approval status...')
const res = await fetch(`/api/arcade/rooms/${roomInfo.id}/join-requests`)
if (res.ok) {
const data = await res.json()
// Check if any request for this user was approved
const approvedRequest = data.requests?.find(
(r: { status: string }) => r.status === 'approved'
)
if (approvedRequest) {
console.log('[JoinRoomModal] Request approved via polling! Joining room...')
clearInterval(pollInterval)
socket.disconnect()
// Get current user's viewer ID
const res = await fetch('/api/viewer')
if (!res.ok) {
console.error('[JoinRoomModal] Failed to get viewer ID')
return
}
const { viewerId } = await res.json()
console.log('[JoinRoomModal] Got viewer ID:', viewerId)
// Connect socket
socket = io({ path: '/api/socket' })
socket.on('connect', () => {
console.log('[JoinRoomModal] Socket connected, joining user channel')
// Join user-specific channel to receive moderation events
socket?.emit('join-user-channel', { userId: viewerId })
})
socket.on('join-request-approved', async (data: { roomId: string; requestId: string }) => {
console.log('[JoinRoomModal] Request approved via socket!', data)
if (data.roomId === roomInfo.id) {
console.log('[JoinRoomModal] Joining room automatically...')
try {
await joinRoom(roomInfo.id)
handleClose()
@@ -199,16 +186,21 @@ export function JoinRoomModal({ isOpen, onClose, onSuccess }: JoinRoomModalProps
setIsLoading(false)
}
}
}
} catch (err) {
console.error('[JoinRoomModal] Failed to poll join requests:', err)
})
socket.on('connect_error', (error) => {
console.error('[JoinRoomModal] Socket connection error:', error)
})
} catch (error) {
console.error('[JoinRoomModal] Error setting up socket:', error)
}
}, 5000)
}
setupSocket()
return () => {
console.log('[JoinRoomModal] Cleaning up approval listeners')
socket.disconnect()
clearInterval(pollInterval)
console.log('[JoinRoomModal] Cleaning up approval listener')
socket?.disconnect()
}
}, [approvalRequested, roomInfo, joinRoom, handleClose, onSuccess])

View File

@@ -1,6 +1,6 @@
{
"name": "soroban-monorepo",
"version": "3.6.0",
"version": "3.6.1",
"private": true,
"description": "Beautiful Soroban Flashcard Generator - Monorepo",
"workspaces": [