Skip to content

Commit bb0290f

Browse files
committed
websockets
1 parent aff193f commit bb0290f

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

cloudbuild.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ steps:
2222
- '--timeout=3600'
2323
- '--max-instances=10'
2424
- '--min-instances=0'
25-
- '--concurrency=1'
25+
- '--concurrency=10'
26+
- '--session-affinity'
2627
- '--port=8080'
2728
- '--env-vars-file=.env.yaml'
2829

server.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ function coerceTypes(obj) {
5252
return coerced;
5353
}
5454

55-
// Initialize Socket.IO server
55+
// Initialize Socket.IO server with Cloud Run optimizations
5656
io = new Server(httpServer, {
5757
cors: {
5858
origin: '*', // Adjust in production for security
5959
methods: ['GET', 'POST']
60-
}
60+
},
61+
// Cloud Run optimizations
62+
transports: ['websocket', 'polling'], // Allow both but prefer WebSocket
63+
allowEIO3: true, // Allow different Engine.IO versions
64+
pingTimeout: 60000, // 60 seconds (Cloud Run timeout)
65+
pingInterval: 25000, // 25 seconds
66+
upgradeTimeout: 30000, // 30 seconds for upgrade
67+
maxHttpBufferSize: 1e6 // 1MB max buffer
6168
});
6269

6370
io.on('connection', socket => {

ui/app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ form.addEventListener('submit', async e => {
564564
// Connect to WebSocket (same server for Cloud Run) with user info
565565
const socket = io({
566566
reconnection: true,
567+
reconnectionAttempts: 5,
568+
reconnectionDelay: 1000,
569+
timeout: 20000,
570+
// Force WebSocket transport for Cloud Run
571+
transports: ['websocket', 'polling'],
567572
auth: {
568573
user: user
569574
}

0 commit comments

Comments
 (0)