chuvsu-js 5.5.1 → 5.5.3
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 +6 -9
- package/dist/common/http.js +2 -4
- package/dist/common/lesson-type.js +6 -1
- package/dist/common/parse.js +3 -1
- package/dist/core.d.ts +2 -1
- package/dist/core.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/lk/client.js +10 -4
- package/dist/lk/parse/grade-value.js +5 -1
- package/dist/lk/parse/portfolio-content.js +58 -16
- package/dist/lk/parse/portfolio-grades.js +37 -9
- package/dist/lk/parse/portfolio-performance.js +26 -8
- package/dist/lk/parse/portfolio.js +31 -13
- package/dist/lk/parse/webinar-lesson.js +4 -2
- package/dist/lk/parse/webinars.js +7 -3
- package/dist/lk/webinars.js +3 -1
- package/dist/tt/client.js +15 -7
- package/dist/tt/domain/directory.js +2 -4
- package/dist/tt/domain/index.d.ts +2 -2
- package/dist/tt/domain/index.js +2 -2
- package/dist/tt/domain/repository.js +67 -35
- package/dist/tt/domain/schedule-snapshot.js +51 -24
- package/dist/tt/domain/schedule.js +7 -3
- package/dist/tt/observations.js +7 -2
- package/dist/tt/parse/audience.js +3 -1
- package/dist/tt/parse/entry-parts.js +2 -3
- package/dist/tt/parse/full-schedule.js +1 -1
- package/dist/tt/parse/groups.js +1 -3
- package/dist/tt/parse/index.d.ts +2 -2
- package/dist/tt/parse/index.js +2 -2
- package/dist/tt/parse/lists.js +3 -3
- package/dist/tt/parse/overlays.js +7 -2
- package/dist/tt/utils/date.js +2 -2
- package/dist/tt/utils/period.js +2 -1
- package/dist/tt/utils/semester.js +2 -2
- package/dist/tt/utils/time-slots.js +81 -15
- package/dist/webinar/chat-subscription.d.ts +5 -0
- package/dist/webinar/chat-subscription.js +20 -0
- package/dist/webinar/client.d.ts +16 -1
- package/dist/webinar/client.js +152 -35
- package/dist/webinar/ddp.js +44 -13
- package/dist/webinar/events.js +7 -2
- package/dist/webinar/gateway.d.ts +3 -1
- package/dist/webinar/gateway.js +63 -16
- package/dist/webinar/media-protocol.d.ts +3 -2
- package/dist/webinar/media-protocol.js +28 -6
- package/dist/webinar/media.js +11 -5
- package/dist/webinar/parse.js +59 -17
- package/dist/webinar/playback.d.ts +1 -0
- package/dist/webinar/playback.js +49 -13
- package/dist/webinar/socket.js +4 -1
- package/dist/webinar/state.js +73 -26
- package/dist/webinar/types.d.ts +14 -1
- package/dist/webinar/types.js +3 -1
- package/dist/webinar/typing.d.ts +8 -0
- package/dist/webinar/typing.js +36 -0
- package/docs/fixture-review.md +44 -44
- package/docs/student-portal.md +11 -2
- package/docs/v5-migration.md +85 -88
- package/docs/webinar.md +38 -6
- package/package.json +1 -1
package/dist/webinar/gateway.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpClient } from "../common/http.js";
|
|
2
2
|
import { AuthError, ParseError } from "../common/types.js";
|
|
3
|
-
import { parseWebinarConfig, parseWebinarIceServers, parseWebinarSession } from "./parse.js";
|
|
4
|
-
import { WebinarPermissionError } from "./types.js";
|
|
3
|
+
import { parseWebinarConfig, parseWebinarIceServers, parseWebinarSession, } from "./parse.js";
|
|
4
|
+
import { WebinarPermissionError, } from "./types.js";
|
|
5
5
|
import { WebinarClient } from "./client.js";
|
|
6
6
|
/** Backend-only LK/BBB bootstrap and same-server presentation HTTP access. */
|
|
7
7
|
export class WebinarGateway {
|
|
@@ -13,18 +13,29 @@ export class WebinarGateway {
|
|
|
13
13
|
throw new AuthError("Open a webinar session first");
|
|
14
14
|
return structuredClone(this.session);
|
|
15
15
|
}
|
|
16
|
+
/** Cookie-authenticated signaling socket; audio/video WebRTC stays in the browser. */
|
|
17
|
+
createMediaSocket() {
|
|
18
|
+
if (!this.session)
|
|
19
|
+
throw new AuthError("Open a webinar session first");
|
|
20
|
+
return this.http.createWebSocket(this.session.connections.media);
|
|
21
|
+
}
|
|
16
22
|
async openSession(opts) {
|
|
17
23
|
if (this.session)
|
|
18
24
|
throw new Error("Create a new gateway for each webinar session");
|
|
19
25
|
let url = new URL(opts.joinUrl);
|
|
20
|
-
if (url.protocol !== "https:" ||
|
|
26
|
+
if (url.protocol !== "https:" ||
|
|
27
|
+
url.username ||
|
|
28
|
+
url.password ||
|
|
29
|
+
url.pathname !== "/bigbluebutton/api/join") {
|
|
21
30
|
throw new RangeError("Expected a signed HTTPS BBB join URL");
|
|
22
31
|
}
|
|
23
32
|
const origin = url.origin;
|
|
24
33
|
let html = null;
|
|
25
34
|
for (let redirects = 0; redirects < 6; redirects++) {
|
|
26
35
|
const response = await this.http.get(url.href, false);
|
|
27
|
-
if (response.status >= 300 &&
|
|
36
|
+
if (response.status >= 300 &&
|
|
37
|
+
response.status < 400 &&
|
|
38
|
+
response.location) {
|
|
28
39
|
const next = new URL(response.location, url);
|
|
29
40
|
if (next.origin !== origin || next.username || next.password)
|
|
30
41
|
throw new AuthError("Webinar redirected outside its server");
|
|
@@ -58,7 +69,12 @@ export class WebinarGateway {
|
|
|
58
69
|
const ice = await this.http.get(endpoint("/bigbluebutton/api/stuns"), false);
|
|
59
70
|
if (ice.status !== 200)
|
|
60
71
|
throw new AuthError("Webinar ICE configuration failed");
|
|
61
|
-
this.session = parseWebinarSession({
|
|
72
|
+
this.session = parseWebinarSession({
|
|
73
|
+
clientUrl: url.href,
|
|
74
|
+
config,
|
|
75
|
+
entry: data,
|
|
76
|
+
iceServers: parseWebinarIceServers(ice.body),
|
|
77
|
+
});
|
|
62
78
|
return structuredClone(this.session);
|
|
63
79
|
}
|
|
64
80
|
/** Opens state only. Browser media is connected separately by WebinarMediaClient. */
|
|
@@ -67,14 +83,18 @@ export class WebinarGateway {
|
|
|
67
83
|
throw new AuthError("Open a webinar session first");
|
|
68
84
|
if (this.client)
|
|
69
85
|
throw new Error("Webinar gateway state client already opened");
|
|
70
|
-
const client = new WebinarClient(this.session, {
|
|
86
|
+
const client = new WebinarClient(this.session, {
|
|
87
|
+
socketFactory: (url) => this.http.createWebSocket(url),
|
|
88
|
+
});
|
|
71
89
|
await client.connect();
|
|
72
90
|
this.client = client;
|
|
73
91
|
return client;
|
|
74
92
|
}
|
|
75
93
|
/** Downloads only when the live participant state exposes this permission. */
|
|
76
94
|
async downloadPresentation(opts) {
|
|
77
|
-
const presentation = this.client
|
|
95
|
+
const presentation = this.client
|
|
96
|
+
?.getPresentations()
|
|
97
|
+
.find((item) => item.id === opts.presentationId);
|
|
78
98
|
if (!this.session || !presentation?.downloadable)
|
|
79
99
|
throw new WebinarPermissionError("Original presentation download is disabled or unavailable");
|
|
80
100
|
const extension = presentation.name.split(".").pop() ?? "";
|
|
@@ -83,32 +103,59 @@ export class WebinarGateway {
|
|
|
83
103
|
const url = new URL(`/bigbluebutton/presentation/download/${encodeURIComponent(this.session.meeting.id)}/${encodeURIComponent(presentation.id)}`, this.session.server.origin);
|
|
84
104
|
url.searchParams.set("presFilename", `${presentation.id}.${extension}`);
|
|
85
105
|
const response = await this.http.getBufferResponse(url.href, false);
|
|
86
|
-
if (response.status !== 200 ||
|
|
106
|
+
if (response.status !== 200 ||
|
|
107
|
+
!response.contentType ||
|
|
108
|
+
response.contentType.startsWith("text/html")) {
|
|
87
109
|
throw new ParseError("Original presentation download failed");
|
|
88
110
|
}
|
|
89
|
-
return {
|
|
90
|
-
|
|
111
|
+
return {
|
|
112
|
+
body: response.body,
|
|
113
|
+
contentType: response.contentType,
|
|
114
|
+
filename: presentation.name.replace(/[\\/\x00-\x1f]/gu, "_"),
|
|
115
|
+
};
|
|
91
116
|
}
|
|
92
117
|
async downloadSlide(opts) {
|
|
93
118
|
if (!this.session)
|
|
94
119
|
throw new AuthError("Open a webinar session first");
|
|
95
120
|
const format = opts.format ?? "svg";
|
|
96
|
-
const value = format === "svg"
|
|
121
|
+
const value = format === "svg"
|
|
122
|
+
? opts.slide.svgUrl
|
|
123
|
+
: format === "text"
|
|
124
|
+
? opts.slide.textUrl
|
|
125
|
+
: opts.slide.thumbnailUrl;
|
|
97
126
|
if (!value)
|
|
98
127
|
throw new ParseError("Slide asset is unavailable");
|
|
99
128
|
const url = new URL(value);
|
|
100
129
|
const prefix = `/bigbluebutton/presentation/${encodeURIComponent(this.session.meeting.id)}/`;
|
|
101
|
-
if (url.origin !== this.session.server.origin ||
|
|
102
|
-
|
|
130
|
+
if (url.origin !== this.session.server.origin ||
|
|
131
|
+
!url.pathname.startsWith(prefix) ||
|
|
132
|
+
!/\/(?:svg|thumbnail|textfiles)\/\d+$/u.test(url.pathname) ||
|
|
133
|
+
url.search ||
|
|
134
|
+
url.username ||
|
|
135
|
+
url.password) {
|
|
103
136
|
throw new RangeError("Expected a slide asset from the current webinar");
|
|
104
137
|
}
|
|
105
138
|
const response = await this.http.getBufferResponse(url.href, false);
|
|
106
139
|
if (response.status !== 200)
|
|
107
140
|
throw new Error(`Webinar slide request failed with HTTP ${response.status}`);
|
|
108
|
-
const expected = format === "svg"
|
|
141
|
+
const expected = format === "svg"
|
|
142
|
+
? "image/svg+xml"
|
|
143
|
+
: format === "text"
|
|
144
|
+
? "text/"
|
|
145
|
+
: "image/";
|
|
109
146
|
if (!response.contentType?.startsWith(expected))
|
|
110
147
|
throw new ParseError("Webinar returned an invalid slide asset");
|
|
111
|
-
const extension = format === "svg"
|
|
112
|
-
|
|
148
|
+
const extension = format === "svg"
|
|
149
|
+
? "svg"
|
|
150
|
+
: format === "text"
|
|
151
|
+
? "txt"
|
|
152
|
+
: response.contentType.includes("png")
|
|
153
|
+
? "png"
|
|
154
|
+
: "jpg";
|
|
155
|
+
return {
|
|
156
|
+
body: response.body,
|
|
157
|
+
contentType: response.contentType,
|
|
158
|
+
filename: `slide-${opts.slide.number}.${extension}`,
|
|
159
|
+
};
|
|
113
160
|
}
|
|
114
161
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { WebinarDocument } from "./ddp.js";
|
|
2
2
|
import type { WebinarPlaybackKind } from "./media-types.js";
|
|
3
3
|
import type { WebinarSession } from "./types.js";
|
|
4
|
-
/** BBB 2.3 SFU messages. One playback per socket; no publish commands. */
|
|
4
|
+
/** BBB 2.3/2.4 SFU messages. One playback per socket; no publish commands. */
|
|
5
5
|
export declare function webinarMediaMessages(session: WebinarSession, kind: WebinarPlaybackKind, streamId?: string, hasAudio?: boolean): {
|
|
6
|
-
start(sdpOffer
|
|
6
|
+
start(sdpOffer?: string): WebinarDocument;
|
|
7
|
+
answer(sdpOffer: string): WebinarDocument;
|
|
7
8
|
candidate(candidate: RTCIceCandidateInit): WebinarDocument;
|
|
8
9
|
stop(): WebinarDocument;
|
|
9
10
|
};
|
|
@@ -1,24 +1,46 @@
|
|
|
1
|
-
/** BBB 2.3 SFU messages. One playback per socket; no publish commands. */
|
|
1
|
+
/** BBB 2.3/2.4 SFU messages. One playback per socket; no publish commands. */
|
|
2
2
|
export function webinarMediaMessages(session, kind, streamId, hasAudio = false) {
|
|
3
3
|
const type = kind === "camera" ? "video" : kind === "screen" ? "screenshare" : "audio";
|
|
4
4
|
const role = kind === "camera" ? "viewer" : "recv";
|
|
5
5
|
const identity = { type, role, voiceBridge: session.meeting.voiceBridge };
|
|
6
|
-
const specific = kind === "camera"
|
|
6
|
+
const specific = kind === "camera"
|
|
7
|
+
? { cameraId: streamId }
|
|
8
|
+
: kind === "screen"
|
|
9
|
+
? { callerName: session.user.id }
|
|
10
|
+
: {};
|
|
7
11
|
return {
|
|
8
12
|
start(sdpOffer) {
|
|
9
13
|
return {
|
|
10
|
-
...identity,
|
|
14
|
+
...identity,
|
|
15
|
+
...specific,
|
|
16
|
+
id: "start",
|
|
17
|
+
sdpOffer,
|
|
11
18
|
userName: session.user.name,
|
|
12
19
|
...(kind === "camera"
|
|
13
20
|
? { meetingId: session.meeting.id, userId: session.user.id }
|
|
14
21
|
: { internalMeetingId: session.meeting.id }),
|
|
15
|
-
...(kind === "audio"
|
|
22
|
+
...(kind === "audio"
|
|
23
|
+
? {
|
|
24
|
+
userId: session.user.id,
|
|
25
|
+
caleeName: `GLOBAL_AUDIO_${session.meeting.voiceBridge}`,
|
|
26
|
+
}
|
|
27
|
+
: {}),
|
|
16
28
|
...(kind === "screen" ? { hasAudio } : {}),
|
|
17
29
|
};
|
|
18
30
|
},
|
|
31
|
+
answer(sdpOffer) {
|
|
32
|
+
return { ...identity, id: "subscriberAnswer", sdpOffer };
|
|
33
|
+
},
|
|
19
34
|
candidate(candidate) {
|
|
20
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
...identity,
|
|
37
|
+
...specific,
|
|
38
|
+
id: kind === "camera" ? "onIceCandidate" : "iceCandidate",
|
|
39
|
+
candidate,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
stop() {
|
|
43
|
+
return { ...identity, ...specific, id: "stop" };
|
|
21
44
|
},
|
|
22
|
-
stop() { return { ...identity, ...specific, id: "stop" }; },
|
|
23
45
|
};
|
|
24
46
|
}
|
package/dist/webinar/media.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WebinarPlayback } from "./playback.js";
|
|
2
2
|
import { browserWebinarSocket } from "./socket.js";
|
|
3
|
-
import { WebinarPermissionError, WebinarProtocolError } from "./types.js";
|
|
3
|
+
import { WebinarPermissionError, WebinarProtocolError, } from "./types.js";
|
|
4
4
|
/** Browser media stays direct; the state client supplies permitted stream IDs. */
|
|
5
5
|
export class WebinarMediaClient {
|
|
6
6
|
room;
|
|
@@ -12,7 +12,7 @@ export class WebinarMediaClient {
|
|
|
12
12
|
constructor(session, room, opts = {}) {
|
|
13
13
|
this.room = room;
|
|
14
14
|
this.opts = opts;
|
|
15
|
-
if (session.mediaBackend !== "kurento"
|
|
15
|
+
if (session.mediaBackend !== "kurento") {
|
|
16
16
|
throw new WebinarProtocolError("Unsupported webinar media backend");
|
|
17
17
|
}
|
|
18
18
|
this.session = structuredClone(session);
|
|
@@ -28,7 +28,9 @@ export class WebinarMediaClient {
|
|
|
28
28
|
async receiveCamera(opts) {
|
|
29
29
|
if (!this.session.features.video)
|
|
30
30
|
throw new WebinarPermissionError("Camera playback is disabled");
|
|
31
|
-
const stream = this.room
|
|
31
|
+
const stream = this.room
|
|
32
|
+
.getMediaStreams()
|
|
33
|
+
.find((stream) => stream.kind === "camera" && stream.id === opts.streamId);
|
|
32
34
|
if (!stream)
|
|
33
35
|
throw new WebinarPermissionError("Camera stream is not published to this participant");
|
|
34
36
|
return this.receive("camera", opts, stream.id);
|
|
@@ -36,7 +38,9 @@ export class WebinarMediaClient {
|
|
|
36
38
|
async receiveScreen(opts = {}) {
|
|
37
39
|
if (!this.session.features.screen)
|
|
38
40
|
throw new WebinarPermissionError("Screen playback is disabled");
|
|
39
|
-
const stream = this.room
|
|
41
|
+
const stream = this.room
|
|
42
|
+
.getMediaStreams()
|
|
43
|
+
.find((stream) => stream.kind === "screen");
|
|
40
44
|
if (!stream)
|
|
41
45
|
throw new WebinarPermissionError("No screen is being shared");
|
|
42
46
|
return this.receive("screen", opts, stream.id, stream.hasAudio);
|
|
@@ -56,7 +60,9 @@ export class WebinarMediaClient {
|
|
|
56
60
|
throw error;
|
|
57
61
|
}
|
|
58
62
|
this.playbacks.add(playback);
|
|
59
|
-
playback.onClose(() => {
|
|
63
|
+
playback.onClose(() => {
|
|
64
|
+
this.playbacks.delete(playback);
|
|
65
|
+
});
|
|
60
66
|
try {
|
|
61
67
|
await playback.connect(this.timeout, opts);
|
|
62
68
|
return playback;
|
package/dist/webinar/parse.js
CHANGED
|
@@ -2,7 +2,8 @@ import { ParseError } from "../common/types.js";
|
|
|
2
2
|
import { WebinarProtocolError } from "./types.js";
|
|
3
3
|
export function record(value) {
|
|
4
4
|
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
5
|
-
? value
|
|
5
|
+
? value
|
|
6
|
+
: {};
|
|
6
7
|
}
|
|
7
8
|
export function string(value) {
|
|
8
9
|
return typeof value === "string" ? value : "";
|
|
@@ -12,8 +13,12 @@ export function safeWebinarUrl(value, origin) {
|
|
|
12
13
|
return null;
|
|
13
14
|
try {
|
|
14
15
|
const url = new URL(value, origin);
|
|
15
|
-
return url.protocol === "https:" &&
|
|
16
|
-
|
|
16
|
+
return url.protocol === "https:" &&
|
|
17
|
+
url.origin === origin &&
|
|
18
|
+
!url.username &&
|
|
19
|
+
!url.password
|
|
20
|
+
? url.href
|
|
21
|
+
: null;
|
|
17
22
|
}
|
|
18
23
|
catch {
|
|
19
24
|
return null;
|
|
@@ -43,12 +48,15 @@ export function parseWebinarSession(opts) {
|
|
|
43
48
|
const kurento = record(opts.config.kurento);
|
|
44
49
|
const chat = record(opts.config.chat);
|
|
45
50
|
const version = String(app.bbbServerVersion ?? "");
|
|
46
|
-
if (!/^2\.3(?:\.|$)/u.test(version)) {
|
|
47
|
-
throw new WebinarProtocolError(`Unsupported webinar version: ${version || "unknown"}`);
|
|
48
|
-
}
|
|
49
51
|
const token = url.searchParams.get("sessionToken");
|
|
50
|
-
const required = [
|
|
51
|
-
|
|
52
|
+
const required = [
|
|
53
|
+
token,
|
|
54
|
+
response.authToken,
|
|
55
|
+
response.internalUserID,
|
|
56
|
+
response.meetingID,
|
|
57
|
+
response.fullname,
|
|
58
|
+
response.voicebridge,
|
|
59
|
+
];
|
|
52
60
|
if (required.some((value) => typeof value !== "string" || !value)) {
|
|
53
61
|
throw new ParseError("Incomplete webinar participant credentials");
|
|
54
62
|
}
|
|
@@ -63,18 +71,36 @@ export function parseWebinarSession(opts) {
|
|
|
63
71
|
media.searchParams.set("sessionToken", token);
|
|
64
72
|
const enabled = (value) => value === true;
|
|
65
73
|
return {
|
|
66
|
-
server: {
|
|
74
|
+
server: {
|
|
75
|
+
origin: url.origin,
|
|
76
|
+
version,
|
|
77
|
+
build: typeof app.html5ClientBuild === "number" ? app.html5ClientBuild : null,
|
|
78
|
+
},
|
|
67
79
|
protocol: "ddp",
|
|
68
80
|
mediaBackend: "kurento",
|
|
69
81
|
sessionToken: token,
|
|
70
82
|
authToken: string(response.authToken),
|
|
71
83
|
externalUserId: string(response.externUserID),
|
|
72
|
-
user: {
|
|
73
|
-
|
|
84
|
+
user: {
|
|
85
|
+
id: string(response.internalUserID),
|
|
86
|
+
name: string(response.fullname),
|
|
87
|
+
role: string(response.role),
|
|
88
|
+
},
|
|
89
|
+
meeting: {
|
|
90
|
+
id: string(response.meetingID),
|
|
91
|
+
name: string(response.confname),
|
|
92
|
+
voiceBridge: string(response.voicebridge),
|
|
93
|
+
},
|
|
74
94
|
connections: { state: state.href, media: media.href },
|
|
75
95
|
iceServers: opts.iceServers,
|
|
96
|
+
mediaSettings: {
|
|
97
|
+
listenOnlyOffering: record(opts.config.media).listenOnlyOffering !== false,
|
|
98
|
+
forceRelay: record(opts.config.media).forceRelay === true,
|
|
99
|
+
forceRelayOnFirefox: kurento.forceRelayOnFirefox === true,
|
|
100
|
+
},
|
|
76
101
|
features: {
|
|
77
102
|
chat: enabled(chat.enabled),
|
|
103
|
+
typing: enabled(record(chat.typingIndicator).enabled),
|
|
78
104
|
notes: enabled(record(opts.config.note).enabled),
|
|
79
105
|
audio: enabled(kurento.enableListenOnly),
|
|
80
106
|
video: enabled(kurento.enableVideo),
|
|
@@ -84,26 +110,42 @@ export function parseWebinarSession(opts) {
|
|
|
84
110
|
},
|
|
85
111
|
notesUrl: safeWebinarUrl(record(opts.config.note).url, url.origin),
|
|
86
112
|
publicChatId: string(chat.public_group_id) || "MAIN-PUBLIC-GROUP-CHAT",
|
|
87
|
-
|
|
88
|
-
|
|
113
|
+
publicTypingId: string(chat.public_id) ||
|
|
114
|
+
string(chat.public_group_id) ||
|
|
115
|
+
"MAIN-PUBLIC-GROUP-CHAT",
|
|
116
|
+
chatPageSize: typeof chat.itemsPerPage === "number" && chat.itemsPerPage > 0
|
|
117
|
+
? chat.itemsPerPage
|
|
118
|
+
: 100,
|
|
119
|
+
maxMessageLength: typeof chat.max_message_length === "number" && chat.max_message_length > 0
|
|
120
|
+
? chat.max_message_length
|
|
121
|
+
: 5_000,
|
|
89
122
|
};
|
|
90
123
|
}
|
|
91
124
|
export function parseWebinarIceServers(body) {
|
|
92
125
|
try {
|
|
93
126
|
const response = record(JSON.parse(body));
|
|
94
|
-
if (!Array.isArray(response.stunServers) ||
|
|
127
|
+
if (!Array.isArray(response.stunServers) ||
|
|
128
|
+
!Array.isArray(response.turnServers))
|
|
95
129
|
throw new Error();
|
|
96
130
|
const servers = [];
|
|
97
|
-
for (const stun of Array.isArray(response.stunServers)
|
|
131
|
+
for (const stun of Array.isArray(response.stunServers)
|
|
132
|
+
? response.stunServers
|
|
133
|
+
: []) {
|
|
98
134
|
const url = string(record(stun).url) || string(stun);
|
|
99
135
|
if (/^stuns?:/u.test(url))
|
|
100
136
|
servers.push({ urls: url });
|
|
101
137
|
}
|
|
102
|
-
for (const turn of Array.isArray(response.turnServers)
|
|
138
|
+
for (const turn of Array.isArray(response.turnServers)
|
|
139
|
+
? response.turnServers
|
|
140
|
+
: []) {
|
|
103
141
|
const data = record(turn);
|
|
104
142
|
const url = string(data.url);
|
|
105
143
|
if (/^turns?:/u.test(url))
|
|
106
|
-
servers.push({
|
|
144
|
+
servers.push({
|
|
145
|
+
urls: url,
|
|
146
|
+
username: string(data.username),
|
|
147
|
+
credential: string(data.password),
|
|
148
|
+
});
|
|
107
149
|
}
|
|
108
150
|
return servers;
|
|
109
151
|
}
|
package/dist/webinar/playback.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { record, string } from "./parse.js";
|
|
2
2
|
import { openWebinarSocket } from "./socket.js";
|
|
3
3
|
import { webinarMediaMessages } from "./media-protocol.js";
|
|
4
|
-
import { WebinarProtocolError } from "./types.js";
|
|
4
|
+
import { WebinarProtocolError, } from "./types.js";
|
|
5
5
|
/** Direct browser-to-BBB receiver. Attach stream to an audio/video element. */
|
|
6
6
|
export class WebinarPlayback {
|
|
7
7
|
kind;
|
|
@@ -12,6 +12,7 @@ export class WebinarPlayback {
|
|
|
12
12
|
closed = false;
|
|
13
13
|
started = false;
|
|
14
14
|
answered = false;
|
|
15
|
+
offering;
|
|
15
16
|
localCandidates = [];
|
|
16
17
|
remoteCandidates = [];
|
|
17
18
|
pendingReceive = Promise.resolve();
|
|
@@ -25,9 +26,19 @@ export class WebinarPlayback {
|
|
|
25
26
|
constructor(session, kind, socket, opts, streamId, hasAudio = false) {
|
|
26
27
|
this.kind = kind;
|
|
27
28
|
this.socket = socket;
|
|
29
|
+
this.offering =
|
|
30
|
+
kind !== "audio" || session.mediaSettings?.listenOnlyOffering !== false;
|
|
28
31
|
this.messages = webinarMediaMessages(session, kind, streamId, hasAudio);
|
|
29
32
|
this.stream = new MediaStream();
|
|
30
|
-
this.connection = (opts.peerFactory ?? ((config) => new RTCPeerConnection(config)))({
|
|
33
|
+
this.connection = (opts.peerFactory ?? ((config) => new RTCPeerConnection(config)))({
|
|
34
|
+
iceServers: session.iceServers,
|
|
35
|
+
iceTransportPolicy: session.mediaSettings?.forceRelay ||
|
|
36
|
+
(session.mediaSettings?.forceRelayOnFirefox &&
|
|
37
|
+
typeof navigator !== "undefined" &&
|
|
38
|
+
/Firefox\//u.test(navigator.userAgent))
|
|
39
|
+
? "relay"
|
|
40
|
+
: "all",
|
|
41
|
+
});
|
|
31
42
|
if (kind !== "camera" && (kind === "audio" || hasAudio))
|
|
32
43
|
this.connection.addTransceiver("audio", { direction: "recvonly" });
|
|
33
44
|
if (kind !== "audio")
|
|
@@ -52,13 +63,15 @@ export class WebinarPlayback {
|
|
|
52
63
|
this.fail(new WebinarProtocolError("Webinar media connection failed"));
|
|
53
64
|
});
|
|
54
65
|
socket.addEventListener("message", (event) => {
|
|
55
|
-
this.pendingReceive = this.pendingReceive
|
|
66
|
+
this.pendingReceive = this.pendingReceive
|
|
67
|
+
.then(async () => {
|
|
56
68
|
if (this.closed)
|
|
57
69
|
return;
|
|
58
70
|
if (typeof event.data !== "string")
|
|
59
71
|
throw new WebinarProtocolError("Invalid media frame");
|
|
60
72
|
await this.receive(record(JSON.parse(event.data)));
|
|
61
|
-
})
|
|
73
|
+
})
|
|
74
|
+
.catch(() => this.fail(new WebinarProtocolError("Webinar media negotiation failed")));
|
|
62
75
|
});
|
|
63
76
|
socket.addEventListener("close", () => {
|
|
64
77
|
if (!this.closed)
|
|
@@ -90,12 +103,15 @@ export class WebinarPlayback {
|
|
|
90
103
|
await openWebinarSocket(this.socket, timeout);
|
|
91
104
|
if (this.closed)
|
|
92
105
|
throw new WebinarProtocolError("Webinar playback closed");
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
let offer;
|
|
107
|
+
if (this.offering) {
|
|
108
|
+
offer = await this.connection.createOffer();
|
|
109
|
+
await this.connection.setLocalDescription(offer);
|
|
110
|
+
}
|
|
95
111
|
if (this.closed)
|
|
96
112
|
throw new WebinarProtocolError("Webinar playback closed");
|
|
97
113
|
this.started = true;
|
|
98
|
-
this.send(this.messages.start(offer
|
|
114
|
+
this.send(this.messages.start(offer?.sdp));
|
|
99
115
|
this.pingTimer = setInterval(() => this.send({ id: "ping" }), 10_000);
|
|
100
116
|
await connected;
|
|
101
117
|
}
|
|
@@ -117,7 +133,17 @@ export class WebinarPlayback {
|
|
|
117
133
|
if (message.id === "startResponse") {
|
|
118
134
|
if (message.response !== "accepted" || !string(message.sdpAnswer))
|
|
119
135
|
throw new WebinarProtocolError("Webinar media offer rejected");
|
|
120
|
-
await this.connection.setRemoteDescription({
|
|
136
|
+
await this.connection.setRemoteDescription({
|
|
137
|
+
type: this.offering ? "answer" : "offer",
|
|
138
|
+
sdp: string(message.sdpAnswer),
|
|
139
|
+
});
|
|
140
|
+
if (!this.offering) {
|
|
141
|
+
const answer = await this.connection.createAnswer();
|
|
142
|
+
await this.connection.setLocalDescription(answer);
|
|
143
|
+
if (this.closed)
|
|
144
|
+
return;
|
|
145
|
+
this.send(this.messages.answer(answer.sdp ?? ""));
|
|
146
|
+
}
|
|
121
147
|
this.answered = true;
|
|
122
148
|
for (const candidate of this.remoteCandidates.splice(0))
|
|
123
149
|
await this.connection.addIceCandidate(candidate);
|
|
@@ -140,11 +166,15 @@ export class WebinarPlayback {
|
|
|
140
166
|
}
|
|
141
167
|
onError(listener) {
|
|
142
168
|
this.errorListeners.add(listener);
|
|
143
|
-
return () => {
|
|
169
|
+
return () => {
|
|
170
|
+
this.errorListeners.delete(listener);
|
|
171
|
+
};
|
|
144
172
|
}
|
|
145
173
|
onClose(listener) {
|
|
146
174
|
this.closeListeners.add(listener);
|
|
147
|
-
return () => {
|
|
175
|
+
return () => {
|
|
176
|
+
this.closeListeners.delete(listener);
|
|
177
|
+
};
|
|
148
178
|
}
|
|
149
179
|
fail(error) {
|
|
150
180
|
if (this.closed)
|
|
@@ -154,11 +184,15 @@ export class WebinarPlayback {
|
|
|
154
184
|
try {
|
|
155
185
|
listener(error);
|
|
156
186
|
}
|
|
157
|
-
catch {
|
|
187
|
+
catch {
|
|
188
|
+
/* Caller owns listener errors. */
|
|
189
|
+
}
|
|
158
190
|
}
|
|
159
191
|
this.close();
|
|
160
192
|
}
|
|
161
|
-
getStats() {
|
|
193
|
+
getStats() {
|
|
194
|
+
return this.connection.getStats();
|
|
195
|
+
}
|
|
162
196
|
close() {
|
|
163
197
|
if (this.closed)
|
|
164
198
|
return;
|
|
@@ -181,7 +215,9 @@ export class WebinarPlayback {
|
|
|
181
215
|
try {
|
|
182
216
|
listener();
|
|
183
217
|
}
|
|
184
|
-
catch {
|
|
218
|
+
catch {
|
|
219
|
+
/* Caller owns listener errors. */
|
|
220
|
+
}
|
|
185
221
|
}
|
|
186
222
|
this.closeListeners.clear();
|
|
187
223
|
}
|
package/dist/webinar/socket.js
CHANGED
|
@@ -11,7 +11,10 @@ export async function openWebinarSocket(socket, timeout) {
|
|
|
11
11
|
clearTimeout(timer);
|
|
12
12
|
reject(new Error("Webinar WebSocket connection failed"));
|
|
13
13
|
};
|
|
14
|
-
socket.addEventListener("open", () => {
|
|
14
|
+
socket.addEventListener("open", () => {
|
|
15
|
+
clearTimeout(timer);
|
|
16
|
+
resolve();
|
|
17
|
+
});
|
|
15
18
|
socket.addEventListener("error", fail);
|
|
16
19
|
socket.addEventListener("close", fail);
|
|
17
20
|
});
|