chuvsu-js 5.4.1 → 5.5.1

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 (73) hide show
  1. package/README.md +33 -3
  2. package/dist/common/http.d.ts +3 -1
  3. package/dist/common/http.js +9 -2
  4. package/dist/{tt/utils → common}/lesson-type.d.ts +4 -2
  5. package/dist/{tt/utils → common}/lesson-type.js +17 -2
  6. package/dist/core.d.ts +13 -5
  7. package/dist/core.js +7 -2
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.js +1 -0
  10. package/dist/lk/client.d.ts +23 -1
  11. package/dist/lk/client.js +95 -0
  12. package/dist/lk/parse/grade-value.d.ts +4 -0
  13. package/dist/lk/parse/grade-value.js +16 -0
  14. package/dist/lk/parse/portfolio-content.d.ts +10 -0
  15. package/dist/lk/parse/portfolio-content.js +116 -0
  16. package/dist/lk/parse/portfolio-grades.d.ts +8 -0
  17. package/dist/lk/parse/portfolio-grades.js +41 -0
  18. package/dist/lk/parse/portfolio-performance.d.ts +2 -0
  19. package/dist/lk/parse/portfolio-performance.js +44 -0
  20. package/dist/lk/parse/portfolio.d.ts +6 -0
  21. package/dist/lk/parse/portfolio.js +64 -0
  22. package/dist/lk/parse/webinar-lesson.d.ts +7 -0
  23. package/dist/lk/parse/webinar-lesson.js +28 -0
  24. package/dist/lk/parse/webinars.d.ts +3 -0
  25. package/dist/lk/parse/webinars.js +67 -0
  26. package/dist/lk/portfolio-types.d.ts +113 -0
  27. package/dist/lk/portfolio-types.js +1 -0
  28. package/dist/lk/types.d.ts +29 -0
  29. package/dist/{tt → lk}/webinars.d.ts +3 -1
  30. package/dist/lk/webinars.js +48 -0
  31. package/dist/parsers.d.ts +3 -1
  32. package/dist/parsers.js +3 -1
  33. package/dist/tt/client.d.ts +1 -11
  34. package/dist/tt/client.js +1 -45
  35. package/dist/tt/domain/types.d.ts +1 -1
  36. package/dist/tt/observations.js +2 -1
  37. package/dist/tt/parse/index.d.ts +0 -1
  38. package/dist/tt/parse/index.js +0 -1
  39. package/dist/tt/types.d.ts +0 -21
  40. package/dist/tt/utils/index.d.ts +0 -1
  41. package/dist/tt/utils/index.js +0 -1
  42. package/dist/webinar/client.d.ts +52 -0
  43. package/dist/webinar/client.js +184 -0
  44. package/dist/webinar/ddp.d.ts +31 -0
  45. package/dist/webinar/ddp.js +208 -0
  46. package/dist/webinar/events.d.ts +6 -0
  47. package/dist/webinar/events.js +38 -0
  48. package/dist/webinar/gateway.d.ts +30 -0
  49. package/dist/webinar/gateway.js +114 -0
  50. package/dist/webinar/media-protocol.d.ts +9 -0
  51. package/dist/webinar/media-protocol.js +24 -0
  52. package/dist/webinar/media-types.d.ts +10 -0
  53. package/dist/webinar/media-types.js +1 -0
  54. package/dist/webinar/media.d.ts +21 -0
  55. package/dist/webinar/media.js +76 -0
  56. package/dist/webinar/parse.d.ts +14 -0
  57. package/dist/webinar/parse.js +113 -0
  58. package/dist/webinar/playback.d.ts +32 -0
  59. package/dist/webinar/playback.js +188 -0
  60. package/dist/webinar/socket.d.ts +3 -0
  61. package/dist/webinar/socket.js +18 -0
  62. package/dist/webinar/state.d.ts +4 -0
  63. package/dist/webinar/state.js +98 -0
  64. package/dist/webinar/types.d.ts +148 -0
  65. package/dist/webinar/types.js +12 -0
  66. package/docs/student-portal.md +151 -0
  67. package/docs/testing.md +13 -0
  68. package/docs/v5-migration.md +25 -2
  69. package/docs/webinar.md +145 -0
  70. package/package.json +2 -2
  71. package/dist/tt/parse/webinars.d.ts +0 -2
  72. package/dist/tt/parse/webinars.js +0 -97
  73. package/dist/tt/webinars.js +0 -39
@@ -0,0 +1,21 @@
1
+ import type { WebinarClient } from "./client.js";
2
+ import { WebinarPlayback } from "./playback.js";
3
+ import { type WebinarSession } from "./types.js";
4
+ import type { WebinarMediaOptions, WebinarReceiveOptions } from "./media-types.js";
5
+ /** Browser media stays direct; the state client supplies permitted stream IDs. */
6
+ export declare class WebinarMediaClient {
7
+ private room;
8
+ private opts;
9
+ private session;
10
+ private playbacks;
11
+ private closed;
12
+ private timeout;
13
+ constructor(session: WebinarSession, room: WebinarClient, opts?: WebinarMediaOptions);
14
+ listen(opts?: WebinarReceiveOptions): Promise<WebinarPlayback>;
15
+ receiveCamera(opts: {
16
+ streamId: string;
17
+ } & WebinarReceiveOptions): Promise<WebinarPlayback>;
18
+ receiveScreen(opts?: WebinarReceiveOptions): Promise<WebinarPlayback>;
19
+ private receive;
20
+ close(): void;
21
+ }
@@ -0,0 +1,76 @@
1
+ import { WebinarPlayback } from "./playback.js";
2
+ import { browserWebinarSocket } from "./socket.js";
3
+ import { WebinarPermissionError, WebinarProtocolError } from "./types.js";
4
+ /** Browser media stays direct; the state client supplies permitted stream IDs. */
5
+ export class WebinarMediaClient {
6
+ room;
7
+ opts;
8
+ session;
9
+ playbacks = new Set();
10
+ closed = false;
11
+ timeout;
12
+ constructor(session, room, opts = {}) {
13
+ this.room = room;
14
+ this.opts = opts;
15
+ if (session.mediaBackend !== "kurento" || !/^2\.3(?:\.|$)/u.test(session.server.version)) {
16
+ throw new WebinarProtocolError("Unsupported webinar media backend");
17
+ }
18
+ this.session = structuredClone(session);
19
+ this.timeout = opts.timeout ?? 20_000;
20
+ if (!Number.isFinite(this.timeout) || this.timeout <= 0)
21
+ throw new RangeError("Invalid webinar media timeout");
22
+ }
23
+ async listen(opts) {
24
+ if (!this.session.features.audio)
25
+ throw new WebinarPermissionError("Listen-only audio is disabled");
26
+ return this.receive("audio", opts);
27
+ }
28
+ async receiveCamera(opts) {
29
+ if (!this.session.features.video)
30
+ throw new WebinarPermissionError("Camera playback is disabled");
31
+ const stream = this.room.getMediaStreams().find((stream) => stream.kind === "camera" && stream.id === opts.streamId);
32
+ if (!stream)
33
+ throw new WebinarPermissionError("Camera stream is not published to this participant");
34
+ return this.receive("camera", opts, stream.id);
35
+ }
36
+ async receiveScreen(opts = {}) {
37
+ if (!this.session.features.screen)
38
+ throw new WebinarPermissionError("Screen playback is disabled");
39
+ const stream = this.room.getMediaStreams().find((stream) => stream.kind === "screen");
40
+ if (!stream)
41
+ throw new WebinarPermissionError("No screen is being shared");
42
+ return this.receive("screen", opts, stream.id, stream.hasAudio);
43
+ }
44
+ async receive(kind, opts, streamId, hasAudio = false) {
45
+ if (this.closed)
46
+ throw new WebinarProtocolError("Webinar media client closed");
47
+ if (this.room.getSnapshot().ended)
48
+ throw new WebinarProtocolError("Webinar has ended");
49
+ const socket = (this.opts.socketFactory ?? browserWebinarSocket)(this.session.connections.media);
50
+ let playback;
51
+ try {
52
+ playback = new WebinarPlayback(this.session, kind, socket, this.opts, streamId, hasAudio);
53
+ }
54
+ catch (error) {
55
+ socket.close();
56
+ throw error;
57
+ }
58
+ this.playbacks.add(playback);
59
+ playback.onClose(() => { this.playbacks.delete(playback); });
60
+ try {
61
+ await playback.connect(this.timeout, opts);
62
+ return playback;
63
+ }
64
+ catch (error) {
65
+ this.playbacks.delete(playback);
66
+ playback.close();
67
+ throw error;
68
+ }
69
+ }
70
+ close() {
71
+ this.closed = true;
72
+ for (const playback of this.playbacks)
73
+ playback.close();
74
+ this.playbacks.clear();
75
+ }
76
+ }
@@ -0,0 +1,14 @@
1
+ import { type WebinarSession } from "./types.js";
2
+ import type { WebinarDocument } from "./ddp.js";
3
+ export declare function record(value: unknown): WebinarDocument;
4
+ export declare function string(value: unknown): string;
5
+ export declare function safeWebinarUrl(value: unknown, origin: string): string | null;
6
+ /** Decode the JSON runtime config without executing server scripts. */
7
+ export declare function parseWebinarConfig(html: string): WebinarDocument;
8
+ export declare function parseWebinarSession(opts: {
9
+ clientUrl: string;
10
+ config: WebinarDocument;
11
+ entry: unknown;
12
+ iceServers: RTCIceServer[];
13
+ }): WebinarSession;
14
+ export declare function parseWebinarIceServers(body: string): RTCIceServer[];
@@ -0,0 +1,113 @@
1
+ import { ParseError } from "../common/types.js";
2
+ import { WebinarProtocolError } from "./types.js";
3
+ export function record(value) {
4
+ return value !== null && typeof value === "object" && !Array.isArray(value)
5
+ ? value : {};
6
+ }
7
+ export function string(value) {
8
+ return typeof value === "string" ? value : "";
9
+ }
10
+ export function safeWebinarUrl(value, origin) {
11
+ if (typeof value !== "string" || !value)
12
+ return null;
13
+ try {
14
+ const url = new URL(value, origin);
15
+ return url.protocol === "https:" && url.origin === origin && !url.username && !url.password
16
+ ? url.href : null;
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
22
+ /** Decode the JSON runtime config without executing server scripts. */
23
+ export function parseWebinarConfig(html) {
24
+ const match = html.match(/__meteor_runtime_config__\s*=\s*JSON\.parse\(decodeURIComponent\("([^"\r\n]+)"\)\)/u);
25
+ if (!match)
26
+ throw new WebinarProtocolError("Unsupported webinar client: no Meteor runtime config");
27
+ try {
28
+ const config = record(JSON.parse(decodeURIComponent(match[1])));
29
+ if (!config.PUBLIC_SETTINGS)
30
+ throw new Error();
31
+ return record(config.PUBLIC_SETTINGS);
32
+ }
33
+ catch {
34
+ throw new ParseError("Invalid webinar runtime configuration");
35
+ }
36
+ }
37
+ export function parseWebinarSession(opts) {
38
+ const url = new URL(opts.clientUrl);
39
+ const response = record(record(opts.entry).response);
40
+ if (response.returncode !== "SUCCESS")
41
+ throw new ParseError("Webinar session entry failed");
42
+ const app = record(opts.config.app);
43
+ const kurento = record(opts.config.kurento);
44
+ const chat = record(opts.config.chat);
45
+ const version = String(app.bbbServerVersion ?? "");
46
+ if (!/^2\.3(?:\.|$)/u.test(version)) {
47
+ throw new WebinarProtocolError(`Unsupported webinar version: ${version || "unknown"}`);
48
+ }
49
+ const token = url.searchParams.get("sessionToken");
50
+ const required = [token, response.authToken, response.internalUserID, response.meetingID,
51
+ response.fullname, response.voicebridge];
52
+ if (required.some((value) => typeof value !== "string" || !value)) {
53
+ throw new ParseError("Incomplete webinar participant credentials");
54
+ }
55
+ const basename = string(app.basename) || "/html5client";
56
+ if (!/^\/[\w/-]+$/u.test(basename))
57
+ throw new ParseError("Invalid webinar client path");
58
+ const state = new URL(`${basename.replace(/\/$/u, "")}/websocket`, url.origin);
59
+ state.protocol = "wss:";
60
+ const media = new URL(string(kurento.wsUrl), url.origin);
61
+ if (media.protocol !== "wss:" || media.host !== url.host)
62
+ throw new ParseError("Invalid webinar media endpoint");
63
+ media.searchParams.set("sessionToken", token);
64
+ const enabled = (value) => value === true;
65
+ return {
66
+ server: { origin: url.origin, version, build: typeof app.html5ClientBuild === "number" ? app.html5ClientBuild : null },
67
+ protocol: "ddp",
68
+ mediaBackend: "kurento",
69
+ sessionToken: token,
70
+ authToken: string(response.authToken),
71
+ externalUserId: string(response.externUserID),
72
+ user: { id: string(response.internalUserID), name: string(response.fullname), role: string(response.role) },
73
+ meeting: { id: string(response.meetingID), name: string(response.confname), voiceBridge: string(response.voicebridge) },
74
+ connections: { state: state.href, media: media.href },
75
+ iceServers: opts.iceServers,
76
+ features: {
77
+ chat: enabled(chat.enabled),
78
+ notes: enabled(record(opts.config.note).enabled),
79
+ audio: enabled(kurento.enableListenOnly),
80
+ video: enabled(kurento.enableVideo),
81
+ screen: enabled(kurento.enableScreensharing),
82
+ raiseHand: enabled(record(app.raiseHandActionButton).enabled),
83
+ presentationDownload: enabled(record(opts.config.presentation).allowDownloadable),
84
+ },
85
+ notesUrl: safeWebinarUrl(record(opts.config.note).url, url.origin),
86
+ publicChatId: string(chat.public_group_id) || "MAIN-PUBLIC-GROUP-CHAT",
87
+ chatPageSize: typeof chat.itemsPerPage === "number" && chat.itemsPerPage > 0 ? chat.itemsPerPage : 100,
88
+ maxMessageLength: typeof chat.max_message_length === "number" && chat.max_message_length > 0 ? chat.max_message_length : 5_000,
89
+ };
90
+ }
91
+ export function parseWebinarIceServers(body) {
92
+ try {
93
+ const response = record(JSON.parse(body));
94
+ if (!Array.isArray(response.stunServers) || !Array.isArray(response.turnServers))
95
+ throw new Error();
96
+ const servers = [];
97
+ for (const stun of Array.isArray(response.stunServers) ? response.stunServers : []) {
98
+ const url = string(record(stun).url) || string(stun);
99
+ if (/^stuns?:/u.test(url))
100
+ servers.push({ urls: url });
101
+ }
102
+ for (const turn of Array.isArray(response.turnServers) ? response.turnServers : []) {
103
+ const data = record(turn);
104
+ const url = string(data.url);
105
+ if (/^turns?:/u.test(url))
106
+ servers.push({ urls: url, username: string(data.username), credential: string(data.password) });
107
+ }
108
+ return servers;
109
+ }
110
+ catch {
111
+ throw new ParseError("Invalid webinar ICE server response");
112
+ }
113
+ }
@@ -0,0 +1,32 @@
1
+ import { type WebinarSession, type WebinarSocket } from "./types.js";
2
+ import type { WebinarMediaOptions, WebinarPlaybackKind, WebinarReceiveOptions } from "./media-types.js";
3
+ /** Direct browser-to-BBB receiver. Attach stream to an audio/video element. */
4
+ export declare class WebinarPlayback {
5
+ readonly kind: WebinarPlaybackKind;
6
+ readonly stream: MediaStream;
7
+ readonly connection: RTCPeerConnection;
8
+ private socket;
9
+ private messages;
10
+ private closed;
11
+ private started;
12
+ private answered;
13
+ private localCandidates;
14
+ private remoteCandidates;
15
+ private pendingReceive;
16
+ private pingTimer;
17
+ private errorListeners;
18
+ private closeListeners;
19
+ private connectionResolve;
20
+ private connectionReject;
21
+ private abort;
22
+ private signal;
23
+ constructor(session: WebinarSession, kind: WebinarPlaybackKind, socket: WebinarSocket, opts: WebinarMediaOptions, streamId?: string, hasAudio?: boolean);
24
+ connect(timeout: number, opts?: WebinarReceiveOptions): Promise<void>;
25
+ private send;
26
+ private receive;
27
+ onError(listener: (error: Error) => void): () => void;
28
+ onClose(listener: () => void): () => void;
29
+ private fail;
30
+ getStats(): Promise<RTCStatsReport>;
31
+ close(): void;
32
+ }
@@ -0,0 +1,188 @@
1
+ import { record, string } from "./parse.js";
2
+ import { openWebinarSocket } from "./socket.js";
3
+ import { webinarMediaMessages } from "./media-protocol.js";
4
+ import { WebinarProtocolError } from "./types.js";
5
+ /** Direct browser-to-BBB receiver. Attach stream to an audio/video element. */
6
+ export class WebinarPlayback {
7
+ kind;
8
+ stream;
9
+ connection;
10
+ socket;
11
+ messages;
12
+ closed = false;
13
+ started = false;
14
+ answered = false;
15
+ localCandidates = [];
16
+ remoteCandidates = [];
17
+ pendingReceive = Promise.resolve();
18
+ pingTimer;
19
+ errorListeners = new Set();
20
+ closeListeners = new Set();
21
+ connectionResolve;
22
+ connectionReject;
23
+ abort;
24
+ signal;
25
+ constructor(session, kind, socket, opts, streamId, hasAudio = false) {
26
+ this.kind = kind;
27
+ this.socket = socket;
28
+ this.messages = webinarMediaMessages(session, kind, streamId, hasAudio);
29
+ this.stream = new MediaStream();
30
+ this.connection = (opts.peerFactory ?? ((config) => new RTCPeerConnection(config)))({ iceServers: session.iceServers });
31
+ if (kind !== "camera" && (kind === "audio" || hasAudio))
32
+ this.connection.addTransceiver("audio", { direction: "recvonly" });
33
+ if (kind !== "audio")
34
+ this.connection.addTransceiver("video", { direction: "recvonly" });
35
+ this.connection.addEventListener("track", (event) => {
36
+ if (!this.stream.getTracks().some((track) => track.id === event.track.id))
37
+ this.stream.addTrack(event.track);
38
+ });
39
+ this.connection.addEventListener("icecandidate", (event) => {
40
+ if (!event.candidate || this.closed)
41
+ return;
42
+ const candidate = event.candidate.toJSON();
43
+ if (!this.answered)
44
+ this.localCandidates.push(candidate);
45
+ else
46
+ this.send(this.messages.candidate(candidate));
47
+ });
48
+ this.connection.addEventListener("connectionstatechange", () => {
49
+ if (this.connection.connectionState === "connected")
50
+ this.connectionResolve?.();
51
+ if (!this.closed && this.connection.connectionState === "failed")
52
+ this.fail(new WebinarProtocolError("Webinar media connection failed"));
53
+ });
54
+ socket.addEventListener("message", (event) => {
55
+ this.pendingReceive = this.pendingReceive.then(async () => {
56
+ if (this.closed)
57
+ return;
58
+ if (typeof event.data !== "string")
59
+ throw new WebinarProtocolError("Invalid media frame");
60
+ await this.receive(record(JSON.parse(event.data)));
61
+ }).catch(() => this.fail(new WebinarProtocolError("Webinar media negotiation failed")));
62
+ });
63
+ socket.addEventListener("close", () => {
64
+ if (!this.closed)
65
+ this.fail(new WebinarProtocolError("Webinar media signaling disconnected"));
66
+ });
67
+ socket.addEventListener("error", () => {
68
+ if (!this.closed)
69
+ this.fail(new WebinarProtocolError("Webinar media signaling failed"));
70
+ });
71
+ }
72
+ async connect(timeout, opts = {}) {
73
+ if (this.closed || this.started)
74
+ throw new WebinarProtocolError("Playback already opened or closed");
75
+ if (opts.signal?.aborted) {
76
+ this.close();
77
+ throw new Error("Webinar playback aborted");
78
+ }
79
+ this.signal = opts.signal;
80
+ this.abort = () => this.fail(new Error("Webinar playback aborted"));
81
+ this.signal?.addEventListener("abort", this.abort, { once: true });
82
+ const connected = new Promise((resolve, reject) => {
83
+ this.connectionResolve = resolve;
84
+ this.connectionReject = reject;
85
+ });
86
+ // Observe early failures while the WebSocket/offer is still opening.
87
+ void connected.catch(() => { });
88
+ const timer = setTimeout(() => this.fail(new WebinarProtocolError("Webinar media connection timed out")), timeout);
89
+ try {
90
+ await openWebinarSocket(this.socket, timeout);
91
+ if (this.closed)
92
+ throw new WebinarProtocolError("Webinar playback closed");
93
+ const offer = await this.connection.createOffer();
94
+ await this.connection.setLocalDescription(offer);
95
+ if (this.closed)
96
+ throw new WebinarProtocolError("Webinar playback closed");
97
+ this.started = true;
98
+ this.send(this.messages.start(offer.sdp ?? ""));
99
+ this.pingTimer = setInterval(() => this.send({ id: "ping" }), 10_000);
100
+ await connected;
101
+ }
102
+ catch (error) {
103
+ this.close();
104
+ throw error;
105
+ }
106
+ finally {
107
+ clearTimeout(timer);
108
+ this.connectionResolve = undefined;
109
+ this.connectionReject = undefined;
110
+ }
111
+ }
112
+ send(message) {
113
+ if (!this.closed && this.socket.readyState === 1)
114
+ this.socket.send(JSON.stringify(message));
115
+ }
116
+ async receive(message) {
117
+ if (message.id === "startResponse") {
118
+ if (message.response !== "accepted" || !string(message.sdpAnswer))
119
+ throw new WebinarProtocolError("Webinar media offer rejected");
120
+ await this.connection.setRemoteDescription({ type: "answer", sdp: string(message.sdpAnswer) });
121
+ this.answered = true;
122
+ for (const candidate of this.remoteCandidates.splice(0))
123
+ await this.connection.addIceCandidate(candidate);
124
+ for (const candidate of this.localCandidates.splice(0))
125
+ this.send(this.messages.candidate(candidate));
126
+ }
127
+ else if (message.id === "iceCandidate") {
128
+ const candidate = record(message.candidate);
129
+ if (!this.answered)
130
+ this.remoteCandidates.push(candidate);
131
+ else
132
+ await this.connection.addIceCandidate(candidate);
133
+ }
134
+ else if (["error", "webRTCAudioError"].includes(string(message.id))) {
135
+ throw new WebinarProtocolError("Webinar media rejected by server");
136
+ }
137
+ else if (["stopSharing", "playStop"].includes(string(message.id))) {
138
+ this.close();
139
+ }
140
+ }
141
+ onError(listener) {
142
+ this.errorListeners.add(listener);
143
+ return () => { this.errorListeners.delete(listener); };
144
+ }
145
+ onClose(listener) {
146
+ this.closeListeners.add(listener);
147
+ return () => { this.closeListeners.delete(listener); };
148
+ }
149
+ fail(error) {
150
+ if (this.closed)
151
+ return;
152
+ this.connectionReject?.(error);
153
+ for (const listener of this.errorListeners) {
154
+ try {
155
+ listener(error);
156
+ }
157
+ catch { /* Caller owns listener errors. */ }
158
+ }
159
+ this.close();
160
+ }
161
+ getStats() { return this.connection.getStats(); }
162
+ close() {
163
+ if (this.closed)
164
+ return;
165
+ if (this.started && this.kind === "camera")
166
+ this.send(this.messages.stop());
167
+ this.closed = true;
168
+ this.connectionReject?.(new WebinarProtocolError("Webinar playback closed"));
169
+ if (this.pingTimer)
170
+ clearInterval(this.pingTimer);
171
+ if (this.abort)
172
+ this.signal?.removeEventListener("abort", this.abort);
173
+ this.socket.close();
174
+ this.connection.close();
175
+ for (const track of this.stream.getTracks())
176
+ track.stop();
177
+ this.localCandidates.length = 0;
178
+ this.remoteCandidates.length = 0;
179
+ this.errorListeners.clear();
180
+ for (const listener of this.closeListeners) {
181
+ try {
182
+ listener();
183
+ }
184
+ catch { /* Caller owns listener errors. */ }
185
+ }
186
+ this.closeListeners.clear();
187
+ }
188
+ }
@@ -0,0 +1,3 @@
1
+ import type { WebinarSocket, WebinarSocketFactory } from "./types.js";
2
+ export declare const browserWebinarSocket: WebinarSocketFactory;
3
+ export declare function openWebinarSocket(socket: WebinarSocket, timeout: number): Promise<void>;
@@ -0,0 +1,18 @@
1
+ export const browserWebinarSocket = (url) => new WebSocket(url);
2
+ export async function openWebinarSocket(socket, timeout) {
3
+ if (socket.readyState === 1)
4
+ return;
5
+ await new Promise((resolve, reject) => {
6
+ const timer = setTimeout(() => {
7
+ reject(new Error("Webinar WebSocket connection timed out"));
8
+ socket.close();
9
+ }, timeout);
10
+ const fail = () => {
11
+ clearTimeout(timer);
12
+ reject(new Error("Webinar WebSocket connection failed"));
13
+ };
14
+ socket.addEventListener("open", () => { clearTimeout(timer); resolve(); });
15
+ socket.addEventListener("error", fail);
16
+ socket.addEventListener("close", fail);
17
+ });
18
+ }
@@ -0,0 +1,4 @@
1
+ import type { WebinarDdp, WebinarDocument } from "./ddp.js";
2
+ import type { WebinarMessage, WebinarSession, WebinarSnapshot } from "./types.js";
3
+ export declare function normalizeWebinarMessage(doc: WebinarDocument, users: WebinarDocument[]): WebinarMessage;
4
+ export declare function buildWebinarSnapshot(ddp: WebinarDdp, session: WebinarSession, history: Map<string, WebinarDocument>): WebinarSnapshot;
@@ -0,0 +1,98 @@
1
+ import { parseHtml, text } from "../common/parse.js";
2
+ import { record, safeWebinarUrl, string } from "./parse.js";
3
+ export function normalizeWebinarMessage(doc, users) {
4
+ const senderId = string(doc.sender) || string(record(doc.sender).id);
5
+ const sender = users.find((user) => user.userId === senderId);
6
+ const html = string(doc.message).replace(/<br\s*\/?\s*>/giu, "\n");
7
+ return {
8
+ id: string(doc.id) || string(doc._id),
9
+ chatId: string(doc.chatId),
10
+ senderId,
11
+ senderName: string(sender?.name) || string(record(doc.sender).name) || null,
12
+ timestamp: typeof doc.timestamp === "number" ? doc.timestamp : 0,
13
+ text: text(parseHtml(`<div id="message">${html}</div>`).querySelector("#message")),
14
+ };
15
+ }
16
+ export function buildWebinarSnapshot(ddp, session, history) {
17
+ const documents = (name) => ddp.documents(name);
18
+ const users = documents("users");
19
+ const persistent = documents("users-persistent-data");
20
+ const voices = documents("voiceUsers");
21
+ const positions = documents("slide-positions");
22
+ const slides = documents("slides");
23
+ const messages = new Map(history);
24
+ for (const doc of documents("group-chat-msg"))
25
+ messages.set(string(doc.id) || string(doc._id), doc);
26
+ const presentations = documents("presentations");
27
+ const meeting = documents("meetings").find((doc) => doc.meetingId === session.meeting.id);
28
+ const self = users.find((user) => user.userId === session.user.id);
29
+ const origin = session.server.origin;
30
+ const normalizeSlide = (doc, presentationId) => {
31
+ const position = positions.find((p) => p.id === doc.id);
32
+ return {
33
+ id: string(doc.id),
34
+ presentationId,
35
+ number: typeof doc.num === "number" ? doc.num : 0,
36
+ current: doc.current === true,
37
+ svgUrl: safeWebinarUrl(doc.svgUri, origin),
38
+ thumbnailUrl: safeWebinarUrl(doc.thumbUri, origin),
39
+ textUrl: safeWebinarUrl(doc.txtUri, origin),
40
+ text: string(doc.content),
41
+ viewport: position ? {
42
+ x: Number(position.x) || 0, y: Number(position.y) || 0,
43
+ width: Number(position.viewBoxWidth) || 0, height: Number(position.viewBoxHeight) || 0,
44
+ } : null,
45
+ };
46
+ };
47
+ const notes = documents("note")[0];
48
+ const noteUrl = (id) => {
49
+ if (!session.notesUrl || !string(id))
50
+ return null;
51
+ return `${session.notesUrl.replace(/\/$/u, "")}/p/${encodeURIComponent(string(id))}`;
52
+ };
53
+ return {
54
+ users: users.filter((user) => user.loggedOut !== true).map((user) => {
55
+ const voice = voices.find((v) => v.intId === user.userId && v.joined === true);
56
+ return {
57
+ id: string(user.userId), name: string(user.name), role: string(user.role),
58
+ presenter: user.presenter === true, moderator: user.role === "MODERATOR",
59
+ locked: user.locked === true, raisedHand: user.emoji === "raiseHand",
60
+ emoji: string(user.emoji) || "none",
61
+ audio: { joined: !!voice, listenOnly: voice?.listenOnly === true, muted: voice?.muted === true, speaking: voice?.talking === true },
62
+ };
63
+ }).sort((a, b) => a.name.localeCompare(b.name, "ru") || a.id.localeCompare(b.id)),
64
+ chats: documents("group-chat").map((chat) => ({
65
+ id: string(chat.chatId), name: string(chat.name), private: chat.access === "PRIVATE_ACCESS",
66
+ userIds: Array.isArray(chat.users) ? chat.users.filter((id) => typeof id === "string") : [],
67
+ })),
68
+ messages: [...messages.values()].map((doc) => normalizeWebinarMessage(doc, [...users, ...persistent]))
69
+ .sort((a, b) => a.timestamp - b.timestamp || a.id.localeCompare(b.id)),
70
+ presentations: presentations.map((presentation) => {
71
+ const id = string(presentation.id);
72
+ const published = slides.filter((slide) => slide.presentationId === id);
73
+ const pages = published.length ? published : Array.isArray(presentation.pages) ? presentation.pages.map(record) : [];
74
+ return {
75
+ id, name: string(presentation.name), current: presentation.current === true,
76
+ downloadable: presentation.downloadable === true && session.features.presentationDownload,
77
+ slides: pages.map((slide) => normalizeSlide(slide, id)).sort((a, b) => a.number - b.number),
78
+ };
79
+ }),
80
+ streams: [
81
+ ...documents("video-streams").filter((stream) => {
82
+ if (self?.role === "MODERATOR" || record(meeting?.usersProp).webcamsOnlyForModerator !== true)
83
+ return true;
84
+ return stream.userId === session.user.id || users.some((user) => user.userId === stream.userId && user.role === "MODERATOR");
85
+ }).map((stream) => ({
86
+ id: string(stream.stream), kind: "camera", userId: string(stream.userId) || null, hasAudio: false,
87
+ })),
88
+ ...documents("screenshare").filter((stream) => stream.screenshare !== false).map((stream) => ({
89
+ id: string(record(stream.screenshare).streamId) || string(stream._id),
90
+ kind: "screen", userId: string(record(stream.screenshare).userId) || null,
91
+ hasAudio: record(stream.screenshare).hasAudio === true,
92
+ })),
93
+ ],
94
+ notes: notes ? { revision: typeof notes.revs === "number" ? notes.revs : 0,
95
+ readUrl: noteUrl(notes.readOnlyId), editUrl: noteUrl(notes.padId) } : null,
96
+ ended: meeting?.meetingEnded === true,
97
+ };
98
+ }