phirepass-widgets 0.0.117 → 0.0.118

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.
Files changed (88) hide show
  1. package/README.md +1 -12
  2. package/dist/cjs/{index-DehquNXP.js → index-C3v5xmUo.js} +2 -74
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/phirepass-rdp.cjs.entry.js +5 -16
  5. package/dist/cjs/phirepass-sftp-client.cjs.entry.js +1470 -0
  6. package/dist/cjs/phirepass-terminal.cjs.entry.js +4 -4
  7. package/dist/cjs/phirepass-widgets.cjs.js +2 -2
  8. package/dist/cjs/{protocol-BjOgJZ9-.js → protocol-DCBMfc2u.js} +21 -277
  9. package/dist/collection/collection-manifest.json +0 -2
  10. package/dist/collection/common/channel.js +1 -21
  11. package/dist/collection/components/phirepass-rdp/phirepass-rdp.js +13 -36
  12. package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.css +0 -122
  13. package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.js +31 -181
  14. package/dist/collection/components/phirepass-terminal/phirepass-terminal.js +2 -2
  15. package/dist/collection/phirepass-channel_bg.wasm +0 -0
  16. package/dist/components/index.js +1 -1
  17. package/dist/components/p-CsYQJXY2.js +1 -0
  18. package/dist/components/phirepass-rdp.js +1 -1
  19. package/dist/components/phirepass-sftp-client.js +1 -1
  20. package/dist/components/phirepass-terminal.js +5 -5
  21. package/dist/esm/{index-BinptKL7.js → index-BVOulYtW.js} +2 -74
  22. package/dist/esm/loader.js +3 -3
  23. package/dist/esm/phirepass-rdp.entry.js +5 -16
  24. package/dist/esm/phirepass-sftp-client.entry.js +1468 -0
  25. package/dist/esm/phirepass-terminal.entry.js +4 -4
  26. package/dist/esm/phirepass-widgets.js +3 -3
  27. package/dist/esm/{protocol-BekUePpu.js → protocol-CsYQJXY2.js} +20 -276
  28. package/dist/phirepass-widgets/{p-9e6f9220.entry.js → p-7ea2fdbc.entry.js} +5 -5
  29. package/dist/phirepass-widgets/p-BVOulYtW.js +3 -0
  30. package/dist/phirepass-widgets/p-CsYQJXY2.js +1 -0
  31. package/dist/phirepass-widgets/p-c1c616ca.entry.js +1 -0
  32. package/dist/phirepass-widgets/p-f1bc04a8.entry.js +1 -0
  33. package/dist/phirepass-widgets/phirepass-channel_bg.wasm +0 -0
  34. package/dist/phirepass-widgets/phirepass-widgets.esm.js +1 -1
  35. package/dist/types/common/channel.d.ts +0 -30
  36. package/dist/types/components/phirepass-rdp/phirepass-rdp.d.ts +0 -10
  37. package/dist/types/components/phirepass-sftp-client/phirepass-sftp-client.d.ts +0 -30
  38. package/dist/types/components.d.ts +34 -434
  39. package/package.json +4 -18
  40. package/dist/cjs/phirepass-downloader_3.cjs.entry.js +0 -3823
  41. package/dist/collection/common/fetch.js +0 -44
  42. package/dist/collection/components/phirepass-downloader/form.js +0 -69
  43. package/dist/collection/components/phirepass-downloader/format.js +0 -105
  44. package/dist/collection/components/phirepass-downloader/jobs.js +0 -393
  45. package/dist/collection/components/phirepass-downloader/phirepass-downloader.css +0 -1109
  46. package/dist/collection/components/phirepass-downloader/phirepass-downloader.js +0 -1466
  47. package/dist/collection/components/phirepass-downloader/source.js +0 -120
  48. package/dist/collection/components/phirepass-downloader/views/dialogs.js +0 -34
  49. package/dist/collection/components/phirepass-downloader/views/fetch-form.js +0 -65
  50. package/dist/collection/components/phirepass-downloader/views/icons.js +0 -34
  51. package/dist/collection/components/phirepass-downloader/views/job-row.js +0 -91
  52. package/dist/collection/components/phirepass-downloader/views/notices.js +0 -15
  53. package/dist/collection/components/phirepass-downloader/views/states.js +0 -19
  54. package/dist/collection/components/phirepass-media-player/phirepass-media-player.css +0 -225
  55. package/dist/collection/components/phirepass-media-player/phirepass-media-player.js +0 -549
  56. package/dist/collection/components/phirepass-media-player/player.js +0 -118
  57. package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.fetch.js +0 -35
  58. package/dist/collection/testing/fixtures.js +0 -219
  59. package/dist/collection/testing/mock-channel.js +0 -410
  60. package/dist/components/p-B4kFfbHE.js +0 -1
  61. package/dist/components/p-BekUePpu.js +0 -1
  62. package/dist/components/p-DIf-Ru26.js +0 -1
  63. package/dist/components/phirepass-downloader.d.ts +0 -11
  64. package/dist/components/phirepass-downloader.js +0 -1
  65. package/dist/components/phirepass-media-player.d.ts +0 -11
  66. package/dist/components/phirepass-media-player.js +0 -1
  67. package/dist/esm/phirepass-downloader_3.entry.js +0 -3819
  68. package/dist/phirepass-widgets/p-6a192c8d.entry.js +0 -1
  69. package/dist/phirepass-widgets/p-BekUePpu.js +0 -1
  70. package/dist/phirepass-widgets/p-BinptKL7.js +0 -3
  71. package/dist/phirepass-widgets/p-fe1ce8da.entry.js +0 -1
  72. package/dist/types/common/fetch.d.ts +0 -167
  73. package/dist/types/components/phirepass-downloader/form.d.ts +0 -54
  74. package/dist/types/components/phirepass-downloader/format.d.ts +0 -17
  75. package/dist/types/components/phirepass-downloader/jobs.d.ts +0 -123
  76. package/dist/types/components/phirepass-downloader/phirepass-downloader.d.ts +0 -238
  77. package/dist/types/components/phirepass-downloader/source.d.ts +0 -61
  78. package/dist/types/components/phirepass-downloader/views/dialogs.d.ts +0 -52
  79. package/dist/types/components/phirepass-downloader/views/fetch-form.d.ts +0 -31
  80. package/dist/types/components/phirepass-downloader/views/icons.d.ts +0 -5
  81. package/dist/types/components/phirepass-downloader/views/job-row.d.ts +0 -21
  82. package/dist/types/components/phirepass-downloader/views/notices.d.ts +0 -18
  83. package/dist/types/components/phirepass-downloader/views/states.d.ts +0 -38
  84. package/dist/types/components/phirepass-media-player/phirepass-media-player.d.ts +0 -82
  85. package/dist/types/components/phirepass-media-player/player.d.ts +0 -53
  86. package/dist/types/components/phirepass-sftp-client/phirepass-sftp-client.fetch.d.ts +0 -40
  87. package/dist/types/testing/fixtures.d.ts +0 -25
  88. package/dist/types/testing/mock-channel.d.ts +0 -132
@@ -1,549 +0,0 @@
1
- import { Host, h } from "@stencil/core";
2
- import { formatBytes, formatClock, formatDay } from "../phirepass-downloader/format";
3
- import { Icon } from "../phirepass-downloader/views/icons";
4
- import { SAVE_EVERY_MS, castBlocker, fetchLinkMinter, isAudio, localPositionStore, positionAction } from "./player";
5
- /**
6
- * Plays a file from the node with the browser's own `<video>` or `<audio>`.
7
- *
8
- * It knows nothing of channels or WASM: `src` is a stream URL the server turns
9
- * into stream events towards the agent, and the browser's range requests do
10
- * the rest. A download that is still arriving plays as far as `ready` bytes;
11
- * past that the element waits, and so does the player, saying why.
12
- */
13
- export class PhirepassMediaPlayer {
14
- el;
15
- media;
16
- lastSave = 0;
17
- resumeAt = 0;
18
- everPlayed = false;
19
- /** A stored position was offered (G6): then `startAt` plays, not `autoplay`. */
20
- positionPrompted = false;
21
- availabilityId;
22
- onRemoteConnect = () => (this.phase = 'casting');
23
- onRemoteDisconnect = () => {
24
- if (this.phase === 'casting') {
25
- this.phase = this.everPlayed ? 'playing' : 'buffering';
26
- }
27
- };
28
- /** The stream URL: `/api/web/stream/{node}/{download}/{file}` or a listing token URL. */
29
- src;
30
- name;
31
- /** Overrides the mime the extension implies. */
32
- mime;
33
- /** The status line above the picture, from the job: “Downloading · 23.4%”, “On the node”. */
34
- status;
35
- /** Bytes ready from the start of the file, while it is still downloading. */
36
- ready;
37
- /** “Continue watching”. Without one, positions stay in this browser. */
38
- positionStore;
39
- /** Key for the stored position: `dl:<download_id>:<file>` or `node:<node_id>:<path>`. */
40
- positionKey;
41
- /** Stands in for `video.remote`, for demos and tests (like `channelFactory`). */
42
- remotePlayback;
43
- /** Makes the link a TV or VLC opens (T2.9). Defaults to POSTing `src`. */
44
- linkMinter;
45
- /** Shown while casting, when the host knows the device's name. */
46
- castDevice;
47
- playerClose;
48
- phase = 'buffering';
49
- stored = null;
50
- castAvailable = false;
51
- /** The ticket URL the element plays from once casting was asked for. */
52
- castSrc = null;
53
- linkNote = null;
54
- currentTime = 0;
55
- duration = 0;
56
- get store() {
57
- return this.positionStore ?? localPositionStore;
58
- }
59
- get audio() {
60
- return isAudio(this.name, this.mime);
61
- }
62
- async componentWillLoad() {
63
- if (this.positionKey) {
64
- const stored = await this.store.get(this.positionKey).catch(() => null);
65
- if (stored && positionAction(stored.secs, stored.duration) === 'save') {
66
- this.stored = stored;
67
- this.positionPrompted = true;
68
- this.phase = 'prompt';
69
- }
70
- }
71
- }
72
- componentDidLoad() {
73
- void this.watchRemote();
74
- }
75
- disconnectedCallback() {
76
- void this.savePosition(true);
77
- const remote = this.remote();
78
- if (remote) {
79
- remote.removeEventListener('connect', this.onRemoteConnect);
80
- remote.removeEventListener('disconnect', this.onRemoteDisconnect);
81
- if (this.availabilityId !== undefined) {
82
- void remote.cancelWatchAvailability(this.availabilityId).catch(() => undefined);
83
- }
84
- }
85
- }
86
- onSrc() {
87
- this.castSrc = null;
88
- this.everPlayed = false;
89
- this.phase = 'buffering';
90
- }
91
- /** Closes the player, saving where it stopped. The download is not affected. */
92
- async close() {
93
- await this.savePosition(true);
94
- this.media?.pause?.();
95
- this.playerClose.emit();
96
- }
97
- get minter() {
98
- return this.linkMinter ?? fetchLinkMinter();
99
- }
100
- /**
101
- * The TV fetches the file itself and has no cookie, so the element first
102
- * moves to a ticket URL (same bytes, same position), then the device picker
103
- * opens. A ticket that cannot be had still opens the picker: on a
104
- * development stack the plain URL plays.
105
- */
106
- async cast() {
107
- if (!this.castSrc) {
108
- const url = await this.minter(this.src);
109
- const media = this.media;
110
- if (url && media) {
111
- const at = media.currentTime;
112
- const playing = !media.paused;
113
- this.castSrc = url;
114
- media.src = url;
115
- this.resumeAt = at;
116
- if (at > 0) {
117
- media.currentTime = at;
118
- }
119
- if (playing) {
120
- void media.play?.()?.catch?.(() => undefined);
121
- }
122
- }
123
- }
124
- await this.remote()?.prompt().catch(() => undefined);
125
- }
126
- /** “Copy link for VLC”: the same ticket, on the clipboard. */
127
- async copyLink() {
128
- const url = this.castSrc ?? (await this.minter(this.src));
129
- if (!url) {
130
- this.linkNote = 'Could not make a link.';
131
- return;
132
- }
133
- try {
134
- await navigator.clipboard.writeText(url);
135
- this.linkNote = 'Link copied. It works in VLC until it expires.';
136
- }
137
- catch {
138
- this.linkNote = url;
139
- }
140
- }
141
- remote() {
142
- return this.remotePlayback ?? this.media?.remote;
143
- }
144
- async watchRemote() {
145
- const remote = this.remote();
146
- if (!remote || this.audio) {
147
- return;
148
- }
149
- remote.addEventListener('connect', this.onRemoteConnect);
150
- remote.addEventListener('disconnect', this.onRemoteDisconnect);
151
- if (remote.state === 'connected') {
152
- this.phase = 'casting';
153
- }
154
- try {
155
- this.availabilityId = await remote.watchAvailability(available => (this.castAvailable = available));
156
- }
157
- catch {
158
- // Browsers that cannot watch (Safari without a device, or a policy) still allow prompt() on click.
159
- this.castAvailable = true;
160
- }
161
- }
162
- async savePosition(force = false) {
163
- const media = this.media;
164
- if (!media || !this.positionKey || !this.everPlayed) {
165
- return;
166
- }
167
- const now = Date.now();
168
- if (!force && now - this.lastSave < SAVE_EVERY_MS) {
169
- return;
170
- }
171
- this.lastSave = now;
172
- const action = positionAction(media.currentTime, media.duration);
173
- if (action === 'save') {
174
- await this.store.set(this.positionKey, media.currentTime, media.duration).catch(() => undefined);
175
- }
176
- else if (action === 'clear') {
177
- await this.store.clear?.(this.positionKey).catch(() => undefined);
178
- }
179
- }
180
- startAt(secs) {
181
- this.stored = null;
182
- this.phase = 'buffering';
183
- this.resumeAt = secs;
184
- const media = this.media;
185
- if (media) {
186
- if (secs > 0) {
187
- media.currentTime = secs;
188
- }
189
- void media.play?.()?.catch?.(() => undefined);
190
- }
191
- }
192
- retry() {
193
- const media = this.media;
194
- const at = media?.currentTime || this.resumeAt;
195
- this.phase = 'buffering';
196
- if (media) {
197
- media.load?.();
198
- this.startAt(at);
199
- }
200
- }
201
- onError() {
202
- const code = this.media?.error?.code;
203
- // 2: the network dropped (the node went away or the session ended). 3 and 4: the browser cannot decode it.
204
- this.phase = code === 2 ? 'stopped' : 'unsupported';
205
- }
206
- bindMedia(el) {
207
- if (!el || el === this.media) {
208
- return;
209
- }
210
- this.media = el;
211
- }
212
- renderStage() {
213
- switch (this.phase) {
214
- case 'prompt':
215
- return (h("div", { class: "stage-msg", "data-phase": "prompt" }, h("b", null, "Resume from ", formatClock(this.stored.secs), "?"), h("span", null, "You stopped here on ", formatDay(this.stored.at), ". ", formatClock(this.stored.duration), " in total."), h("div", { class: "row" }, h("button", { type: "button", class: "btn", onClick: () => this.startAt(0) }, "Start over"), h("button", { type: "button", class: "btn pri", onClick: () => this.startAt(this.stored.secs) }, "Resume"))));
216
- case 'buffering':
217
- return (h("div", { class: "stage-msg overlay-msg", "data-phase": "buffering" }, h("span", { class: "spin", "aria-hidden": "true" }), h("b", null, "Buffering"), this.ready !== undefined && h("span", null, formatBytes(this.ready), " ready from the start")));
218
- case 'waiting':
219
- return (h("div", { class: "stage-msg overlay-msg", "data-phase": "waiting" }, h("span", { class: "spin", "aria-hidden": "true" }), h("b", null, "Waiting for this part to download"), h("span", null, "You skipped ahead of what the node has. Playback resumes by itself.")));
220
- case 'unsupported':
221
- return (h("div", { class: "stage-msg", "data-phase": "unsupported" }, h(Icon, { name: "warn", size: 28 }), h("b", null, "This browser cannot play this format"), h("span", null, "The download is not affected. Download the file to play it in another app."), h("a", { class: "btn pri", href: this.src, download: this.name }, "Download file")));
222
- case 'stopped':
223
- return (h("div", { class: "stage-msg", "data-phase": "stopped" }, h(Icon, { name: "signal", size: 28 }), h("b", null, "Playback stopped"), h("span", null, "The connection to the node was lost."), h("button", { type: "button", class: "btn pri", onClick: () => this.retry() }, "Try again")));
224
- case 'casting':
225
- return (h("div", { class: "stage-msg", "data-phase": "casting" }, h(Icon, { name: "cast", size: 28 }), h("b", null, "Playing on ", this.castDevice ?? 'your TV'), h("span", null, "The TV reads the file from the node. You can close this tab."), h("span", { class: "clock" }, formatClock(this.currentTime), " / ", formatClock(this.duration)), h("button", { type: "button", class: "btn", onClick: () => void this.remote()?.prompt().catch(() => undefined) }, "Stop casting")));
226
- default:
227
- return null;
228
- }
229
- }
230
- render() {
231
- const audio = this.audio;
232
- const blocked = castBlocker(this.name, this.mime);
233
- const airplay = typeof this.media?.webkitShowPlaybackTargetPicker === 'function';
234
- const hideMedia = this.phase === 'prompt' || this.phase === 'unsupported' || this.phase === 'stopped' || this.phase === 'casting';
235
- const common = {
236
- ref: (el) => this.bindMedia(el),
237
- src: this.castSrc ?? this.src,
238
- controls: true,
239
- // Play was pressed to get here; a stored position asks first (G6).
240
- preload: this.phase === 'prompt' ? 'metadata' : 'auto',
241
- autoplay: !this.positionPrompted,
242
- playsInline: true,
243
- class: { hidden: hideMedia },
244
- onCanPlay: () => {
245
- if (this.phase === 'buffering' || this.phase === 'waiting') {
246
- this.phase = 'playing';
247
- }
248
- },
249
- onPlaying: () => {
250
- this.everPlayed = true;
251
- if (this.phase !== 'casting') {
252
- this.phase = 'playing';
253
- }
254
- },
255
- onWaiting: () => {
256
- if (this.phase === 'playing') {
257
- this.phase = this.everPlayed ? 'waiting' : 'buffering';
258
- }
259
- },
260
- onTimeUpdate: (e) => {
261
- const m = e.target;
262
- this.currentTime = m.currentTime;
263
- void this.savePosition();
264
- },
265
- onDurationChange: (e) => (this.duration = e.target.duration || 0),
266
- onPause: () => void this.savePosition(true),
267
- onError: () => this.onError(),
268
- };
269
- return (h(Host, { key: '2a0961d6bb91d0d28c516e42b11c8988a7721c99', class: { audio } }, h("header", { key: 'c2339f0ca216eb347a09c9be77df877a54cf8b47', class: "bar" }, h("span", { key: 'ae5b874219ff03c803febb079027549ee68751b6', class: "nm", title: this.name }, this.name), this.status && h("span", { key: '09ccaae203ecb0c205bd2e4b1ac9fc2f5d9b22a1', class: "pill" }, this.status), h("span", { key: '7304adbb0b50a3bcf8c4783f3444029f97e84fa9', class: "sp" }), !audio && (this.castAvailable || blocked) && (h("button", { key: '5c2b9d5d36ae0fd723d81da54e8e4acbf79a39d0', type: "button", class: "ib", disabled: !!blocked, title: blocked ?? 'Cast', "aria-label": blocked ? `Cast unavailable: ${blocked}` : 'Cast', onClick: () => void this.cast() }, h(Icon, { key: 'f45d71a1a5b1144376b6360812185dcbc7e5e57f', name: "cast", size: 15 }))), h("button", { key: '71964d197aee9de089f895fd0c017e1e4e04297a', type: "button", class: "ib", title: "Copy link for VLC", "aria-label": "Copy link for VLC", onClick: () => void this.copyLink() }, h(Icon, { key: '643d026d4dd85cad24e1e6b01dcba1bfda956825', name: "link", size: 15 })), !audio && airplay && (h("button", { key: 'a42d75246d807366e427b660062b47cc03890fac', type: "button", class: "ib", title: "AirPlay", "aria-label": "AirPlay", onClick: () => this.media.webkitShowPlaybackTargetPicker() }, h(Icon, { key: '21c9dc4e3ea560f72d230b017f2f73314ae17ef4', name: "cast", size: 15 }))), h("button", { key: 'f1413cec5dceb9f1dfe9b0470d3784ccaf20d08a', type: "button", class: "ib", "aria-label": "Close player", title: "Close", onClick: () => void this.close() }, h(Icon, { key: '707e719e7608edbad68185c8071ab90e2da614d4', name: "x", size: 14 }))), h("div", { key: '51673733f9cd732cfe5f1b9406ddec3787ba0e6c', class: { stage: true, audio }, "data-phase": this.phase }, audio ? h("audio", { ...common }) : h("video", { ...common }), this.renderStage()), this.linkNote && (h("p", { key: 'bd2db764da4183f67d1589a8be5aa4e8e7df76f3', class: "link-note", role: "status" }, this.linkNote))));
270
- }
271
- static get is() { return "phirepass-media-player"; }
272
- static get encapsulation() { return "shadow"; }
273
- static get originalStyleUrls() {
274
- return {
275
- "$": ["phirepass-media-player.css"]
276
- };
277
- }
278
- static get styleUrls() {
279
- return {
280
- "$": ["phirepass-media-player.css"]
281
- };
282
- }
283
- static get properties() {
284
- return {
285
- "src": {
286
- "type": "string",
287
- "mutable": false,
288
- "complexType": {
289
- "original": "string",
290
- "resolved": "string",
291
- "references": {}
292
- },
293
- "required": true,
294
- "optional": false,
295
- "docs": {
296
- "tags": [],
297
- "text": "The stream URL: `/api/web/stream/{node}/{download}/{file}` or a listing token URL."
298
- },
299
- "getter": false,
300
- "setter": false,
301
- "reflect": false,
302
- "attribute": "src"
303
- },
304
- "name": {
305
- "type": "string",
306
- "mutable": false,
307
- "complexType": {
308
- "original": "string",
309
- "resolved": "string",
310
- "references": {}
311
- },
312
- "required": true,
313
- "optional": false,
314
- "docs": {
315
- "tags": [],
316
- "text": ""
317
- },
318
- "getter": false,
319
- "setter": false,
320
- "reflect": false,
321
- "attribute": "name"
322
- },
323
- "mime": {
324
- "type": "string",
325
- "mutable": false,
326
- "complexType": {
327
- "original": "string",
328
- "resolved": "string",
329
- "references": {}
330
- },
331
- "required": false,
332
- "optional": true,
333
- "docs": {
334
- "tags": [],
335
- "text": "Overrides the mime the extension implies."
336
- },
337
- "getter": false,
338
- "setter": false,
339
- "reflect": false,
340
- "attribute": "mime"
341
- },
342
- "status": {
343
- "type": "string",
344
- "mutable": false,
345
- "complexType": {
346
- "original": "string",
347
- "resolved": "string",
348
- "references": {}
349
- },
350
- "required": false,
351
- "optional": true,
352
- "docs": {
353
- "tags": [],
354
- "text": "The status line above the picture, from the job: \u201CDownloading \u00B7 23.4%\u201D, \u201COn the node\u201D."
355
- },
356
- "getter": false,
357
- "setter": false,
358
- "reflect": false,
359
- "attribute": "status"
360
- },
361
- "ready": {
362
- "type": "number",
363
- "mutable": false,
364
- "complexType": {
365
- "original": "number",
366
- "resolved": "number",
367
- "references": {}
368
- },
369
- "required": false,
370
- "optional": true,
371
- "docs": {
372
- "tags": [],
373
- "text": "Bytes ready from the start of the file, while it is still downloading."
374
- },
375
- "getter": false,
376
- "setter": false,
377
- "reflect": false,
378
- "attribute": "ready"
379
- },
380
- "positionStore": {
381
- "type": "unknown",
382
- "mutable": false,
383
- "complexType": {
384
- "original": "PositionStore",
385
- "resolved": "{ get(key: string): Promise<StoredPosition>; set(key: string, secs: number, duration: number): Promise<void>; clear?(key: string): Promise<void>; }",
386
- "references": {
387
- "PositionStore": {
388
- "location": "import",
389
- "path": "./player",
390
- "id": "src/components/phirepass-media-player/player.ts::PositionStore",
391
- "referenceLocation": "PositionStore"
392
- }
393
- }
394
- },
395
- "required": false,
396
- "optional": true,
397
- "docs": {
398
- "tags": [],
399
- "text": "\u201CContinue watching\u201D. Without one, positions stay in this browser."
400
- },
401
- "getter": false,
402
- "setter": false
403
- },
404
- "positionKey": {
405
- "type": "string",
406
- "mutable": false,
407
- "complexType": {
408
- "original": "string",
409
- "resolved": "string",
410
- "references": {}
411
- },
412
- "required": false,
413
- "optional": true,
414
- "docs": {
415
- "tags": [],
416
- "text": "Key for the stored position: `dl:<download_id>:<file>` or `node:<node_id>:<path>`."
417
- },
418
- "getter": false,
419
- "setter": false,
420
- "reflect": false,
421
- "attribute": "position-key"
422
- },
423
- "remotePlayback": {
424
- "type": "unknown",
425
- "mutable": false,
426
- "complexType": {
427
- "original": "RemotePlaybackLike",
428
- "resolved": "{ state: \"connected\" | \"disconnected\" | \"connecting\"; watchAvailability(cb: (available: boolean) => void): Promise<number>; cancelWatchAvailability(id?: number): Promise<void>; prompt(): Promise<void>; addEventListener(type: \"connect\" | \"disconnect\" | \"connecting\", cb: () => void): void; removeEventListener(type: \"connect\" | \"disconnect\" | \"connecting\", cb: () => void): void; }",
429
- "references": {
430
- "RemotePlaybackLike": {
431
- "location": "import",
432
- "path": "./player",
433
- "id": "src/components/phirepass-media-player/player.ts::RemotePlaybackLike",
434
- "referenceLocation": "RemotePlaybackLike"
435
- }
436
- }
437
- },
438
- "required": false,
439
- "optional": true,
440
- "docs": {
441
- "tags": [],
442
- "text": "Stands in for `video.remote`, for demos and tests (like `channelFactory`)."
443
- },
444
- "getter": false,
445
- "setter": false
446
- },
447
- "linkMinter": {
448
- "type": "unknown",
449
- "mutable": false,
450
- "complexType": {
451
- "original": "LinkMinter",
452
- "resolved": "(src: string) => Promise<string>",
453
- "references": {
454
- "LinkMinter": {
455
- "location": "import",
456
- "path": "./player",
457
- "id": "src/components/phirepass-media-player/player.ts::LinkMinter",
458
- "referenceLocation": "LinkMinter"
459
- }
460
- }
461
- },
462
- "required": false,
463
- "optional": true,
464
- "docs": {
465
- "tags": [],
466
- "text": "Makes the link a TV or VLC opens (T2.9). Defaults to POSTing `src`."
467
- },
468
- "getter": false,
469
- "setter": false
470
- },
471
- "castDevice": {
472
- "type": "string",
473
- "mutable": false,
474
- "complexType": {
475
- "original": "string",
476
- "resolved": "string",
477
- "references": {}
478
- },
479
- "required": false,
480
- "optional": true,
481
- "docs": {
482
- "tags": [],
483
- "text": "Shown while casting, when the host knows the device's name."
484
- },
485
- "getter": false,
486
- "setter": false,
487
- "reflect": false,
488
- "attribute": "cast-device"
489
- }
490
- };
491
- }
492
- static get states() {
493
- return {
494
- "phase": {},
495
- "stored": {},
496
- "castAvailable": {},
497
- "castSrc": {},
498
- "linkNote": {},
499
- "currentTime": {},
500
- "duration": {}
501
- };
502
- }
503
- static get events() {
504
- return [{
505
- "method": "playerClose",
506
- "name": "phirepassPlayerClose",
507
- "bubbles": true,
508
- "cancelable": true,
509
- "composed": true,
510
- "docs": {
511
- "tags": [],
512
- "text": ""
513
- },
514
- "complexType": {
515
- "original": "void",
516
- "resolved": "void",
517
- "references": {}
518
- }
519
- }];
520
- }
521
- static get methods() {
522
- return {
523
- "close": {
524
- "complexType": {
525
- "signature": "() => Promise<void>",
526
- "parameters": [],
527
- "references": {
528
- "Promise": {
529
- "location": "global",
530
- "id": "global::Promise"
531
- }
532
- },
533
- "return": "Promise<void>"
534
- },
535
- "docs": {
536
- "text": "Closes the player, saving where it stopped. The download is not affected.",
537
- "tags": []
538
- }
539
- }
540
- };
541
- }
542
- static get elementRef() { return "el"; }
543
- static get watchers() {
544
- return [{
545
- "propName": "src",
546
- "methodName": "onSrc"
547
- }];
548
- }
549
- }
@@ -1,118 +0,0 @@
1
- const MIME = {
2
- mp4: 'video/mp4',
3
- m4v: 'video/mp4',
4
- webm: 'video/webm',
5
- mkv: 'video/x-matroska',
6
- mov: 'video/quicktime',
7
- mp3: 'audio/mpeg',
8
- m4a: 'audio/mp4',
9
- flac: 'audio/flac',
10
- ogg: 'audio/ogg',
11
- oga: 'audio/ogg',
12
- opus: 'audio/ogg',
13
- wav: 'audio/wav',
14
- };
15
- export function extOf(name) {
16
- const m = /\.([a-z0-9]+)$/i.exec(name);
17
- return m ? m[1].toLowerCase() : '';
18
- }
19
- /** Mime from the extension, as the agent's stream server decides it. */
20
- export function mimeFor(name) {
21
- return MIME[extOf(name)] ?? 'application/octet-stream';
22
- }
23
- export function isAudio(name, mime) {
24
- return (mime ?? mimeFor(name)).startsWith('audio/');
25
- }
26
- export function isPlayableName(name) {
27
- return extOf(name) in MIME;
28
- }
29
- /**
30
- * Whether a Cast receiver can play this. The Default Media Receiver plays MP4
31
- * (H.264/AAC), WebM and common audio, mostly not MKV or MOV.
32
- */
33
- export function castBlocker(name, mime) {
34
- const m = mime ?? mimeFor(name);
35
- if (m === 'video/x-matroska') {
36
- return 'TVs cannot play MKV files. Download it and play it with VLC.';
37
- }
38
- if (m === 'video/quicktime') {
39
- return 'TVs cannot play MOV files.';
40
- }
41
- return null;
42
- }
43
- /** `src` with its ticket, absolute, since it leaves this page. */
44
- export function ticketUrl(src, ticket, base = globalThis.location?.href) {
45
- // An invalid base throws even for an absolute src, so it is used only
46
- // when src needs one.
47
- const url = /^[a-z][a-z0-9+.-]*:/i.test(src) ? new URL(src) : new URL(src, base);
48
- url.searchParams.set('ticket', ticket);
49
- return url.href;
50
- }
51
- /** POSTs the stream URL with the session cookie; the server answers `{ ticket }`. */
52
- export function fetchLinkMinter(fetcher = (input, init) => fetch(input, init)) {
53
- return async (src) => {
54
- try {
55
- const res = await fetcher(src, { method: 'POST', credentials: 'include' });
56
- if (!res.ok) {
57
- return null;
58
- }
59
- const body = (await res.json());
60
- return typeof body.ticket === 'string' && body.ticket ? ticketUrl(src, body.ticket) : null;
61
- }
62
- catch {
63
- return null;
64
- }
65
- };
66
- }
67
- /** Nothing is saved in the first 30 seconds. */
68
- export const SAVE_AFTER_SECS = 30;
69
- export const SAVE_EVERY_MS = 10_000;
70
- /** Past 95%, or within the last two minutes, the file counts as watched and the position is cleared. */
71
- export function isWatched(secs, duration) {
72
- if (!Number.isFinite(duration) || duration <= 0) {
73
- return false;
74
- }
75
- return secs >= duration * 0.95 || duration - secs <= 120;
76
- }
77
- export function positionAction(secs, duration) {
78
- if (isWatched(secs, duration)) {
79
- return 'clear';
80
- }
81
- if (secs < SAVE_AFTER_SECS) {
82
- return 'skip';
83
- }
84
- return 'save';
85
- }
86
- const LS_PREFIX = 'phirepass.player.position.';
87
- /** The fallback store, per browser. Every access is guarded: storage can be missing or refuse. */
88
- export const localPositionStore = {
89
- async get(key) {
90
- try {
91
- const raw = window.localStorage.getItem(LS_PREFIX + key);
92
- if (!raw) {
93
- return null;
94
- }
95
- const value = JSON.parse(raw);
96
- return typeof value?.secs === 'number' ? value : null;
97
- }
98
- catch {
99
- return null;
100
- }
101
- },
102
- async set(key, secs, duration) {
103
- try {
104
- window.localStorage.setItem(LS_PREFIX + key, JSON.stringify({ secs, duration, at: Date.now() }));
105
- }
106
- catch {
107
- // Nothing to do: the next visit starts from the beginning.
108
- }
109
- },
110
- async clear(key) {
111
- try {
112
- window.localStorage.removeItem(LS_PREFIX + key);
113
- }
114
- catch {
115
- // ignore
116
- }
117
- },
118
- };