@matreshka/bff 0.37.0 → 0.38.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.
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { Audio, MediaConfig, Video } from "./media";
|
|
1
3
|
import { Platform } from "./platform";
|
|
2
4
|
/**
|
|
3
5
|
* Абстрактный класс, реализующий любую клиентскую платформу.
|
|
4
6
|
*/
|
|
5
7
|
export declare abstract class ClientPlatform extends Platform {
|
|
8
|
+
/**
|
|
9
|
+
* Создаёт `HTMLAudioElement` на клиенте вне DOM.
|
|
10
|
+
* Hot: элемент создаётся при вызове. Observable эмитит объект после ack.
|
|
11
|
+
*/
|
|
12
|
+
createAudio(config?: MediaConfig): Observable<Audio>;
|
|
13
|
+
/**
|
|
14
|
+
* Создаёт `HTMLVideoElement` на клиенте вне DOM.
|
|
15
|
+
* `Video.id` — ключ реестра, который позже сможет забрать видеокомпонент.
|
|
16
|
+
*/
|
|
17
|
+
createVideo(config?: MediaConfig): Observable<Video>;
|
|
6
18
|
}
|
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClientPlatform = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const media_1 = require("./media");
|
|
4
6
|
const platform_1 = require("./platform");
|
|
5
7
|
/**
|
|
6
8
|
* Абстрактный класс, реализующий любую клиентскую платформу.
|
|
7
9
|
*/
|
|
8
10
|
class ClientPlatform extends platform_1.Platform {
|
|
11
|
+
/**
|
|
12
|
+
* Создаёт `HTMLAudioElement` на клиенте вне DOM.
|
|
13
|
+
* Hot: элемент создаётся при вызове. Observable эмитит объект после ack.
|
|
14
|
+
*/
|
|
15
|
+
createAudio(config = {}) {
|
|
16
|
+
const audio = new media_1.Audio(this.client, config);
|
|
17
|
+
return audio.open().pipe((0, rxjs_1.map)(() => audio));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Создаёт `HTMLVideoElement` на клиенте вне DOM.
|
|
21
|
+
* `Video.id` — ключ реестра, который позже сможет забрать видеокомпонент.
|
|
22
|
+
*/
|
|
23
|
+
createVideo(config = {}) {
|
|
24
|
+
const video = new media_1.Video(this.client, config);
|
|
25
|
+
return video.open().pipe((0, rxjs_1.map)(() => video));
|
|
26
|
+
}
|
|
9
27
|
}
|
|
10
28
|
exports.ClientPlatform = ClientPlatform;
|
|
@@ -3,6 +3,7 @@ export * from "./browser-platform";
|
|
|
3
3
|
export * from "./client-platform";
|
|
4
4
|
export * from "./ios-platform";
|
|
5
5
|
export * from "./max-mini-app-platform";
|
|
6
|
+
export * from "./media";
|
|
6
7
|
export * from "./mobile-platform";
|
|
7
8
|
export * from "./platform";
|
|
8
9
|
export * from "./popover-show";
|
package/dist/platforms/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./browser-platform"), exports);
|
|
|
19
19
|
__exportStar(require("./client-platform"), exports);
|
|
20
20
|
__exportStar(require("./ios-platform"), exports);
|
|
21
21
|
__exportStar(require("./max-mini-app-platform"), exports);
|
|
22
|
+
__exportStar(require("./media"), exports);
|
|
22
23
|
__exportStar(require("./mobile-platform"), exports);
|
|
23
24
|
__exportStar(require("./platform"), exports);
|
|
24
25
|
__exportStar(require("./popover-show"), exports);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { MediaCrossOrigin } from "@matreshka/client-bff-protocol/enums/media-cross-origin";
|
|
2
|
+
import { MediaKind } from "@matreshka/client-bff-protocol/enums/media-kind";
|
|
3
|
+
import { MediaPreload } from "@matreshka/client-bff-protocol/enums/media-preload";
|
|
4
|
+
import { AnyBffToClientMessage } from "@matreshka/client-bff-protocol/messages/bff-to-client/bff-to-client-message";
|
|
5
|
+
import type { MediaElementConfig } from "@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-create-message";
|
|
6
|
+
import { Observable } from "rxjs";
|
|
7
|
+
import { ServerAction, type ServerActionHandler } from "../components/actions/server-action";
|
|
8
|
+
import { LocalAction } from "../core/actions/local-action";
|
|
9
|
+
import type { Client } from "../core/client";
|
|
10
|
+
import type { Componentable } from "../core/types/componentable";
|
|
11
|
+
export { MediaCrossOrigin, MediaKind, MediaPreload };
|
|
12
|
+
export type MediaProgressPayload = {
|
|
13
|
+
currentTime: number;
|
|
14
|
+
duration: number;
|
|
15
|
+
};
|
|
16
|
+
export type MediaVolumePayload = {
|
|
17
|
+
volume: number;
|
|
18
|
+
muted: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type MediaRatePayload = {
|
|
21
|
+
playbackRate: number;
|
|
22
|
+
};
|
|
23
|
+
export type MediaErrorPayload = {
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
/** Одно действие или массив локальных и серверных, как `onClick` у компонента. */
|
|
27
|
+
export type MediaAction<Payload> = ServerAction<Componentable, Payload> | ServerActionHandler<Componentable, Payload> | LocalAction;
|
|
28
|
+
export type MediaActionList<Payload> = MediaAction<Payload> | MediaAction<Payload>[];
|
|
29
|
+
export type MediaEventConfig = {
|
|
30
|
+
onPlay?: MediaActionList<MediaProgressPayload>;
|
|
31
|
+
onPause?: MediaActionList<MediaProgressPayload>;
|
|
32
|
+
onPlaying?: MediaActionList<MediaProgressPayload>;
|
|
33
|
+
onWaiting?: MediaActionList<MediaProgressPayload>;
|
|
34
|
+
onEnded?: MediaActionList<MediaProgressPayload>;
|
|
35
|
+
onError?: MediaActionList<MediaErrorPayload>;
|
|
36
|
+
onLoadedMetadata?: MediaActionList<MediaProgressPayload>;
|
|
37
|
+
onSeeking?: MediaActionList<MediaProgressPayload>;
|
|
38
|
+
onSeeked?: MediaActionList<MediaProgressPayload>;
|
|
39
|
+
onVolumeChange?: MediaActionList<MediaVolumePayload>;
|
|
40
|
+
onRateChange?: MediaActionList<MediaRatePayload>;
|
|
41
|
+
onTimeUpdate?: MediaActionList<MediaProgressPayload>;
|
|
42
|
+
onEnterPictureInPicture?: MediaActionList<Record<string, never>>;
|
|
43
|
+
onLeavePictureInPicture?: MediaActionList<Record<string, never>>;
|
|
44
|
+
};
|
|
45
|
+
export type MediaConfig = MediaElementConfig & MediaEventConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Сессия `HTMLMediaElement` на клиенте. Элемент не входит в дерево компонентов.
|
|
48
|
+
* `id` — ключ клиентского реестра для будущего видеокомпонента.
|
|
49
|
+
*/
|
|
50
|
+
export declare abstract class Media {
|
|
51
|
+
protected readonly client: Client;
|
|
52
|
+
private readonly kind;
|
|
53
|
+
readonly id: string;
|
|
54
|
+
private readonly handlers;
|
|
55
|
+
private readonly rawConfig;
|
|
56
|
+
private sessionSubscription?;
|
|
57
|
+
private clientDestroySubscription?;
|
|
58
|
+
private ended;
|
|
59
|
+
constructor(client: Client, config: MediaConfig, kind: MediaKind);
|
|
60
|
+
play(): Observable<void>;
|
|
61
|
+
pause(): Observable<void>;
|
|
62
|
+
load(): Observable<void>;
|
|
63
|
+
seek(time: number): Observable<void>;
|
|
64
|
+
setSrc(src: string): Observable<void>;
|
|
65
|
+
setVolume(volume: number): Observable<void>;
|
|
66
|
+
setMuted(muted: boolean): Observable<void>;
|
|
67
|
+
setPlaybackRate(playbackRate: number): Observable<void>;
|
|
68
|
+
setLoop(loop: boolean): Observable<void>;
|
|
69
|
+
setPreload(preload: MediaPreload): Observable<void>;
|
|
70
|
+
destroy(): Observable<void>;
|
|
71
|
+
/** @internal */
|
|
72
|
+
open(): Observable<void>;
|
|
73
|
+
protected send(outgoingMessage: (scope: string) => AnyBffToClientMessage): Observable<void>;
|
|
74
|
+
private elementConfig;
|
|
75
|
+
private bindEvents;
|
|
76
|
+
private parseAction;
|
|
77
|
+
private serializeInteractions;
|
|
78
|
+
private startSession;
|
|
79
|
+
private emit;
|
|
80
|
+
private endSession;
|
|
81
|
+
}
|
|
82
|
+
export declare class Audio extends Media {
|
|
83
|
+
constructor(client: Client, config: MediaConfig);
|
|
84
|
+
}
|
|
85
|
+
export declare class Video extends Media {
|
|
86
|
+
constructor(client: Client, config: MediaConfig);
|
|
87
|
+
requestPictureInPicture(): Observable<void>;
|
|
88
|
+
exitPictureInPicture(): Observable<void>;
|
|
89
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Video = exports.Audio = exports.Media = exports.MediaPreload = exports.MediaKind = exports.MediaCrossOrigin = void 0;
|
|
4
|
+
const media_cross_origin_1 = require("@matreshka/client-bff-protocol/enums/media-cross-origin");
|
|
5
|
+
Object.defineProperty(exports, "MediaCrossOrigin", { enumerable: true, get: function () { return media_cross_origin_1.MediaCrossOrigin; } });
|
|
6
|
+
const media_kind_1 = require("@matreshka/client-bff-protocol/enums/media-kind");
|
|
7
|
+
Object.defineProperty(exports, "MediaKind", { enumerable: true, get: function () { return media_kind_1.MediaKind; } });
|
|
8
|
+
const media_preload_1 = require("@matreshka/client-bff-protocol/enums/media-preload");
|
|
9
|
+
Object.defineProperty(exports, "MediaPreload", { enumerable: true, get: function () { return media_preload_1.MediaPreload; } });
|
|
10
|
+
const media_create_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-create-message");
|
|
11
|
+
const media_destroy_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-destroy-message");
|
|
12
|
+
const media_exit_picture_in_picture_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-exit-picture-in-picture-message");
|
|
13
|
+
const media_load_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-load-message");
|
|
14
|
+
const media_pause_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-pause-message");
|
|
15
|
+
const media_play_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-play-message");
|
|
16
|
+
const media_request_picture_in_picture_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-request-picture-in-picture-message");
|
|
17
|
+
const media_seek_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-seek-message");
|
|
18
|
+
const media_set_loop_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-loop-message");
|
|
19
|
+
const media_set_muted_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-muted-message");
|
|
20
|
+
const media_set_playback_rate_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-playback-rate-message");
|
|
21
|
+
const media_set_preload_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-preload-message");
|
|
22
|
+
const media_set_src_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-src-message");
|
|
23
|
+
const media_set_volume_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-volume-message");
|
|
24
|
+
const media_event_messages_1 = require("@matreshka/client-bff-protocol/messages/client-to-bff/platforms/media-event-messages");
|
|
25
|
+
const rxjs_1 = require("rxjs");
|
|
26
|
+
const zod_1 = require("zod");
|
|
27
|
+
const server_action_1 = require("../components/actions/server-action");
|
|
28
|
+
const action_1 = require("../core/actions/action");
|
|
29
|
+
const local_action_1 = require("../core/actions/local-action");
|
|
30
|
+
const client_context_1 = require("../core/client-context");
|
|
31
|
+
const incoming_message_observer_1 = require("../core/utils/incoming-message-observer");
|
|
32
|
+
const targeted_client_platform_action_1 = require("./utils/targeted-client-platform-action");
|
|
33
|
+
function isMediaIncomingEvent(message) {
|
|
34
|
+
return (message instanceof media_event_messages_1.MediaPlayEventMessage ||
|
|
35
|
+
message instanceof media_event_messages_1.MediaPauseEventMessage ||
|
|
36
|
+
message instanceof media_event_messages_1.MediaPlayingEventMessage ||
|
|
37
|
+
message instanceof media_event_messages_1.MediaWaitingEventMessage ||
|
|
38
|
+
message instanceof media_event_messages_1.MediaEndedEventMessage ||
|
|
39
|
+
message instanceof media_event_messages_1.MediaLoadedMetadataEventMessage ||
|
|
40
|
+
message instanceof media_event_messages_1.MediaSeekingEventMessage ||
|
|
41
|
+
message instanceof media_event_messages_1.MediaSeekedEventMessage ||
|
|
42
|
+
message instanceof media_event_messages_1.MediaTimeUpdateEventMessage ||
|
|
43
|
+
message instanceof media_event_messages_1.MediaVolumeChangeEventMessage ||
|
|
44
|
+
message instanceof media_event_messages_1.MediaRateChangeEventMessage ||
|
|
45
|
+
message instanceof media_event_messages_1.MediaErrorEventMessage ||
|
|
46
|
+
message instanceof media_event_messages_1.MediaEnterPictureInPictureEventMessage ||
|
|
47
|
+
message instanceof media_event_messages_1.MediaLeavePictureInPictureEventMessage);
|
|
48
|
+
}
|
|
49
|
+
const mediaHandlersSchema = zod_1.z.array(zod_1.z.number().int().nonnegative());
|
|
50
|
+
const mediaProgressEventSchema = zod_1.z.strictObject({
|
|
51
|
+
currentTime: zod_1.z.number(),
|
|
52
|
+
duration: zod_1.z.number(),
|
|
53
|
+
handlers: mediaHandlersSchema,
|
|
54
|
+
});
|
|
55
|
+
const mediaVolumeEventSchema = zod_1.z.strictObject({
|
|
56
|
+
volume: zod_1.z.number(),
|
|
57
|
+
muted: zod_1.z.boolean(),
|
|
58
|
+
handlers: mediaHandlersSchema,
|
|
59
|
+
});
|
|
60
|
+
const mediaRateEventSchema = zod_1.z.strictObject({
|
|
61
|
+
playbackRate: zod_1.z.number(),
|
|
62
|
+
handlers: mediaHandlersSchema,
|
|
63
|
+
});
|
|
64
|
+
const mediaErrorEventSchema = zod_1.z.strictObject({
|
|
65
|
+
message: zod_1.z.string(),
|
|
66
|
+
handlers: mediaHandlersSchema,
|
|
67
|
+
});
|
|
68
|
+
const mediaPictureInPictureEventSchema = zod_1.z.strictObject({
|
|
69
|
+
handlers: mediaHandlersSchema,
|
|
70
|
+
});
|
|
71
|
+
function mediaEventSchema(message) {
|
|
72
|
+
if (message instanceof media_event_messages_1.MediaVolumeChangeEventMessage) {
|
|
73
|
+
return mediaVolumeEventSchema;
|
|
74
|
+
}
|
|
75
|
+
if (message instanceof media_event_messages_1.MediaRateChangeEventMessage) {
|
|
76
|
+
return mediaRateEventSchema;
|
|
77
|
+
}
|
|
78
|
+
if (message instanceof media_event_messages_1.MediaErrorEventMessage) {
|
|
79
|
+
return mediaErrorEventSchema;
|
|
80
|
+
}
|
|
81
|
+
if (message instanceof media_event_messages_1.MediaEnterPictureInPictureEventMessage ||
|
|
82
|
+
message instanceof media_event_messages_1.MediaLeavePictureInPictureEventMessage) {
|
|
83
|
+
return mediaPictureInPictureEventSchema;
|
|
84
|
+
}
|
|
85
|
+
return mediaProgressEventSchema;
|
|
86
|
+
}
|
|
87
|
+
function mediaEventName(message) {
|
|
88
|
+
if (message instanceof media_event_messages_1.MediaPlayEventMessage) {
|
|
89
|
+
return "play";
|
|
90
|
+
}
|
|
91
|
+
if (message instanceof media_event_messages_1.MediaPauseEventMessage) {
|
|
92
|
+
return "pause";
|
|
93
|
+
}
|
|
94
|
+
if (message instanceof media_event_messages_1.MediaPlayingEventMessage) {
|
|
95
|
+
return "playing";
|
|
96
|
+
}
|
|
97
|
+
if (message instanceof media_event_messages_1.MediaWaitingEventMessage) {
|
|
98
|
+
return "waiting";
|
|
99
|
+
}
|
|
100
|
+
if (message instanceof media_event_messages_1.MediaEndedEventMessage) {
|
|
101
|
+
return "ended";
|
|
102
|
+
}
|
|
103
|
+
if (message instanceof media_event_messages_1.MediaLoadedMetadataEventMessage) {
|
|
104
|
+
return "loadedmetadata";
|
|
105
|
+
}
|
|
106
|
+
if (message instanceof media_event_messages_1.MediaSeekingEventMessage) {
|
|
107
|
+
return "seeking";
|
|
108
|
+
}
|
|
109
|
+
if (message instanceof media_event_messages_1.MediaSeekedEventMessage) {
|
|
110
|
+
return "seeked";
|
|
111
|
+
}
|
|
112
|
+
if (message instanceof media_event_messages_1.MediaTimeUpdateEventMessage) {
|
|
113
|
+
return "timeupdate";
|
|
114
|
+
}
|
|
115
|
+
if (message instanceof media_event_messages_1.MediaVolumeChangeEventMessage) {
|
|
116
|
+
return "volumechange";
|
|
117
|
+
}
|
|
118
|
+
if (message instanceof media_event_messages_1.MediaRateChangeEventMessage) {
|
|
119
|
+
return "ratechange";
|
|
120
|
+
}
|
|
121
|
+
if (message instanceof media_event_messages_1.MediaErrorEventMessage) {
|
|
122
|
+
return "error";
|
|
123
|
+
}
|
|
124
|
+
if (message instanceof media_event_messages_1.MediaEnterPictureInPictureEventMessage) {
|
|
125
|
+
return "enterpictureinpicture";
|
|
126
|
+
}
|
|
127
|
+
return "leavepictureinpicture";
|
|
128
|
+
}
|
|
129
|
+
const EVENT_FIELDS = {
|
|
130
|
+
onPlay: "play",
|
|
131
|
+
onPause: "pause",
|
|
132
|
+
onPlaying: "playing",
|
|
133
|
+
onWaiting: "waiting",
|
|
134
|
+
onEnded: "ended",
|
|
135
|
+
onError: "error",
|
|
136
|
+
onLoadedMetadata: "loadedmetadata",
|
|
137
|
+
onSeeking: "seeking",
|
|
138
|
+
onSeeked: "seeked",
|
|
139
|
+
onVolumeChange: "volumechange",
|
|
140
|
+
onRateChange: "ratechange",
|
|
141
|
+
onTimeUpdate: "timeupdate",
|
|
142
|
+
onEnterPictureInPicture: "enterpictureinpicture",
|
|
143
|
+
onLeavePictureInPicture: "leavepictureinpicture",
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Сессия `HTMLMediaElement` на клиенте. Элемент не входит в дерево компонентов.
|
|
147
|
+
* `id` — ключ клиентского реестра для будущего видеокомпонента.
|
|
148
|
+
*/
|
|
149
|
+
class Media {
|
|
150
|
+
constructor(client, config, kind) {
|
|
151
|
+
this.client = client;
|
|
152
|
+
this.kind = kind;
|
|
153
|
+
this.id = "media-" + crypto.randomUUID();
|
|
154
|
+
this.handlers = new Map();
|
|
155
|
+
this.ended = false;
|
|
156
|
+
this.rawConfig = config;
|
|
157
|
+
this.bindEvents(config);
|
|
158
|
+
}
|
|
159
|
+
play() {
|
|
160
|
+
return this.send((scope) => new media_play_message_1.MediaPlayMessage(scope, { mediaId: this.id }));
|
|
161
|
+
}
|
|
162
|
+
pause() {
|
|
163
|
+
return this.send((scope) => new media_pause_message_1.MediaPauseMessage(scope, { mediaId: this.id }));
|
|
164
|
+
}
|
|
165
|
+
load() {
|
|
166
|
+
return this.send((scope) => new media_load_message_1.MediaLoadMessage(scope, { mediaId: this.id }));
|
|
167
|
+
}
|
|
168
|
+
seek(time) {
|
|
169
|
+
return this.send((scope) => new media_seek_message_1.MediaSeekMessage(scope, { mediaId: this.id, time }));
|
|
170
|
+
}
|
|
171
|
+
setSrc(src) {
|
|
172
|
+
return this.send((scope) => new media_set_src_message_1.MediaSetSrcMessage(scope, { mediaId: this.id, src }));
|
|
173
|
+
}
|
|
174
|
+
setVolume(volume) {
|
|
175
|
+
return this.send((scope) => new media_set_volume_message_1.MediaSetVolumeMessage(scope, { mediaId: this.id, volume }));
|
|
176
|
+
}
|
|
177
|
+
setMuted(muted) {
|
|
178
|
+
return this.send((scope) => new media_set_muted_message_1.MediaSetMutedMessage(scope, { mediaId: this.id, muted }));
|
|
179
|
+
}
|
|
180
|
+
setPlaybackRate(playbackRate) {
|
|
181
|
+
return this.send((scope) => new media_set_playback_rate_message_1.MediaSetPlaybackRateMessage(scope, {
|
|
182
|
+
mediaId: this.id,
|
|
183
|
+
playbackRate,
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
setLoop(loop) {
|
|
187
|
+
return this.send((scope) => new media_set_loop_message_1.MediaSetLoopMessage(scope, { mediaId: this.id, loop }));
|
|
188
|
+
}
|
|
189
|
+
setPreload(preload) {
|
|
190
|
+
return this.send((scope) => new media_set_preload_message_1.MediaSetPreloadMessage(scope, { mediaId: this.id, preload }));
|
|
191
|
+
}
|
|
192
|
+
destroy() {
|
|
193
|
+
if (this.ended) {
|
|
194
|
+
return (0, rxjs_1.of)(undefined);
|
|
195
|
+
}
|
|
196
|
+
return this.send((scope) => new media_destroy_message_1.MediaDestroyMessage(scope, { mediaId: this.id })).pipe((0, rxjs_1.tap)(() => this.endSession()));
|
|
197
|
+
}
|
|
198
|
+
/** @internal */
|
|
199
|
+
open() {
|
|
200
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
201
|
+
outgoingMessage: (scope) => (0, client_context_1.runWithClient)(this.client, () => new media_create_message_1.MediaCreateMessage(scope, {
|
|
202
|
+
mediaId: this.id,
|
|
203
|
+
kind: this.kind,
|
|
204
|
+
config: this.elementConfig(),
|
|
205
|
+
interactions: this.serializeInteractions(),
|
|
206
|
+
})),
|
|
207
|
+
}).pipe((0, rxjs_1.tap)(() => this.startSession()));
|
|
208
|
+
}
|
|
209
|
+
send(outgoingMessage) {
|
|
210
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
211
|
+
outgoingMessage,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
elementConfig() {
|
|
215
|
+
const config = this.rawConfig;
|
|
216
|
+
return {
|
|
217
|
+
src: config.src,
|
|
218
|
+
volume: config.volume,
|
|
219
|
+
muted: config.muted,
|
|
220
|
+
loop: config.loop,
|
|
221
|
+
playbackRate: config.playbackRate,
|
|
222
|
+
preload: config.preload,
|
|
223
|
+
crossOrigin: config.crossOrigin,
|
|
224
|
+
autoplay: config.autoplay,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
bindEvents(config) {
|
|
228
|
+
Object.keys(EVENT_FIELDS).forEach((field) => {
|
|
229
|
+
const actions = config[field];
|
|
230
|
+
if (actions === undefined) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const list = (Array.isArray(actions) ? actions : [actions]).map((action) => this.parseAction(action));
|
|
234
|
+
this.handlers.set(EVENT_FIELDS[field], list);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
parseAction(action) {
|
|
238
|
+
if (action instanceof local_action_1.LocalAction || action instanceof server_action_1.ServerAction) {
|
|
239
|
+
return action;
|
|
240
|
+
}
|
|
241
|
+
if (action instanceof action_1.Action) {
|
|
242
|
+
throw new Error("Media events accept LocalAction, ServerAction, or a server function");
|
|
243
|
+
}
|
|
244
|
+
return new server_action_1.ServerAction(action);
|
|
245
|
+
}
|
|
246
|
+
serializeInteractions() {
|
|
247
|
+
const interactions = {};
|
|
248
|
+
this.handlers.forEach((actions, event) => {
|
|
249
|
+
interactions[event] = actions.map((action) => action.toJSON());
|
|
250
|
+
});
|
|
251
|
+
return interactions;
|
|
252
|
+
}
|
|
253
|
+
startSession() {
|
|
254
|
+
if (this.sessionSubscription || this.ended) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
this.sessionSubscription = this.client.incomingMessage$
|
|
258
|
+
.pipe((0, rxjs_1.filter)((message) => isMediaIncomingEvent(message) && message.target === this.id))
|
|
259
|
+
.subscribe((0, incoming_message_observer_1.incomingMessageObserver)(this.client, (message) => {
|
|
260
|
+
const parsed = mediaEventSchema(message).safeParse(message.payload);
|
|
261
|
+
if (!parsed.success) {
|
|
262
|
+
this.client.error$.next(`Invalid media event payload: ${message.type}`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const { handlers, ...payload } = parsed.data;
|
|
266
|
+
this.emit(mediaEventName(message), payload, handlers);
|
|
267
|
+
}));
|
|
268
|
+
this.clientDestroySubscription = this.client.destroy$
|
|
269
|
+
.pipe((0, rxjs_1.take)(1))
|
|
270
|
+
.subscribe(() => this.endSession());
|
|
271
|
+
}
|
|
272
|
+
emit(event, payload, handlers) {
|
|
273
|
+
const actions = this.handlers.get(event);
|
|
274
|
+
if (!actions) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
for (const index of handlers) {
|
|
278
|
+
const action = actions[index];
|
|
279
|
+
if (!(action instanceof server_action_1.ServerAction)) {
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
action.execute({
|
|
283
|
+
payload,
|
|
284
|
+
instance: { client: this.client },
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
endSession() {
|
|
289
|
+
if (this.ended) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
this.ended = true;
|
|
293
|
+
this.sessionSubscription?.unsubscribe();
|
|
294
|
+
this.clientDestroySubscription?.unsubscribe();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
exports.Media = Media;
|
|
298
|
+
class Audio extends Media {
|
|
299
|
+
constructor(client, config) {
|
|
300
|
+
super(client, config, media_kind_1.MediaKind.Audio);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
exports.Audio = Audio;
|
|
304
|
+
class Video extends Media {
|
|
305
|
+
constructor(client, config) {
|
|
306
|
+
super(client, config, media_kind_1.MediaKind.Video);
|
|
307
|
+
}
|
|
308
|
+
requestPictureInPicture() {
|
|
309
|
+
return this.send((scope) => new media_request_picture_in_picture_message_1.MediaRequestPictureInPictureMessage(scope, { mediaId: this.id }));
|
|
310
|
+
}
|
|
311
|
+
exitPictureInPicture() {
|
|
312
|
+
return this.send((scope) => new media_exit_picture_in_picture_message_1.MediaExitPictureInPictureMessage(scope, { mediaId: this.id }));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
exports.Video = Video;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matreshka/bff",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Matreshka BFF: server-driven UI runtime — routing, pages, context, component DSL, and platform APIs",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vitest": "^4.1.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@matreshka/client-bff-protocol": "^0.
|
|
65
|
+
"@matreshka/client-bff-protocol": "^0.7.0",
|
|
66
66
|
"@matreshka/gateway-bff-protocol": "^0.1.0",
|
|
67
67
|
"@matreshka/shared": "^0.26.0",
|
|
68
68
|
"@simplewebauthn/server": "^13.1.1",
|