All files / lib/awareness events.ts

0% Statements 0/4
100% Branches 1/1
100% Functions 1/1
0% Lines 0/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                                                                                     
// lib/awareness/events.ts
 
// Top-level debug flag
export const DEBUG = process.env.NODE_ENV !== 'production';
 
// Environment-driven guards
export const AWARENESS_ENABLED = DEBUG || process.env.AWARENESS_ENABLED === 'true' || process.env.TEST_AWARENESS === 'true';
export const TELEMETRY_ENABLED = DEBUG || process.env.TELEMETRY_ENABLED === 'true' || process.env.TEST_TELEMETRY === 'true';
 
export enum AwarenessEvent {
  DESKTOP_LOADED = 'DESKTOP_LOADED',
  WINDOW_OPENED = 'WINDOW_OPENED',
  WINDOW_CLOSED = 'WINDOW_CLOSED',
  WINDOW_FOCUSED = 'WINDOW_FOCUSED',
  TELEMETRY_METRIC = 'TELEMETRY_METRIC',
}
 
export type DesktopLoadedPayload = {
  timestamp: number;
  openWindows: number;
  activeWindow: string | null;
};
 
export type WindowOpenedPayload = {
  windowId: string;
  timestamp: number;
};
 
export type WindowClosedPayload = {
  windowId: string;
  timestamp: number;
};
 
export type WindowFocusedPayload = {
  windowId: string;
  timestamp: number;
};
 
export type TelemetryMetricPayload = {
  name: string;
  value: number;
  tags?: Record<string, string>;
};
 
export type AwarenessEventPayload =
  | { type: AwarenessEvent.DESKTOP_LOADED; payload: DesktopLoadedPayload }
  | { type: AwarenessEvent.WINDOW_OPENED; payload: WindowOpenedPayload }
  | { type: AwarenessEvent.WINDOW_CLOSED; payload: WindowClosedPayload }
  | { type: AwarenessEvent.WINDOW_FOCUSED; payload: WindowFocusedPayload }
  | { type: AwarenessEvent.TELEMETRY_METRIC; payload: TelemetryMetricPayload };