@myzonerocks/gosslens 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ import { type GossSession } from "./index.js";
2
+ export type GossDisplaySurface = "monitor" | "window" | "browser" | "unknown";
3
+ export interface GossScreenShare {
4
+ readonly track: MediaStreamTrack;
5
+ readonly surface: GossDisplaySurface;
6
+ readonly width: number;
7
+ readonly height: number;
8
+ readonly scale: number;
9
+ step(session: GossSession, source?: string): boolean;
10
+ stop(): void;
11
+ }
12
+ export declare function shareScreen(options?: {
13
+ audio?: boolean;
14
+ frameRate?: number;
15
+ }): Promise<GossScreenShare | null>;
16
+ //# sourceMappingURL=screen-capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen-capture.d.ts","sourceRoot":"","sources":["../../src/screen-capture.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAI/D,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAE9E,MAAM,WAAW,eAAe;IAE9B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IAErC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAGvB,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACrD,IAAI,IAAI,IAAI,CAAC;CACd;AAID,wBAAsB,WAAW,CAAC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAuExH"}
@@ -0,0 +1,75 @@
1
+ //! Screens on the web. getDisplayMedia is the browser's own consent dialog and
2
+ //! its own picker, so there is no enumeration to do here: the user chooses, and
3
+ //! what comes back says which kind of surface it is.
4
+ /// Opens the browser's screen picker. Rejecting the dialog is a refusal, not an
5
+ /// error: the caller gets null and prompts again when it makes sense to.
6
+ export async function shareScreen(options = {}) {
7
+ const media = navigator.mediaDevices;
8
+ if (typeof media?.getDisplayMedia !== "function")
9
+ return null;
10
+ let stream;
11
+ try {
12
+ stream = await media.getDisplayMedia({
13
+ video: options.frameRate ? { frameRate: options.frameRate } : true,
14
+ audio: options.audio ?? false,
15
+ });
16
+ }
17
+ catch {
18
+ // The user declined, or the browser refused. Both are answers.
19
+ return null;
20
+ }
21
+ const track = stream.getVideoTracks()[0];
22
+ if (!track) {
23
+ stream.getTracks().forEach((t) => t.stop());
24
+ return null;
25
+ }
26
+ const settings = track.getSettings();
27
+ const width = settings.width ?? 0;
28
+ const height = settings.height ?? 0;
29
+ const surface = settings.displaySurface === "monitor" || settings.displaySurface === "window" || settings.displaySurface === "browser"
30
+ ? settings.displaySurface
31
+ : "unknown";
32
+ // An OffscreenCanvas where one exists, because drawing the frame is the only
33
+ // way a page reads pixels out of a track and a visible canvas would need a DOM.
34
+ const canvas = typeof OffscreenCanvas === "function"
35
+ ? new OffscreenCanvas(Math.max(width, 1), Math.max(height, 1))
36
+ : Object.assign(document.createElement("canvas"), { width: Math.max(width, 1), height: Math.max(height, 1) });
37
+ const context = canvas.getContext("2d");
38
+ const video = document.createElement("video");
39
+ video.srcObject = stream;
40
+ video.muted = true;
41
+ await video.play().catch(() => undefined);
42
+ let lastTime = -1;
43
+ return {
44
+ track,
45
+ surface,
46
+ width,
47
+ height,
48
+ scale: typeof devicePixelRatio === "number" ? devicePixelRatio : 1,
49
+ step(session, source = "") {
50
+ if (!context || video.readyState < 2)
51
+ return false;
52
+ // The same frame twice is not a new frame, which is what makes a static
53
+ // screen free rather than a copy per tick.
54
+ if (video.currentTime === lastTime)
55
+ return false;
56
+ lastTime = video.currentTime;
57
+ context.drawImage(video, 0, 0, canvas.width, canvas.height);
58
+ const image = context.getImageData(0, 0, canvas.width, canvas.height);
59
+ const pixels = new Uint8Array(image.data.buffer);
60
+ const timestampUs = Math.round(video.currentTime * 1e6);
61
+ if (source.length === 0) {
62
+ session.submitFrameRgbaCopy(pixels, canvas.width * 4, canvas.width, canvas.height, 4 /* GossPixelFormat.Rgba8 */, undefined, false, timestampUs);
63
+ }
64
+ else {
65
+ session.submitSourceFrameRgba(source, pixels, canvas.width, canvas.height, canvas.width * 4);
66
+ }
67
+ return true;
68
+ },
69
+ stop() {
70
+ stream.getTracks().forEach((t) => t.stop());
71
+ video.srcObject = null;
72
+ },
73
+ };
74
+ }
75
+ //# sourceMappingURL=screen-capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen-capture.js","sourceRoot":"","sources":["../../src/screen-capture.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gFAAgF;AAChF,qDAAqD;AAuBrD,gFAAgF;AAChF,yEAAyE;AACzE,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAO,GAA4C,EAAE;IACrF,MAAM,KAAK,GAAG,SAAS,CAAC,YAEvB,CAAC;IACF,IAAI,OAAO,KAAK,EAAE,eAAe,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IAE9D,IAAI,MAAmB,CAAC;IACxB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC;YACnC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI;YAClE,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK;SAC9B,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,+DAA+D;QAC/D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,KAAK,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CAAyB,SAAS,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;YAC3I,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YAC/F,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI;YACF,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YAC5C,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@myzonerocks/gosslens",
3
- "version": "0.12.0",
4
- "description": "Web SDK for the gosslens camera and AR engine, over the wasm core.",
3
+ "version": "0.13.0",
4
+ "description": "Web SDK for gosslens, real-time visual plumbing for agents, over the wasm core.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "sideEffects": false,
26
26
  "scripts": {
27
- "build": "tsc -p tsconfig.json",
27
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.demo.json",
28
28
  "test": "bun test ./test",
29
29
  "typecheck": "tsc -p tsconfig.json --noEmit",
30
30
  "prepublishOnly": "bun run build"