openvibers/openvibe.live Commits

menu card: build and serve it with openvibe-sdk/menu (#673)

OP OpenVibers committed 6 days ago · f77a6e991c · 4 files, +14 −17

* menu card: build and serve it with openvibe-sdk/menu

Live's card and route were hand-rolled against frame.menu-card@1. menuCard()
now builds the same 'Live now' rail (plain text, six items, own-origin and
openvibe.* links, optional thumbnails) and menuRoute() answers
/.well-known/openvibe-menu.json with the same 30 s cache and CORS *; the
last-good-card cache stays in card(). Pin openvibe-sdk v0.97.0.

* Pin openvibe-sdk v0.97.1

The menu handler types now accept plain node:http messages under
exactOptionalPropertyTypes; no runtime change.

Changes

ddiff --git a/STATUS.json b/STATUS.json
iindex d55b5047..27fc2e5d 100644
---- a/STATUS.json
++++ b/STATUS.json
@@@ -6,7 +6,7 @@
"port": 3000,
"domain": "openvibe.live (www, ingest, whip)",
"contracts": "openvibe-contracts v0.320.0",
-- "sdk": "openvibe-sdk v0.94.0",
++ "sdk": "openvibe-sdk v0.97.1",
"shared": "openvibe-shared v4.133.0",
"capabilities": [
"live.chat_context.read",
ddiff --git a/package-lock.json b/package-lock.json
iindex ddc76560..30cc6701 100644
---- a/package-lock.json
++++ b/package-lock.json
@@@ -24,7 +24,7 @@
"node-media-server": "^2.7.1",
"onnxruntime-node": "^1.20.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.320.0",
-- "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.94.0",
++ "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.97.1",
"openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v4.133.0",
"pg": "^8.23.1",
"sanitize-html": "^2.17.7",
@@@ -2856,9 +2856,9 @@
}
},
"node_modules/openvibe-sdk": {
-- "version": "0.94.0",
-- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.94.0",
-- "integrity": "sha512-p3buZSOSFV81OdZgs5GoSIfMCQNJjW23eAIXIt0RVFIOvh3TByNNEMmuCanxRybFIbzh+9IDMbBwHJrBLl3JeA==",
++ "version": "0.97.1",
++ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.97.1",
++ "integrity": "sha512-zCRmu7NoOi7kI0v04N8uypCgsuEcf9kCzkw88r0+dj9PG3AA/z+Pp4BZaX6Z1JUE3sdrtc17D5LcD05IbWsw8w==",
"license": "MIT",
"bin": {
"openvibe-download": "bin/openvibe-download.js"
ddiff --git a/package.json b/package.json
iindex 0dfaa1da..f465ef8c 100644
---- a/package.json
++++ b/package.json
@@@ -43,7 +43,7 @@
"node-media-server": "^2.7.1",
"onnxruntime-node": "^1.20.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.320.0",
-- "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.94.0",
++ "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.97.1",
"openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v4.133.0",
"pg": "^8.23.1",
"sanitize-html": "^2.17.7",
ddiff --git a/server/menu-card.js b/server/menu-card.js
iindex 240e43dd..990edef2 100644
---- a/server/menu-card.js
++++ b/server/menu-card.js
@@@ -12,6 +12,7 @@
// there is one (https on openvibe.live or an openvibe.* host); a stream without a picture gets no image.
const db = require('./db/database');
const contentLabels = require('./labels');
++const { menuCard, menuRoute } = require('openvibe-sdk/menu');
const SITE = 'live';
const BASE = 'https://openvibe.live';
@@@ -62,16 +63,17 @@ function cardFrom(rows, at = Date.now()) {
if (image) item.image = image;
return item;
});
-- return {
++ return menuCard({
id: 'live-now',
site: SITE,
title: 'Live now',
kind: 'rail',
++ origin: BASE,
items,
more: { label: 'See all', url: `${BASE}/` },
-- updated_at: new Date(at).toISOString(),
-- ttl_s: CARD_TTL_S,
-- };
++ ttlSeconds: CARD_TTL_S,
++ updatedAt: at,
++ });
}
/**
@@@ -104,13 +106,8 @@ function createMenuCard({ load = () => db.getLiveStreams(), now = Date.now } = {
return pending;
}
-- async function handler(_req, res) {
-- const body = await card();
-- res.set('Cache-Control', `public, max-age=${CARD_TTL_S}`)
-- .set('Access-Control-Allow-Origin', '*')
-- .set('Cross-Origin-Resource-Policy', 'cross-origin')
-- .json([body]);
-- }
++ // openvibe-sdk/menu answers the file (CORS *, the public cache) and turns a build failure into [], never a 500.
++ const handler = menuRoute(async () => [await card()], { maxAgeSeconds: CARD_TTL_S });
return { card, handler, cardFrom, cacheMs: CACHE_MS };
}