thai
thai
Explore posts from servers
HHono
Created by thai on 8/11/2024 in #help
Websockets connected clients count
Hi, I'd like to know how to get the amount of connected clients.
import { Hono } from 'hono'
import { upgradeWebSocket } from 'hono/cloudflare-workers'
const app = new Hono()
const obj = { data: 5 };

//i'm periodically changing the data in obj
function startTimer() {
return setInterval(() => {
obj.data = Math.random();
}, 1000);
}

const wsApp = app.get(
'/ws',
upgradeWebSocket((c) => {
let timer: NodeJS.Timeout;
return {
onOpen: (event, ws) => {
console.log('connected');
ws.send(JSON.stringify(obj));
timer = startTimer();
},
onClose: (event, ws) => {
//if no clients are connected stop the timer
// if ( ws.clients.size === 0) {
// clearInterval(timer);
// }
}
}
})
)

export type WebSocketApp = typeof wsApp;
import { Hono } from 'hono'
import { upgradeWebSocket } from 'hono/cloudflare-workers'
const app = new Hono()
const obj = { data: 5 };

//i'm periodically changing the data in obj
function startTimer() {
return setInterval(() => {
obj.data = Math.random();
}, 1000);
}

const wsApp = app.get(
'/ws',
upgradeWebSocket((c) => {
let timer: NodeJS.Timeout;
return {
onOpen: (event, ws) => {
console.log('connected');
ws.send(JSON.stringify(obj));
timer = startTimer();
},
onClose: (event, ws) => {
//if no clients are connected stop the timer
// if ( ws.clients.size === 0) {
// clearInterval(timer);
// }
}
}
})
)

export type WebSocketApp = typeof wsApp;
7 replies
PPrisma
Created by thai on 7/28/2024 in #help-and-questions
Relation field not appearing in model.createMany
No description
3 replies
PPrisma
Created by thai on 7/21/2024 in #help-and-questions
Can't see relation field in Types
No description
4 replies