openvibers/openvibe.sdk Commits

Expose Cam recorder as ov.cam.open() (#150)

OP OpenVibers committed 4 days ago · e903138341 · 20 files, +284 −65

* Expose Cam recorder through SDK browser namespace

* Prepare SDK 0.107.0 release

* Cam: pin the recorder's current integrity

openvibe.cam's cam-kit.js changed with Cam #111 (its icons); the old SHA-384 would make every browser refuse the script.

Changes

ddiff --git a/CHANGELOG.md b/CHANGELOG.md
iindex 27a6731..71c0e9b 100644
---- a/CHANGELOG.md
++++ b/CHANGELOG.md
@@@ -1,5 +1,9 @@
# Changelog
++## 0.107.0 — 2026-11-09
++
++- Add `ov.cam.open()` for the Cam recorder, with typed modes, options and file results across Node and browser exports.
++
## 0.106.0 (2026-11-09)
- Add `openvibe-sdk/home-feed` and `homeFeed` to the top-level and browser exports, with home layout, Today frame, and personal feed methods.
ddiff --git a/README.md b/README.md
iindex 9273536..c8d016e 100644
---- a/README.md
++++ b/README.md
@@@ -2,7 +2,7 @@
> Supported browser and server clients for the OpenVibe platform.
--**Status:** alpha, v0.106.0 (the five 1.0 core entries — `core`, `auth`, `events`, `db` and `media` — are frozen: their exported names change only with a major release; roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat, AI, Vision and consent clients; sign-in with recovery and a client health check). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.
++**Status:** alpha, v0.107.0 (the five 1.0 core entries — `core`, `auth`, `events`, `db` and `media` — are frozen: their exported names change only with a major release; roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat, AI, Vision and consent clients; sign-in with recovery and a client health check). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.
**Plan:** OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30.
**License:** MIT ([LICENSE](LICENSE)). This package is a library that apps outside the network embed, so it uses MIT. The OpenVibe services themselves stay AGPL-3.0.
@@@ -11,7 +11,7 @@
After v0.97.1 is tagged:
```bash
--npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.106.0
++npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.107.0
```
It has no runtime dependencies. It needs Node ≥ 20, or any browser with `fetch`, Web Crypto and `TextDecoder`. There is no build step. The package is CommonJS with ESM entry points (`import` works). Each subpath has its own `.d.ts`. For a page with no bundler, `browser/openvibe-sdk.mjs` is one self-contained ES module of the browser-safe subpaths (see [Browser without a bundler](#browser-without-a-bundler)). It does not depend on `openvibe-contracts` at runtime: it copies the contract types it uses (from the temporary Contracts sharing branch, a devDependency the tests check them against).
@@@ -493,6 +493,18 @@ Install the drivers the service uses: `pg` and `iovalkey` (production), `@electr
### The OpenVibe camera element
++The browser bundle also offers `ov.cam.open()` for video, photo or screen capture in place. It loads Cam's
++SRI-pinned recorder once, then gives your page a `File` and metadata after the person reviews and chooses Use this:
++
++```js
++import ov from 'openvibe-sdk';
++const result = await ov.cam.open({ mode: 'video', maxSeconds: 60 });
++if (result) await upload(result.file);
++```
++
++Closing Cam resolves to `null`. The calling site owns the file and upload. `openvibe-sdk/cam` also exports
++`open`, `loadCamKit`, `CAM_KIT_SRC` and `CAM_KIT_SRI` for direct use.
++
`openvibe-sdk/cam` loads the camera app's framework-free `<ov-camera>` element from OpenVibe.Cam and types its
attributes, events and methods. It injects the embed script once and resolves to the element class:
ddiff --git a/STATUS.json b/STATUS.json
iindex 2dd709d..f7e6eef 100644
---- a/STATUS.json
++++ b/STATUS.json
@@@ -3,7 +3,7 @@
"stage": "alpha",
"code": true,
"wave": "W2",
-- "version": "0.106.0",
++ "version": "0.107.0",
"plan": "OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30",
"deployed": false,
"deployment": "none: a package released as git tags; services and apps pin a tag",
ddiff --git a/browser.js b/browser.js
iindex a7f3b10..087cc19 100644
---- a/browser.js
++++ b/browser.js
@@@ -14,6 +14,7 @@ module.exports = {
modules: require('./src/modules'),
realtime: require('./src/realtime'),
media: require('./src/media'),
++ cam: require('./src/cam'),
community: require('./src/community'),
homeFeed: require('./src/home-feed'),
bot: require('./src/bot'),
ddiff --git a/browser/openvibe-sdk.mjs b/browser/openvibe-sdk.mjs
iindex 317a0a6..3a28f04 100644
---- a/browser/openvibe-sdk.mjs
++++ b/browser/openvibe-sdk.mjs
@@@ -1,6 +1,6 @@
--// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.106.0, MIT). Do not edit.
++// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.107.0, MIT). Do not edit.
// One self-contained ES module: core at the top level plus the browser-safe subpaths as namespaces
--// (auth, locker, registry, trust, modules, realtime, media, community, homeFeed, bot, search, bench, meme, vision, themes, redact, chat, ai, credentials, jobs, tools, projects, geo). No server-only code: no service tokens, JWT verification, events, identity.
++// (auth, locker, registry, trust, modules, realtime, media, cam, community, homeFeed, bot, search, bench, meme, vision, themes, redact, chat, ai, credentials, jobs, tools, projects, geo). No server-only code: no service tokens, JWT verification, events, identity.
/* eslint-disable */
const __defs = [
// ── 0: browser.js ──────────────────────────────────────────────────
@@@ -21,22 +21,23 @@ module.exports = {
modules: __load(22),
realtime: __load(23),
media: __load(24),
-- community: __load(26),
-- homeFeed: __load(27),
-- bot: __load(28),
-- search: __load(29),
-- bench: __load(30),
-- meme: __load(31),
-- vision: __load(32),
-- themes: __load(33),
-- redact: __load(34),
-- chat: __load(35),
-- ai: __load(36),
-- credentials: __load(37),
-- jobs: __load(38),
-- tools: __load(40),
-- projects: __load(41),
-- geo: __load(42),
++ cam: __load(26),
++ community: __load(27),
++ homeFeed: __load(28),
++ bot: __load(29),
++ search: __load(30),
++ bench: __load(31),
++ meme: __load(32),
++ vision: __load(33),
++ themes: __load(34),
++ redact: __load(35),
++ chat: __load(36),
++ ai: __load(37),
++ credentials: __load(38),
++ jobs: __load(39),
++ tools: __load(41),
++ projects: __load(42),
++ geo: __load(43),
};
},
// ── 1: src/core/index.js ───────────────────────────────────────────
@@@ -51,7 +52,7 @@ const { paginate, offsetPager } = __load(7);
const semver = __load(6);
/** The package version (test/version.test.js keeps it equal to package.json). */
--const SDK_VERSION = '0.106.0';
++const SDK_VERSION = '0.107.0';
module.exports = {
createClient,
@@@ -3223,7 +3224,98 @@ function createObjectsClient({
module.exports = { createObjectsClient };
},
--// ── 26: src/community.js ────────────────────────────────────────────
++// ── 26: src/cam/index.js ────────────────────────────────────────────
++function (module, exports) {
++'use strict';
++/**
++ * openvibe-sdk/cam: the OpenVibe camera element, from https://openvibe.cam/embed/ov-camera.js.
++ *
++ * In an app: import { defineOvCamera } from the package's cam entry.
++ * await defineOvCamera();
++ * const camera = document.querySelector('ov-camera');
++ * camera.addEventListener('ov-camera:capture', (event) => upload(event.detail.blob));
++ *
++ * The embed itself is OpenVibe.Cam's framework-free custom element. This loader only injects one
++ * <script> per origin (the page may already include it) and resolves to the class once the browser
++ * has defined it. Nothing here touches the camera: the element starts only from a click or an
++ * explicit start(), and its default upload="off" means a capture never leaves the page.
++ *
++ * <ov-camera facing="user" filters="none,mono,warm" timer="3" mode="photo" upload="off"></ov-camera>
++ *
++ * Browser-only by nature; in Node the call rejects and the module still loads (the types and the
++ * pack test import it). Pass `src` to self-host the same element file.
++ */
++const OV_CAMERA_SRC = 'https://openvibe.cam/embed/ov-camera.js';
++const CAM_KIT_SRC = 'https://openvibe.cam/embed/cam-kit.js';
++const CAM_KIT_SRI = 'sha384-kD5WfySp7D3rNJliBpLgJRrl4Geks+4EcgSaCIBGX+dZdecjmUVxEjzbcUw2Spp7';
++
++// One promise per src: a second call while the script is in flight gets the same load, never a second tag.
++const pending = new Map();
++let kitPending = null;
++
++/** Load Cam's in-page recorder once. The pinned script gives the calling site a File. */
++function loadCamKit() {
++ if (typeof window === 'undefined' || typeof document === 'undefined') return Promise.reject(new Error('openvibe-sdk/cam: open() needs a browser.'));
++ if (window.OpenVibeCam && typeof window.OpenVibeCam.open === 'function') return Promise.resolve(window.OpenVibeCam);
++ if (kitPending) return kitPending;
++ kitPending = new Promise((resolve, reject) => {
++ const script = document.createElement('script');
++ script.src = CAM_KIT_SRC;
++ script.integrity = CAM_KIT_SRI;
++ script.crossOrigin = 'anonymous';
++ script.async = true;
++ script.addEventListener('load', () => {
++ if (window.OpenVibeCam && typeof window.OpenVibeCam.open === 'function') resolve(window.OpenVibeCam);
++ else reject(new Error('openvibe-sdk/cam: Cam kit loaded without OpenVibeCam.open().'));
++ });
++ script.addEventListener('error', () => { script.remove(); reject(new Error('openvibe-sdk/cam: could not load the Cam kit.')); });
++ (document.head || document.documentElement).appendChild(script);
++ }).finally(() => { kitPending = null; });
++ return kitPending;
++}
++
++/** Open Cam on this page. Resolves to a File and metadata after Use this, or null on cancel. */
++function open(options = {}) { return loadCamKit().then((kit) => kit.open(options)); }
++
++/**
++ * Inject the <ov-camera> embed once and resolve to the element class.
++ * @param {{ src?: string }} [options]
++ * @returns {Promise<CustomElementConstructor>}
++ */
++function defineOvCamera(options = {}) {
++ const src = String((options && options.src) || OV_CAMERA_SRC);
++ if (typeof window === 'undefined' || typeof document === 'undefined') {
++ return Promise.reject(new Error('openvibe-sdk/cam: defineOvCamera() needs a browser with custom elements.'));
++ }
++ const defined = () => (window.customElements ? window.customElements.get('ov-camera') : undefined);
++ const already = defined();
++ if (already) return Promise.resolve(already);
++ if (pending.has(src)) return pending.get(src);
++
++ const load = new Promise((resolve, reject) => {
++ const script = document.createElement('script');
++ script.src = src;
++ script.async = true;
++ script.dataset.ovCamera = '';
++ script.addEventListener('load', () => {
++ const ctor = defined();
++ if (ctor) resolve(ctor);
++ else reject(new Error(`openvibe-sdk/cam: ${src} loaded but did not define <ov-camera>.`));
++ });
++ script.addEventListener('error', () => {
++ script.remove();
++ reject(new Error(`openvibe-sdk/cam: could not load ${src}`));
++ });
++ (document.head || document.documentElement).appendChild(script);
++ }).finally(() => pending.delete(src));
++
++ pending.set(src, load);
++ return load;
++}
++
++module.exports = { defineOvCamera, OV_CAMERA_SRC, CAM_KIT_SRC, CAM_KIT_SRI, loadCamKit, open };
++},
++// ── 27: src/community.js ────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -3342,7 +3434,7 @@ function createCommunityClient(client, defaults = {}) {
module.exports = { createCommunityClient, actingHeaders };
},
--// ── 27: src/home-feed.js ────────────────────────────────────────────
++// ── 28: src/home-feed.js ────────────────────────────────────────────
function (module, exports) {
'use strict';
/** The menu's portable Home layout, network day counts and personal wall. Pass a user-token core client;
@@@ -3369,7 +3461,7 @@ function createHomeFeedClient(client, { networkBaseUrl, communityBaseUrl } = {})
module.exports = { createHomeFeedClient };
},
--// ── 28: src/bot.js ──────────────────────────────────────────────────
++// ── 29: src/bot.js ──────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -3591,7 +3683,7 @@ function createBotClient(client, defaults = {}) {
module.exports = { createBotClient, actingHeaders };
},
--// ── 29: src/search.js ───────────────────────────────────────────────
++// ── 30: src/search.js ───────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -3704,7 +3796,7 @@ function createSearchClient(client, defaults = {}) {
module.exports = { createSearchClient, queryOf, fabricOf };
},
--// ── 30: src/bench.js ────────────────────────────────────────────────
++// ── 31: src/bench.js ────────────────────────────────────────────────
function (module, exports) {
'use strict';
/** openvibe-sdk/bench: OpenVibe.Bench's JSON API and streamed open dataset. Browser-safe. */
@@@ -3805,7 +3897,7 @@ function createBenchClient(client, defaults = {}) {
module.exports = { createBenchClient };
},
--// ── 31: src/meme.js ─────────────────────────────────────────────────
++// ── 32: src/meme.js ─────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -3873,7 +3965,7 @@ function createMemeClient(client, defaults = {}) {
module.exports = { createMemeClient };
},
--// ── 32: src/vision.js ───────────────────────────────────────────────
++// ── 33: src/vision.js ───────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4031,7 +4123,7 @@ function pick(o, keys) {
module.exports = { createVisionClient, DEFAULT_AUDIENCE };
},
--// ── 33: src/themes.js ───────────────────────────────────────────────
++// ── 34: src/themes.js ───────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4181,7 +4273,7 @@ function followTheme(fn, opts = {}) {
module.exports = { createThemesClient, followTheme, readTheme, applyTheme, seasonOn, onColor, DISPLAY_OPTIONS, TOKENS };
},
--// ── 34: src/redact.js ───────────────────────────────────────────────
++// ── 35: src/redact.js ───────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4428,7 +4520,7 @@ function onlySecret(text) {
module.exports = { redact, onlySecret };
},
--// ── 35: src/chat.js ─────────────────────────────────────────────────
++// ── 36: src/chat.js ─────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4670,7 +4762,7 @@ function createFeedPublisher(client, { feed, key, baseUrl } = {}) {
module.exports = { createChatClient, createInboxVisitor, createFeedPublisher };
},
--// ── 36: src/ai.js ───────────────────────────────────────────────────
++// ── 37: src/ai.js ───────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4802,7 +4894,7 @@ function createAiClient(client, defaults = {}) {
module.exports = { createAiClient, TERMINAL, OPS, CLASSES };
},
--// ── 37: src/credentials.js ──────────────────────────────────────────
++// ── 38: src/credentials.js ──────────────────────────────────────────
function (module, exports) {
'use strict';
@@@ -4820,7 +4912,7 @@ function createCredentialsClient(client, defaults = {}) {
module.exports = { createCredentialsClient };
},
--// ── 38: src/jobs.js ─────────────────────────────────────────────────
++// ── 39: src/jobs.js ─────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -4858,7 +4950,7 @@ function (module, exports) {
*/
const { OpenVibeError, isOpenVibeError } = __load(3);
const { newIdempotencyKey } = __load(5);
--const { appendFiles } = __load(39);
++const { appendFiles } = __load(40);
const { parseSSE } = __load(23);
const TERMINAL = new Set(['succeeded', 'failed', 'cancelled']);
@@@ -5022,7 +5114,7 @@ function createJobsClient(client, { baseUrl, service = 'tools', audience = 'open
module.exports = { createJobsClient, isTerminal, TERMINAL_STATES: [...TERMINAL] };
},
--// ── 39: src/core/form.js ────────────────────────────────────────────
++// ── 40: src/core/form.js ────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5056,7 +5148,7 @@ function appendFiles(form, list, where) {
module.exports = { isBlob, isUpload, appendFiles };
},
--// ── 40: src/tools.js ────────────────────────────────────────────────
++// ── 41: src/tools.js ────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5090,8 +5182,8 @@ function (module, exports) {
*/
const { OpenVibeError, isOpenVibeError } = __load(3);
const { newIdempotencyKey } = __load(5);
--const { isUpload, appendFiles } = __load(39);
--const { createJobsClient } = __load(38);
++const { isUpload, appendFiles } = __load(40);
++const { createJobsClient } = __load(39);
const enc = encodeURIComponent;
const ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
@@@ -5341,7 +5433,7 @@ function createToolsClient(client, { baseUrl, service = 'tools', audience = 'ope
module.exports = { createToolsClient, ToolRunError, isToolRunError };
},
--// ── 41: src/projects.js ─────────────────────────────────────────────
++// ── 42: src/projects.js ─────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5457,7 +5549,7 @@ function createProjectsClient(client, { baseUrl } = {}) {
module.exports = { createProjectsClient };
},
--// ── 42: src/geo.js ──────────────────────────────────────────────────
++// ── 43: src/geo.js ──────────────────────────────────────────────────
function (module, exports) {
'use strict';
/**
@@@ -5537,8 +5629,8 @@ export const {
startSpan, contextFromHeaders, ulid, newEventId, newIdempotencyKey, isActingSubjectId,
satisfiesRange, compareVersions, CONTRACTS_RANGE, DEFAULT_NETWORK, SDK_VERSION, auth,
locker, registry, trust, modules, realtime, media,
-- community, homeFeed, bot, search, bench, meme,
-- vision, themes, redact, chat, ai, credentials,
-- jobs, tools, projects, geo,
++ cam, community, homeFeed, bot, search, bench,
++ meme, vision, themes, redact, chat, ai,
++ credentials, jobs, tools, projects, geo,
} = sdk;
export default sdk;
ddiff --git a/docs/api-surface.json b/docs/api-surface.json
iindex ef2d353..1533427 100644
---- a/docs/api-surface.json
++++ b/docs/api-surface.json
@@@ -58,6 +58,16 @@
"createBotClient"
]
},
++ "cam": {
++ "object": [
++ "CAM_KIT_SRC",
++ "CAM_KIT_SRI",
++ "OV_CAMERA_SRC",
++ "defineOvCamera",
++ "loadCamKit",
++ "open"
++ ]
++ },
"chat": {
"object": [
"createChatClient",
@@@ -507,8 +517,12 @@
"createCache": "function"
},
"openvibe-sdk/cam": {
++ "CAM_KIT_SRC": "string",
++ "CAM_KIT_SRI": "string",
"OV_CAMERA_SRC": "string",
-- "defineOvCamera": "function"
++ "defineOvCamera": "function",
++ "loadCamKit": "function",
++ "open": "function"
},
"openvibe-sdk/chat": {
"createChatClient": "function",
ddiff --git a/esm/cam.mjs b/esm/cam.mjs
iindex 7b89bfd..6752763 100644
---- a/esm/cam.mjs
++++ b/esm/cam.mjs
@@@ -2,6 +2,6 @@
import cjs from '../src/cam/index.js';
export const {
-- defineOvCamera, OV_CAMERA_SRC,
++ defineOvCamera, OV_CAMERA_SRC, CAM_KIT_SRC, CAM_KIT_SRI, loadCamKit, open,
} = cjs;
export default cjs;
ddiff --git a/esm/index.mjs b/esm/index.mjs
iindex ac00385..46d5e3e 100644
---- a/esm/index.mjs
++++ b/esm/index.mjs
@@@ -6,13 +6,14 @@ export const {
startSpan, contextFromHeaders, ulid, newEventId, newIdempotencyKey, isActingSubjectId,
satisfiesRange, compareVersions, CONTRACTS_RANGE, DEFAULT_NETWORK, SDK_VERSION, report,
share, locker, auth, registry, identity, trust,
-- modules, events, realtime, media, community, homeFeed,
-- bot, search, bench, meme, vision, themes,
-- redact, chat, chatApps, ai, credentials, jobs,
-- tools, projects, resources, vip, quest, live,
-- inventory, tips, blog, reviews, wiki, coupons,
-- deals, trade, space, host, news, food,
-- actor, run, video, work, zone, play,
-- download, openre, geo, usage, commerce, telemetry,
++ modules, events, realtime, media, cam, community,
++ homeFeed, bot, search, bench, meme, vision,
++ themes, redact, chat, chatApps, ai, credentials,
++ jobs, tools, projects, resources, vip, quest,
++ live, inventory, tips, blog, reviews, wiki,
++ coupons, deals, trade, space, host, news,
++ food, actor, run, video, work, zone,
++ play, download, openre, geo, usage, commerce,
++ telemetry,
} = cjs;
export default cjs;
ddiff --git a/index.js b/index.js
iindex eacd4bc..38c6fbe 100644
---- a/index.js
++++ b/index.js
@@@ -19,6 +19,7 @@ module.exports = {
events: require('./src/events'),
realtime: require('./src/realtime'),
media: require('./src/media'),
++ cam: require('./src/cam'),
community: require('./src/community'),
homeFeed: require('./src/home-feed'),
bot: require('./src/bot'),
ddiff --git a/package-lock.json b/package-lock.json
iindex 72caf86..b31fb17 100644
---- a/package-lock.json
++++ b/package-lock.json
@@@ -1,12 +1,12 @@
{
"name": "openvibe-sdk",
-- "version": "0.106.0",
++ "version": "0.107.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openvibe-sdk",
-- "version": "0.106.0",
++ "version": "0.107.0",
"license": "MIT",
"bin": {
"openvibe-download": "bin/openvibe-download.js"
ddiff --git a/package.json b/package.json
iindex afb3179..462ff4b 100644
---- a/package.json
++++ b/package.json
@@@ -1,6 +1,6 @@
{
"name": "openvibe-sdk",
-- "version": "0.106.0",
++ "version": "0.107.0",
"description": "Supported browser and server clients for the OpenVibe platform: auth (incl. developer apps), registry discovery, identity, user modules, events, realtime, media, community, Bot robots, search, chat, AI runs, Tools (registry, run API and jobs), VIP memberships and developer projects, the async PostgreSQL data layer (db) and the Valkey cache, limits store, queue and pub/sub, with deadlines, safe retries, problem errors and trace propagation.",
"main": "index.js",
"types": "types/index.d.ts",
ddiff --git a/src/cam/index.js b/src/cam/index.js
iindex d560640..15e8327 100644
---- a/src/cam/index.js
++++ b/src/cam/index.js
@@@ -18,9 +18,36 @@
* pack test import it). Pass `src` to self-host the same element file.
*/
const OV_CAMERA_SRC = 'https://openvibe.cam/embed/ov-camera.js';
++const CAM_KIT_SRC = 'https://openvibe.cam/embed/cam-kit.js';
++const CAM_KIT_SRI = 'sha384-kD5WfySp7D3rNJliBpLgJRrl4Geks+4EcgSaCIBGX+dZdecjmUVxEjzbcUw2Spp7';
// One promise per src: a second call while the script is in flight gets the same load, never a second tag.
const pending = new Map();
++let kitPending = null;
++
++/** Load Cam's in-page recorder once. The pinned script gives the calling site a File. */
++function loadCamKit() {
++ if (typeof window === 'undefined' || typeof document === 'undefined') return Promise.reject(new Error('openvibe-sdk/cam: open() needs a browser.'));
++ if (window.OpenVibeCam && typeof window.OpenVibeCam.open === 'function') return Promise.resolve(window.OpenVibeCam);
++ if (kitPending) return kitPending;
++ kitPending = new Promise((resolve, reject) => {
++ const script = document.createElement('script');
++ script.src = CAM_KIT_SRC;
++ script.integrity = CAM_KIT_SRI;
++ script.crossOrigin = 'anonymous';
++ script.async = true;
++ script.addEventListener('load', () => {
++ if (window.OpenVibeCam && typeof window.OpenVibeCam.open === 'function') resolve(window.OpenVibeCam);
++ else reject(new Error('openvibe-sdk/cam: Cam kit loaded without OpenVibeCam.open().'));
++ });
++ script.addEventListener('error', () => { script.remove(); reject(new Error('openvibe-sdk/cam: could not load the Cam kit.')); });
++ (document.head || document.documentElement).appendChild(script);
++ }).finally(() => { kitPending = null; });
++ return kitPending;
++}
++
++/** Open Cam on this page. Resolves to a File and metadata after Use this, or null on cancel. */
++function open(options = {}) { return loadCamKit().then((kit) => kit.open(options)); }
/**
* Inject the <ov-camera> embed once and resolve to the element class.
@@@ -58,4 +85,4 @@ function defineOvCamera(options = {}) {
return load;
}
--module.exports = { defineOvCamera, OV_CAMERA_SRC };
++module.exports = { defineOvCamera, OV_CAMERA_SRC, CAM_KIT_SRC, CAM_KIT_SRI, loadCamKit, open };
ddiff --git a/src/core/index.js b/src/core/index.js
iindex 5269dcc..583ed2e 100644
---- a/src/core/index.js
++++ b/src/core/index.js
@@@ -8,7 +8,7 @@ const { paginate, offsetPager } = require('./paginate');
const semver = require('./semver');
/** The package version (test/version.test.js keeps it equal to package.json). */
--const SDK_VERSION = '0.106.0';
++const SDK_VERSION = '0.107.0';
module.exports = {
createClient,
ddiff --git a/test/browser-entries.test.js b/test/browser-entries.test.js
iindex 02dbe56..5d3a7bb 100644
---- a/test/browser-entries.test.js
++++ b/test/browser-entries.test.js
@@@ -97,5 +97,7 @@ run([
['server entries really are server-only (sanity)', async () => {
assert.match(fs.readFileSync(path.join(ROOT, 'src/auth/tokens.js'), 'utf8'), /client_secret/);
assert.equal(browserTarget(pkg.exports['./auth']), './src/auth/browser.js');
++ assert.equal(typeof require('../browser').cam.open, 'function', 'the browser entry exposes ov.cam.open');
++ assert.match(fs.readFileSync(path.join(ROOT, 'esm/index.mjs'), 'utf8'), /\bcam\b/, 'the ESM root exports cam');
}],
]);
ddiff --git a/test/cam.test.js b/test/cam.test.js
iindex 6faeea2..cb3ce7f 100644
---- a/test/cam.test.js
++++ b/test/cam.test.js
@@@ -15,8 +15,10 @@ const pkg = require('../package.json');
run([
['the entry resolves by name and names the loader and the default script', async () => {
-- assert.deepEqual(Object.keys(cam).sort(), ['OV_CAMERA_SRC', 'defineOvCamera']);
++ assert.deepEqual(Object.keys(cam).sort(), ['CAM_KIT_SRC', 'CAM_KIT_SRI', 'OV_CAMERA_SRC', 'defineOvCamera', 'loadCamKit', 'open']);
assert.equal(cam.OV_CAMERA_SRC, 'https://openvibe.cam/embed/ov-camera.js');
++ assert.equal(cam.CAM_KIT_SRC, 'https://openvibe.cam/embed/cam-kit.js');
++ assert.match(cam.CAM_KIT_SRI, /^sha384-/);
assert.equal(require('openvibe-sdk/cam'), cam);
assert.deepEqual(pkg.exports['./cam'], {
types: './types/cam.d.ts',
@@@ -27,12 +29,41 @@ run([
assert.equal(esm.default, cam);
assert.equal(esm.OV_CAMERA_SRC, cam.OV_CAMERA_SRC);
assert.equal(typeof esm.defineOvCamera, 'function');
++ assert.equal(typeof esm.open, 'function');
}],
['in Node it rejects instead of touching a document', async () => {
assert.equal(typeof global.window, 'undefined');
await assert.rejects(cam.defineOvCamera(), /needs a browser/);
await assert.rejects(cam.defineOvCamera({ src: 'https://example.test/ov-camera.js' }), /needs a browser/);
++ await assert.rejects(cam.open({ mode: 'video' }), /needs a browser/);
++ }],
++
++ ['the recorder loader pins one script and forwards the result', async () => {
++ const oldWindow = global.window;
++ const oldDocument = global.document;
++ const tags = [];
++ let kit = null;
++ global.window = {};
++ global.document = { createElement: () => {
++ const listeners = {};
++ return { addEventListener: (name, fn) => { listeners[name] = fn; }, remove() {}, listeners };
++ }, head: { appendChild: (tag) => {
++ tags.push(tag);
++ kit = { open: async (options) => ({ mode: options.mode, file: { name: 'clip.webm' } }) };
++ global.window.OpenVibeCam = kit;
++ queueMicrotask(() => tag.listeners.load());
++ } } };
++ try {
++ const [a, b] = await Promise.all([cam.open({ mode: 'video' }), cam.open({ mode: 'photo' })]);
++ assert.equal(tags.length, 1);
++ assert.equal(tags[0].src, cam.CAM_KIT_SRC);
++ assert.equal(tags[0].integrity, cam.CAM_KIT_SRI);
++ assert.equal(tags[0].crossOrigin, 'anonymous');
++ assert.equal(a.mode, 'video');
++ assert.equal(b.mode, 'photo');
++ assert.equal(await cam.loadCamKit(), kit);
++ } finally { if (oldWindow === undefined) delete global.window; else global.window = oldWindow; if (oldDocument === undefined) delete global.document; else global.document = oldDocument; }
}],
['a browser gets one <script> per load and the class; a defined element resolves without another', async () => {
@@@ -86,7 +117,7 @@ run([
['the types file names the runtime exports and the element surface', async () => {
const dts = fs.readFileSync(path.join(ROOT, 'types/cam.d.ts'), 'utf8');
for (const name of [
-- 'OV_CAMERA_SRC', 'defineOvCamera', 'DefineOvCameraOptions',
++ 'OV_CAMERA_SRC', 'defineOvCamera', 'DefineOvCameraOptions', 'CAM_KIT_SRC', 'CAM_KIT_SRI', 'CamKitResult', 'CamKitOptions', 'loadCamKit', 'open(options?',
'OvCameraAttributes', 'OvCameraFacing', 'OvCameraFilter', 'OvCameraTimer', 'OvCameraMode', 'OvCameraUpload',
'OvCameraElement', 'OvCameraCaptureDetail', 'OvCameraErrorCode', 'OvCameraErrorDetail',
'OvCameraCaptureEvent', 'OvCameraErrorEvent', 'OvCameraEventMap', 'HTMLElementTagNameMap',
ddiff --git a/test/pack.test.js b/test/pack.test.js
iindex aa932f4..3e8971d 100644
---- a/test/pack.test.js
++++ b/test/pack.test.js
@@@ -72,7 +72,7 @@ run([
})().catch((err) => { console.error(err); process.exit(1); });`;
const res = execFileSync(process.execPath, ['-e', script], { cwd: app, encoding: 'utf8' });
assert.match(res, new RegExp(`consumer ok: ${subpaths.length} subpaths \\+ the browser bundle`));
-- assert.equal(subpaths.length, 93); // Adds the home and feed client (0.106.0); 92 had the Report AI comparison client.
++ assert.equal(subpaths.length, 93); // Cam recorder methods extend the existing cam subpath (0.107.0); the 93-subpath count is unchanged.
assert.ok(!fs.existsSync(path.join(app, 'node_modules/openvibe-contracts')), 'the optional peer is not installed');
} finally {
fs.rmSync(tmp, { recursive: true, force: true });
ddiff --git a/test/version.test.js b/test/version.test.js
iindex 65fc138..15247a5 100644
---- a/test/version.test.js
++++ b/test/version.test.js
@@@ -19,8 +19,15 @@ run([
const lock = require('../package-lock.json');
assert.equal(lock.version, pkg.version);
assert.equal(lock.packages[''].version, pkg.version);
-- assert.match(fs.readFileSync(path.join(ROOT, 'CHANGELOG.md'), 'utf8'), new RegExp(`^## ${pkg.version.replace(/\./g, '\\.')} \\(`, 'm'));
++ const changelog = fs.readFileSync(path.join(ROOT, 'CHANGELOG.md'), 'utf8');
++ const versionPattern = pkg.version.replace(/\./g, '\\.');
++ assert.match(changelog, new RegExp(`^## ${versionPattern} (?:\\(|— )`, 'm'));
assert.match(fs.readFileSync(path.join(ROOT, 'browser/openvibe-sdk.mjs'), 'utf8'), new RegExp(`openvibe-sdk ${pkg.version.replace(/\./g, '\\.')},`));
++ const browserBundle = await import('../browser/openvibe-sdk.mjs');
++ assert.equal(browserBundle.default.SDK_VERSION, pkg.version);
++ assert.equal(typeof browserBundle.default.cam.open, 'function');
++ const camEsm = await import('../esm/cam.mjs');
++ assert.equal(typeof camEsm.open, 'function');
}],
['the README installs and names this release (it said v0.35.2 and v0.37.0 at 0.51.1)', async () => {
ddiff --git a/types/bundle.d.ts b/types/bundle.d.ts
iindex 0aacccb..914cde1 100644
---- a/types/bundle.d.ts
++++ b/types/bundle.d.ts
@@@ -4,6 +4,7 @@ import * as registry from './registry';
import * as modules from './modules';
import * as realtime from './realtime';
import * as media from './media';
++import * as cam from './cam';
import * as community from './community';
import * as homeFeed from './home-feed';
import * as bot from './bot';
@@@ -30,6 +31,7 @@ export * as registry from './registry';
export * as modules from './modules';
export * as realtime from './realtime';
export * as media from './media';
++export * as cam from './cam';
export * as community from './community';
export * as homeFeed from './home-feed';
export * as bot from './bot';
@@@ -51,6 +53,6 @@ export * as trust from './trust';
declare const sdk: typeof core & {
auth: typeof auth; registry: typeof registry; modules: typeof modules; realtime: typeof realtime;
-- media: typeof media; community: typeof community; homeFeed: typeof homeFeed; bot: typeof bot; search: typeof search; bench: typeof bench; meme: typeof meme; vision: typeof vision; themes: typeof themes; redact: typeof redact; chat: typeof chat; ai: typeof ai; credentials: typeof credentials; jobs: typeof jobs; tools: typeof tools; projects: typeof projects; geo: typeof geo; locker: typeof locker; trust: typeof trust;
++ media: typeof media; cam: typeof cam; community: typeof community; homeFeed: typeof homeFeed; bot: typeof bot; search: typeof search; bench: typeof bench; meme: typeof meme; vision: typeof vision; themes: typeof themes; redact: typeof redact; chat: typeof chat; ai: typeof ai; credentials: typeof credentials; jobs: typeof jobs; tools: typeof tools; projects: typeof projects; geo: typeof geo; locker: typeof locker; trust: typeof trust;
};
export default sdk;
ddiff --git a/types/cam.d.ts b/types/cam.d.ts
iindex 631eb32..675db63 100644
---- a/types/cam.d.ts
++++ b/types/cam.d.ts
@@@ -7,6 +7,30 @@
/** The embed script the loader injects when no `src` is given. */
export declare const OV_CAMERA_SRC: string;
++/** The pinned in-page recorder script and its SHA-384 integrity value. */
++export declare const CAM_KIT_SRC: string;
++export declare const CAM_KIT_SRI: string;
++
++export type CamKitMode = 'video' | 'photo' | 'screen';
++export interface CamKitResult {
++ file: File;
++ mode: CamKitMode;
++ mimeType: string;
++ duration: number;
++ width: number;
++ height: number;
++ maxSeconds: number;
++}
++export interface CamKitOptions {
++ mode?: CamKitMode;
++ maxSeconds?: number;
++ timer?: 0 | 3 | 10;
++ onDone?: (result: CamKitResult) => void | Promise<void>;
++}
++/** Load OpenVibeCam once and return its browser API. */
++export declare function loadCamKit(): Promise<{ open(options?: CamKitOptions): Promise<CamKitResult | null> }>;
++/** Open Cam on this page and return a file after Use this; cancellation resolves to null. */
++export declare function open(options?: CamKitOptions): Promise<CamKitResult | null>;
/** The front camera (`user`) or the back camera (`environment`). */
export type OvCameraFacing = 'user' | 'environment';
ddiff --git a/types/index.d.ts b/types/index.d.ts
iindex 9224c0c..5ff09a6 100644
---- a/types/index.d.ts
++++ b/types/index.d.ts
@@@ -9,6 +9,7 @@ export * as modules from './modules';
export * as events from './events';
export * as realtime from './realtime';
export * as media from './media';
++export * as cam from './cam';
export * as community from './community';
export * as homeFeed from './home-feed';
export * as bot from './bot';