Skip to content

gitflarePublicPartly agent-ready50

cf-durable-whiteboard

Realtime collaborative whiteboard on Cloudflare Durable Objects: presence cursors, WebSocket hibernation, SQLite storage, undo, PNG export.

Keep board zoom and pan stable across reloads6eb4fbd
TypeScript15 lines437 B
export class TokenBucket {  private tokens: number;  private last: number;  constructor(private rate = 60, private burst = 120, now = Date.now()) {    this.tokens = burst;    this.last = now;  }  take(now = Date.now()): boolean {    this.tokens = Math.min(this.burst, this.tokens + ((now - this.last) / 1000) * this.rate);    this.last = now;    if (this.tokens >= 1) { this.tokens -= 1; return true; }    return false;  }}