chuvsu-js 5.4.0 → 5.5.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.
- package/README.md +32 -3
- package/dist/common/http.d.ts +3 -1
- package/dist/common/http.js +9 -2
- package/dist/{tt/utils → common}/lesson-type.d.ts +4 -2
- package/dist/{tt/utils → common}/lesson-type.js +17 -2
- package/dist/core.d.ts +13 -5
- package/dist/core.js +7 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lk/client.d.ts +23 -1
- package/dist/lk/client.js +95 -0
- package/dist/lk/parse/grade-value.d.ts +4 -0
- package/dist/lk/parse/grade-value.js +16 -0
- package/dist/lk/parse/portfolio-content.d.ts +10 -0
- package/dist/lk/parse/portfolio-content.js +116 -0
- package/dist/lk/parse/portfolio-grades.d.ts +8 -0
- package/dist/lk/parse/portfolio-grades.js +41 -0
- package/dist/lk/parse/portfolio-performance.d.ts +2 -0
- package/dist/lk/parse/portfolio-performance.js +44 -0
- package/dist/lk/parse/portfolio.d.ts +6 -0
- package/dist/lk/parse/portfolio.js +64 -0
- package/dist/lk/parse/webinar-lesson.d.ts +7 -0
- package/dist/lk/parse/webinar-lesson.js +28 -0
- package/dist/lk/parse/webinars.d.ts +3 -0
- package/dist/lk/parse/webinars.js +67 -0
- package/dist/lk/portfolio-types.d.ts +113 -0
- package/dist/lk/portfolio-types.js +1 -0
- package/dist/lk/types.d.ts +29 -0
- package/dist/{tt → lk}/webinars.d.ts +3 -1
- package/dist/lk/webinars.js +52 -0
- package/dist/parsers.d.ts +3 -1
- package/dist/parsers.js +3 -1
- package/dist/tt/client.d.ts +1 -11
- package/dist/tt/client.js +1 -45
- package/dist/tt/domain/schedule.js +5 -1
- package/dist/tt/domain/substitution-occurrences.d.ts +3 -0
- package/dist/tt/domain/substitution-occurrences.js +75 -0
- package/dist/tt/domain/types.d.ts +1 -1
- package/dist/tt/observations.js +2 -1
- package/dist/tt/parse/index.d.ts +0 -1
- package/dist/tt/parse/index.js +0 -1
- package/dist/tt/types.d.ts +0 -21
- package/dist/tt/utils/index.d.ts +0 -1
- package/dist/tt/utils/index.js +0 -1
- package/dist/webinar/client.d.ts +52 -0
- package/dist/webinar/client.js +184 -0
- package/dist/webinar/ddp.d.ts +31 -0
- package/dist/webinar/ddp.js +208 -0
- package/dist/webinar/events.d.ts +6 -0
- package/dist/webinar/events.js +38 -0
- package/dist/webinar/gateway.d.ts +30 -0
- package/dist/webinar/gateway.js +114 -0
- package/dist/webinar/media-protocol.d.ts +9 -0
- package/dist/webinar/media-protocol.js +24 -0
- package/dist/webinar/media-types.d.ts +10 -0
- package/dist/webinar/media-types.js +1 -0
- package/dist/webinar/media.d.ts +21 -0
- package/dist/webinar/media.js +76 -0
- package/dist/webinar/parse.d.ts +14 -0
- package/dist/webinar/parse.js +113 -0
- package/dist/webinar/playback.d.ts +32 -0
- package/dist/webinar/playback.js +188 -0
- package/dist/webinar/socket.d.ts +3 -0
- package/dist/webinar/socket.js +18 -0
- package/dist/webinar/state.d.ts +4 -0
- package/dist/webinar/state.js +98 -0
- package/dist/webinar/types.d.ts +148 -0
- package/dist/webinar/types.js +12 -0
- package/docs/student-portal.md +151 -0
- package/docs/testing.md +13 -0
- package/docs/v5-migration.md +25 -2
- package/docs/webinar.md +145 -0
- package/package.json +2 -2
- package/dist/tt/parse/webinars.d.ts +0 -2
- package/dist/tt/parse/webinars.js +0 -97
- package/dist/tt/webinars.js +0 -39
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { HttpClient } from "../common/http.js";
|
|
2
|
+
import { AuthError, ParseError } from "../common/types.js";
|
|
3
|
+
import { parseWebinarConfig, parseWebinarIceServers, parseWebinarSession } from "./parse.js";
|
|
4
|
+
import { WebinarPermissionError } from "./types.js";
|
|
5
|
+
import { WebinarClient } from "./client.js";
|
|
6
|
+
/** Backend-only LK/BBB bootstrap and same-server presentation HTTP access. */
|
|
7
|
+
export class WebinarGateway {
|
|
8
|
+
http = new HttpClient();
|
|
9
|
+
session = null;
|
|
10
|
+
client = null;
|
|
11
|
+
getSession() {
|
|
12
|
+
if (!this.session)
|
|
13
|
+
throw new AuthError("Open a webinar session first");
|
|
14
|
+
return structuredClone(this.session);
|
|
15
|
+
}
|
|
16
|
+
async openSession(opts) {
|
|
17
|
+
if (this.session)
|
|
18
|
+
throw new Error("Create a new gateway for each webinar session");
|
|
19
|
+
let url = new URL(opts.joinUrl);
|
|
20
|
+
if (url.protocol !== "https:" || url.username || url.password || url.pathname !== "/bigbluebutton/api/join") {
|
|
21
|
+
throw new RangeError("Expected a signed HTTPS BBB join URL");
|
|
22
|
+
}
|
|
23
|
+
const origin = url.origin;
|
|
24
|
+
let html = null;
|
|
25
|
+
for (let redirects = 0; redirects < 6; redirects++) {
|
|
26
|
+
const response = await this.http.get(url.href, false);
|
|
27
|
+
if (response.status >= 300 && response.status < 400 && response.location) {
|
|
28
|
+
const next = new URL(response.location, url);
|
|
29
|
+
if (next.origin !== origin || next.username || next.password)
|
|
30
|
+
throw new AuthError("Webinar redirected outside its server");
|
|
31
|
+
url = next;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (response.status !== 200)
|
|
35
|
+
throw new AuthError(`Webinar join failed with HTTP ${response.status}`);
|
|
36
|
+
html = response.body;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
if (html === null || !url.searchParams.get("sessionToken"))
|
|
40
|
+
throw new AuthError("Webinar did not create a participant session");
|
|
41
|
+
const config = parseWebinarConfig(html);
|
|
42
|
+
const token = url.searchParams.get("sessionToken");
|
|
43
|
+
const endpoint = (path) => {
|
|
44
|
+
const endpointUrl = new URL(path, origin);
|
|
45
|
+
endpointUrl.searchParams.set("sessionToken", token);
|
|
46
|
+
return endpointUrl.href;
|
|
47
|
+
};
|
|
48
|
+
const entry = await this.http.get(endpoint("/bigbluebutton/api/enter"), false);
|
|
49
|
+
if (entry.status !== 200)
|
|
50
|
+
throw new AuthError("Webinar participant entry failed");
|
|
51
|
+
let data;
|
|
52
|
+
try {
|
|
53
|
+
data = JSON.parse(entry.body);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new ParseError("Invalid webinar entry response");
|
|
57
|
+
}
|
|
58
|
+
const ice = await this.http.get(endpoint("/bigbluebutton/api/stuns"), false);
|
|
59
|
+
if (ice.status !== 200)
|
|
60
|
+
throw new AuthError("Webinar ICE configuration failed");
|
|
61
|
+
this.session = parseWebinarSession({ clientUrl: url.href, config, entry: data, iceServers: parseWebinarIceServers(ice.body) });
|
|
62
|
+
return structuredClone(this.session);
|
|
63
|
+
}
|
|
64
|
+
/** Opens state only. Browser media is connected separately by WebinarMediaClient. */
|
|
65
|
+
async connect() {
|
|
66
|
+
if (!this.session)
|
|
67
|
+
throw new AuthError("Open a webinar session first");
|
|
68
|
+
if (this.client)
|
|
69
|
+
throw new Error("Webinar gateway state client already opened");
|
|
70
|
+
const client = new WebinarClient(this.session, { socketFactory: (url) => this.http.createWebSocket(url) });
|
|
71
|
+
await client.connect();
|
|
72
|
+
this.client = client;
|
|
73
|
+
return client;
|
|
74
|
+
}
|
|
75
|
+
/** Downloads only when the live participant state exposes this permission. */
|
|
76
|
+
async downloadPresentation(opts) {
|
|
77
|
+
const presentation = this.client?.getPresentations().find((item) => item.id === opts.presentationId);
|
|
78
|
+
if (!this.session || !presentation?.downloadable)
|
|
79
|
+
throw new WebinarPermissionError("Original presentation download is disabled or unavailable");
|
|
80
|
+
const extension = presentation.name.split(".").pop() ?? "";
|
|
81
|
+
if (!/^[a-zA-Z0-9]+$/u.test(extension))
|
|
82
|
+
throw new ParseError("Invalid presentation extension");
|
|
83
|
+
const url = new URL(`/bigbluebutton/presentation/download/${encodeURIComponent(this.session.meeting.id)}/${encodeURIComponent(presentation.id)}`, this.session.server.origin);
|
|
84
|
+
url.searchParams.set("presFilename", `${presentation.id}.${extension}`);
|
|
85
|
+
const response = await this.http.getBufferResponse(url.href, false);
|
|
86
|
+
if (response.status !== 200 || !response.contentType || response.contentType.startsWith("text/html")) {
|
|
87
|
+
throw new ParseError("Original presentation download failed");
|
|
88
|
+
}
|
|
89
|
+
return { body: response.body, contentType: response.contentType,
|
|
90
|
+
filename: presentation.name.replace(/[\\/\x00-\x1f]/gu, "_") };
|
|
91
|
+
}
|
|
92
|
+
async downloadSlide(opts) {
|
|
93
|
+
if (!this.session)
|
|
94
|
+
throw new AuthError("Open a webinar session first");
|
|
95
|
+
const format = opts.format ?? "svg";
|
|
96
|
+
const value = format === "svg" ? opts.slide.svgUrl : format === "text" ? opts.slide.textUrl : opts.slide.thumbnailUrl;
|
|
97
|
+
if (!value)
|
|
98
|
+
throw new ParseError("Slide asset is unavailable");
|
|
99
|
+
const url = new URL(value);
|
|
100
|
+
const prefix = `/bigbluebutton/presentation/${encodeURIComponent(this.session.meeting.id)}/`;
|
|
101
|
+
if (url.origin !== this.session.server.origin || !url.pathname.startsWith(prefix)
|
|
102
|
+
|| !/\/(?:svg|thumbnail|textfiles)\/\d+$/u.test(url.pathname) || url.search || url.username || url.password) {
|
|
103
|
+
throw new RangeError("Expected a slide asset from the current webinar");
|
|
104
|
+
}
|
|
105
|
+
const response = await this.http.getBufferResponse(url.href, false);
|
|
106
|
+
if (response.status !== 200)
|
|
107
|
+
throw new Error(`Webinar slide request failed with HTTP ${response.status}`);
|
|
108
|
+
const expected = format === "svg" ? "image/svg+xml" : format === "text" ? "text/" : "image/";
|
|
109
|
+
if (!response.contentType?.startsWith(expected))
|
|
110
|
+
throw new ParseError("Webinar returned an invalid slide asset");
|
|
111
|
+
const extension = format === "svg" ? "svg" : format === "text" ? "txt" : response.contentType.includes("png") ? "png" : "jpg";
|
|
112
|
+
return { body: response.body, contentType: response.contentType, filename: `slide-${opts.slide.number}.${extension}` };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WebinarDocument } from "./ddp.js";
|
|
2
|
+
import type { WebinarPlaybackKind } from "./media-types.js";
|
|
3
|
+
import type { WebinarSession } from "./types.js";
|
|
4
|
+
/** BBB 2.3 SFU messages. One playback per socket; no publish commands. */
|
|
5
|
+
export declare function webinarMediaMessages(session: WebinarSession, kind: WebinarPlaybackKind, streamId?: string, hasAudio?: boolean): {
|
|
6
|
+
start(sdpOffer: string): WebinarDocument;
|
|
7
|
+
candidate(candidate: RTCIceCandidateInit): WebinarDocument;
|
|
8
|
+
stop(): WebinarDocument;
|
|
9
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** BBB 2.3 SFU messages. One playback per socket; no publish commands. */
|
|
2
|
+
export function webinarMediaMessages(session, kind, streamId, hasAudio = false) {
|
|
3
|
+
const type = kind === "camera" ? "video" : kind === "screen" ? "screenshare" : "audio";
|
|
4
|
+
const role = kind === "camera" ? "viewer" : "recv";
|
|
5
|
+
const identity = { type, role, voiceBridge: session.meeting.voiceBridge };
|
|
6
|
+
const specific = kind === "camera" ? { cameraId: streamId } : kind === "screen" ? { callerName: session.user.id } : {};
|
|
7
|
+
return {
|
|
8
|
+
start(sdpOffer) {
|
|
9
|
+
return {
|
|
10
|
+
...identity, ...specific, id: "start", sdpOffer,
|
|
11
|
+
userName: session.user.name,
|
|
12
|
+
...(kind === "camera"
|
|
13
|
+
? { meetingId: session.meeting.id, userId: session.user.id }
|
|
14
|
+
: { internalMeetingId: session.meeting.id }),
|
|
15
|
+
...(kind === "audio" ? { userId: session.user.id, caleeName: `GLOBAL_AUDIO_${session.meeting.voiceBridge}` } : {}),
|
|
16
|
+
...(kind === "screen" ? { hasAudio } : {}),
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
candidate(candidate) {
|
|
20
|
+
return { ...identity, ...specific, id: kind === "camera" ? "onIceCandidate" : "iceCandidate", candidate };
|
|
21
|
+
},
|
|
22
|
+
stop() { return { ...identity, ...specific, id: "stop" }; },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WebinarSocketFactory } from "./types.js";
|
|
2
|
+
export interface WebinarMediaOptions {
|
|
3
|
+
socketFactory?: WebinarSocketFactory;
|
|
4
|
+
peerFactory?: (config: RTCConfiguration) => RTCPeerConnection;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
export type WebinarPlaybackKind = "audio" | "camera" | "screen";
|
|
8
|
+
export interface WebinarReceiveOptions {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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;
|