@v-office/website-sdk 2.31.1 → 2.33.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,168 @@
1
+ # Videos
2
+
3
+ Videos are available on v9 only. Check `sdk.backend === "v9"` before using them. v10 has no
4
+ `sdk.static.videos`.
5
+
6
+ ## Service
7
+
8
+ ```ts
9
+ if (sdk.backend === "v9") {
10
+ const all = await sdk.static.videos.getVideos();
11
+ const hero = await sdk.static.videos.getVideos({ placement: "frontpage" });
12
+ const ofRental = await sdk.static.videos.getVideos({ placement: "object", rentalId: "12345" });
13
+ }
14
+ ```
15
+
16
+ The SDK loads the list once per instance. Filters run locally and combine with AND; without
17
+ input every video is returned.
18
+
19
+ ## Input
20
+
21
+ ```ts
22
+ type V9VideosGetVideosInput = {
23
+ placement?: string;
24
+ rentalId?: string;
25
+ };
26
+ ```
27
+
28
+ ## Output
29
+
30
+ Returns `Promise<ReadonlyArray<V9Video>>`, ordered by upload (oldest first).
31
+
32
+ ```ts
33
+ type V9Video = {
34
+ id: string;
35
+ placement: string;
36
+ rentalIds: ReadonlyArray<string>;
37
+ hlsUrl: string;
38
+ posterUrl: string | null;
39
+ durationSeconds: number;
40
+ fileName: string;
41
+ };
42
+ ```
43
+
44
+ Sample item:
45
+
46
+ ```json
47
+ {
48
+ "id": "17",
49
+ "placement": "object",
50
+ "rentalIds": ["12345"],
51
+ "hlsUrl": "https://stream.example/abc/manifest/video.m3u8",
52
+ "posterUrl": "https://stream.example/abc/thumbnails/thumbnail.jpg",
53
+ "durationSeconds": 67.2,
54
+ "fileName": "haus-seeblick-final.mp4"
55
+ }
56
+ ```
57
+
58
+ - `placement` says where the agency wants the video. `frontpage` is the home page video
59
+ (at most one per agency). `object` videos belong to the rentals in `rentalIds`; one rental
60
+ can have several videos. Any other value is a free slug for a page of the agency's choosing,
61
+ for example a landing page. The agency picks the placement in the be-on! agency portal.
62
+ - `rentalIds` match `rental.id` of the rentals.
63
+ - `fileName` is the name of the uploaded file. Never show it to visitors. Label a video from
64
+ the rental name or the page it sits on.
65
+ - `posterUrl` is `null` when no still image exists.
66
+
67
+ ## Behaviour
68
+
69
+ - Call it at build time. A video the agency adds or deletes shows up after the next site
70
+ build.
71
+ - A failing call rejects, which fails the build. The previous build stays live.
72
+ - An empty list is normal. Render nothing, not an empty player.
73
+
74
+ ## Playback
75
+
76
+ `hlsUrl` is an HLS stream. Install `hls.js` as an exactly pinned dependency of the site. Safari
77
+ and iOS play HLS natively; other browsers need `hls.js`. Try native playback first, then load
78
+ `hls.js` on demand.
79
+
80
+ This snippet is temporary: a playback helper in `@v-office/website-headless` will replace it.
81
+
82
+ ### Rental video
83
+
84
+ ```astro
85
+ ---
86
+ const [video] = await sdk.static.videos.getVideos({ placement: "object", rentalId: rental.id });
87
+ ---
88
+
89
+ {
90
+ video && (
91
+ <video
92
+ data-hls={video.hlsUrl}
93
+ controls
94
+ poster={video.posterUrl ?? undefined}
95
+ preload="none"
96
+ playsinline
97
+ aria-label={`Video: ${rental.nameOrLabel}`}
98
+ />
99
+ )
100
+ }
101
+
102
+ <script>
103
+ const attach = async (video: HTMLVideoElement, src: string) => {
104
+ if (video.canPlayType("application/vnd.apple.mpegurl")) {
105
+ video.src = src;
106
+ return;
107
+ }
108
+ const { default: Hls } = await import("hls.js");
109
+ if (!Hls.isSupported()) return;
110
+ const hls = new Hls();
111
+ hls.loadSource(src);
112
+ hls.attachMedia(video);
113
+ };
114
+
115
+ document
116
+ .querySelectorAll<HTMLVideoElement>("video[data-hls]")
117
+ .forEach((video) => attach(video, video.dataset.hls!));
118
+ </script>
119
+ ```
120
+
121
+ ### Hero video
122
+
123
+ The home page video plays silently in the background, so it is muted, loops and carries no
124
+ native controls. Moving content that starts on its own needs a way to stop it, so the hero
125
+ gets a pause button and does not start for visitors who ask for reduced motion.
126
+
127
+ ```astro
128
+ ---
129
+ const [hero] = await sdk.static.videos.getVideos({ placement: "frontpage" });
130
+ ---
131
+
132
+ {
133
+ hero && (
134
+ <div class="hero-video">
135
+ <video
136
+ data-hls={hero.hlsUrl}
137
+ data-hero
138
+ muted
139
+ loop
140
+ playsinline
141
+ poster={hero.posterUrl ?? undefined}
142
+ aria-hidden="true"
143
+ />
144
+ <button type="button" data-hero-toggle>Pause video</button>
145
+ </div>
146
+ )
147
+ }
148
+
149
+ <script>
150
+ const video = document.querySelector<HTMLVideoElement>("video[data-hero]");
151
+ const toggle = document.querySelector<HTMLButtonElement>("button[data-hero-toggle]");
152
+ if (video && toggle) {
153
+ const sync = () => (toggle.textContent = video.paused ? "Play video" : "Pause video");
154
+ video.addEventListener("play", sync);
155
+ video.addEventListener("pause", sync);
156
+ toggle.addEventListener("click", () => (video.paused ? video.play() : video.pause()));
157
+ // hls.js attaches the source later; autoplay starts the video once it can play.
158
+ video.autoplay = !matchMedia("(prefers-reduced-motion: reduce)").matches;
159
+ if (video.autoplay && video.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA) {
160
+ video.play().catch(sync);
161
+ }
162
+ sync();
163
+ }
164
+ </script>
165
+ ```
166
+
167
+ Use the `<script>` from the rental video as well. It attaches every `video[data-hls]` on the
168
+ page.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v-office/website-sdk",
3
- "version": "2.31.1",
3
+ "version": "2.33.0",
4
4
  "description": "Website-facing SDK facade backed by @v-office/sdk-core",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {
@@ -82,7 +82,7 @@
82
82
  "fmt": "oxfmt",
83
83
  "fmt:check": "oxfmt --check",
84
84
  "check": "pnpm run typecheck && pnpm run lint && pnpm run fmt:check",
85
- "test": "pnpm run test:cli && pnpm run test:v9:openapi && pnpm run test:v9:properties && pnpm run test:v9:rentals && pnpm run test:v9:graphql && pnpm run test:v9:availability && pnpm run test:v9:search && pnpm run test:v9:booking && pnpm run build && node --test test/*.test.mjs",
85
+ "test": "pnpm run test:cli && pnpm run test:v9:openapi && pnpm run test:v9:properties && pnpm run test:v9:rentals && pnpm run test:v9:graphql && pnpm run test:v9:availability && pnpm run test:v9:search && pnpm run test:v9:booking && pnpm run test:v9:videos && pnpm run build && node --test test/*.test.mjs",
86
86
  "test:cli": "node --test src/cli/v9-hub-filters.test.ts",
87
87
  "test:v9:openapi": "node --test codegen/v9/php-record.test.ts src/legacy-v9/openapi/setup-response.test.ts src/legacy-v9/openapi/quote-response.test.ts",
88
88
  "test:v9:properties": "node --test codegen/v9/heuristic-generation/generate/property.test.ts src/legacy-v9/property-highlight-sources.test.ts src/legacy-v9/parser/rentals/render-property-attribute.test.ts src/legacy-v9/parser/rentals/to-property.test.ts src/legacy-v9/parser/rentals/to-rooms.test.ts",
@@ -91,6 +91,7 @@
91
91
  "test:v9:availability": "node --test src/legacy-v9/parser/availability/to-availability-restrictions-by-date.test.ts src/legacy-v9/parser/availability/to-initial-availability-calendar-days.test.ts src/legacy-v9/parser/availability/to-occupancy-limits.test.ts src/legacy-v9/parser/availability/to-rent-night-prices.test.ts src/legacy-v9/parser/availability/to-start-date-selected-calendar-days.test.ts",
92
92
  "test:v9:search": "node --test src/legacy-v9/parser/search/resolve-exact-match.test.ts src/legacy-v9/rental-scope.test.ts",
93
93
  "test:v9:booking": "node --test src/legacy-v9/parser/booking/output/to-payment-schedules.test.ts",
94
+ "test:v9:videos": "node --test src/legacy-v9/parser/videos/to-videos.test.ts",
94
95
  "playground:custom-attributes": "pnpm run build && node --env-file=.env playground/custom-attributes.ts"
95
96
  }
96
97
  }