It works locally, but DOES NOT work when deployed to Cloudflare. Can you provide some examples and update the docs as well?
export class Agents extends Server<Bindings> {
options = { hibernate: true };
state: DurableObjectState;
sockets = new Set<WebSocket>();
constructor(state: DurableObjectState, env: Bindings) {
super(state, env);
this.state = state;
this.env = env;
this.sockets = new Set<WebSocket>();
this.state.getWebSockets().forEach((socket) => {
this.sockets.add(socket);
});
}
broadcastToAll(channelId: number, msg: { type: string, data: Record<string, any> }, without?: string[] | undefined) {
const message = JSON.stringify(msg);
for (const socket of this.getConnections(`C:${channelId}`)) {
if (without && without.includes(socket.id)) {
continue;
}
socket.send(message);
}
}
}
I see some documentation on Cloudflare and this is how the connections needs to load after hibernation?
It works locally, but DOES NOT work when deployed to Cloudflare. Can you provide some examples and update the docs as well?