chuvsu-js 5.5.2 → 5.5.4
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.js +2 -1
- package/dist/webinar/client.d.ts +11 -0
- package/dist/webinar/client.js +136 -33
- package/dist/webinar/ddp.js +40 -13
- package/dist/webinar/events.js +7 -2
- package/dist/webinar/gateway.js +57 -16
- package/dist/webinar/media-protocol.d.ts +2 -1
- package/dist/webinar/media-protocol.js +30 -5
- package/dist/webinar/media.js +10 -4
- package/dist/webinar/parse.js +62 -14
- package/dist/webinar/playback.d.ts +3 -0
- package/dist/webinar/playback.js +67 -15
- package/dist/webinar/socket.js +4 -1
- package/dist/webinar/state.js +73 -26
- package/dist/webinar/types.d.ts +14 -0
- 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 +19 -2
- 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 {
|
|
@@ -23,14 +23,19 @@ export class WebinarGateway {
|
|
|
23
23
|
if (this.session)
|
|
24
24
|
throw new Error("Create a new gateway for each webinar session");
|
|
25
25
|
let url = new URL(opts.joinUrl);
|
|
26
|
-
if (url.protocol !== "https:" ||
|
|
26
|
+
if (url.protocol !== "https:" ||
|
|
27
|
+
url.username ||
|
|
28
|
+
url.password ||
|
|
29
|
+
url.pathname !== "/bigbluebutton/api/join") {
|
|
27
30
|
throw new RangeError("Expected a signed HTTPS BBB join URL");
|
|
28
31
|
}
|
|
29
32
|
const origin = url.origin;
|
|
30
33
|
let html = null;
|
|
31
34
|
for (let redirects = 0; redirects < 6; redirects++) {
|
|
32
35
|
const response = await this.http.get(url.href, false);
|
|
33
|
-
if (response.status >= 300 &&
|
|
36
|
+
if (response.status >= 300 &&
|
|
37
|
+
response.status < 400 &&
|
|
38
|
+
response.location) {
|
|
34
39
|
const next = new URL(response.location, url);
|
|
35
40
|
if (next.origin !== origin || next.username || next.password)
|
|
36
41
|
throw new AuthError("Webinar redirected outside its server");
|
|
@@ -64,7 +69,12 @@ export class WebinarGateway {
|
|
|
64
69
|
const ice = await this.http.get(endpoint("/bigbluebutton/api/stuns"), false);
|
|
65
70
|
if (ice.status !== 200)
|
|
66
71
|
throw new AuthError("Webinar ICE configuration failed");
|
|
67
|
-
this.session = parseWebinarSession({
|
|
72
|
+
this.session = parseWebinarSession({
|
|
73
|
+
clientUrl: url.href,
|
|
74
|
+
config,
|
|
75
|
+
entry: data,
|
|
76
|
+
iceServers: parseWebinarIceServers(ice.body),
|
|
77
|
+
});
|
|
68
78
|
return structuredClone(this.session);
|
|
69
79
|
}
|
|
70
80
|
/** Opens state only. Browser media is connected separately by WebinarMediaClient. */
|
|
@@ -73,14 +83,18 @@ export class WebinarGateway {
|
|
|
73
83
|
throw new AuthError("Open a webinar session first");
|
|
74
84
|
if (this.client)
|
|
75
85
|
throw new Error("Webinar gateway state client already opened");
|
|
76
|
-
const client = new WebinarClient(this.session, {
|
|
86
|
+
const client = new WebinarClient(this.session, {
|
|
87
|
+
socketFactory: (url) => this.http.createWebSocket(url),
|
|
88
|
+
});
|
|
77
89
|
await client.connect();
|
|
78
90
|
this.client = client;
|
|
79
91
|
return client;
|
|
80
92
|
}
|
|
81
93
|
/** Downloads only when the live participant state exposes this permission. */
|
|
82
94
|
async downloadPresentation(opts) {
|
|
83
|
-
const presentation = this.client
|
|
95
|
+
const presentation = this.client
|
|
96
|
+
?.getPresentations()
|
|
97
|
+
.find((item) => item.id === opts.presentationId);
|
|
84
98
|
if (!this.session || !presentation?.downloadable)
|
|
85
99
|
throw new WebinarPermissionError("Original presentation download is disabled or unavailable");
|
|
86
100
|
const extension = presentation.name.split(".").pop() ?? "";
|
|
@@ -89,32 +103,59 @@ export class WebinarGateway {
|
|
|
89
103
|
const url = new URL(`/bigbluebutton/presentation/download/${encodeURIComponent(this.session.meeting.id)}/${encodeURIComponent(presentation.id)}`, this.session.server.origin);
|
|
90
104
|
url.searchParams.set("presFilename", `${presentation.id}.${extension}`);
|
|
91
105
|
const response = await this.http.getBufferResponse(url.href, false);
|
|
92
|
-
if (response.status !== 200 ||
|
|
106
|
+
if (response.status !== 200 ||
|
|
107
|
+
!response.contentType ||
|
|
108
|
+
response.contentType.startsWith("text/html")) {
|
|
93
109
|
throw new ParseError("Original presentation download failed");
|
|
94
110
|
}
|
|
95
|
-
return {
|
|
96
|
-
|
|
111
|
+
return {
|
|
112
|
+
body: response.body,
|
|
113
|
+
contentType: response.contentType,
|
|
114
|
+
filename: presentation.name.replace(/[\\/\x00-\x1f]/gu, "_"),
|
|
115
|
+
};
|
|
97
116
|
}
|
|
98
117
|
async downloadSlide(opts) {
|
|
99
118
|
if (!this.session)
|
|
100
119
|
throw new AuthError("Open a webinar session first");
|
|
101
120
|
const format = opts.format ?? "svg";
|
|
102
|
-
const value = format === "svg"
|
|
121
|
+
const value = format === "svg"
|
|
122
|
+
? opts.slide.svgUrl
|
|
123
|
+
: format === "text"
|
|
124
|
+
? opts.slide.textUrl
|
|
125
|
+
: opts.slide.thumbnailUrl;
|
|
103
126
|
if (!value)
|
|
104
127
|
throw new ParseError("Slide asset is unavailable");
|
|
105
128
|
const url = new URL(value);
|
|
106
129
|
const prefix = `/bigbluebutton/presentation/${encodeURIComponent(this.session.meeting.id)}/`;
|
|
107
|
-
if (url.origin !== this.session.server.origin ||
|
|
108
|
-
|
|
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) {
|
|
109
136
|
throw new RangeError("Expected a slide asset from the current webinar");
|
|
110
137
|
}
|
|
111
138
|
const response = await this.http.getBufferResponse(url.href, false);
|
|
112
139
|
if (response.status !== 200)
|
|
113
140
|
throw new Error(`Webinar slide request failed with HTTP ${response.status}`);
|
|
114
|
-
const expected = format === "svg"
|
|
141
|
+
const expected = format === "svg"
|
|
142
|
+
? "image/svg+xml"
|
|
143
|
+
: format === "text"
|
|
144
|
+
? "text/"
|
|
145
|
+
: "image/";
|
|
115
146
|
if (!response.contentType?.startsWith(expected))
|
|
116
147
|
throw new ParseError("Webinar returned an invalid slide asset");
|
|
117
|
-
const extension = format === "svg"
|
|
118
|
-
|
|
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
|
+
};
|
|
119
160
|
}
|
|
120
161
|
}
|
|
@@ -3,7 +3,8 @@ import type { WebinarPlaybackKind } from "./media-types.js";
|
|
|
3
3
|
import type { WebinarSession } from "./types.js";
|
|
4
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
|
};
|
|
@@ -3,22 +3,47 @@ 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
|
+
...(session.mediaSettings?.listenOnlyMediaServer
|
|
27
|
+
? { mediaServer: session.mediaSettings.listenOnlyMediaServer }
|
|
28
|
+
: {}),
|
|
29
|
+
}
|
|
30
|
+
: {}),
|
|
16
31
|
...(kind === "screen" ? { hasAudio } : {}),
|
|
17
32
|
};
|
|
18
33
|
},
|
|
34
|
+
answer(sdpOffer) {
|
|
35
|
+
return { ...identity, id: "subscriberAnswer", sdpOffer };
|
|
36
|
+
},
|
|
19
37
|
candidate(candidate) {
|
|
20
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
...identity,
|
|
40
|
+
...specific,
|
|
41
|
+
id: kind === "camera" ? "onIceCandidate" : "iceCandidate",
|
|
42
|
+
candidate,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
stop() {
|
|
46
|
+
return { ...identity, ...specific, id: "stop" };
|
|
21
47
|
},
|
|
22
|
-
stop() { return { ...identity, ...specific, id: "stop" }; },
|
|
23
48
|
};
|
|
24
49
|
}
|
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;
|
|
@@ -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;
|
|
@@ -44,8 +49,14 @@ export function parseWebinarSession(opts) {
|
|
|
44
49
|
const chat = record(opts.config.chat);
|
|
45
50
|
const version = String(app.bbbServerVersion ?? "");
|
|
46
51
|
const token = url.searchParams.get("sessionToken");
|
|
47
|
-
const required = [
|
|
48
|
-
|
|
52
|
+
const required = [
|
|
53
|
+
token,
|
|
54
|
+
response.authToken,
|
|
55
|
+
response.internalUserID,
|
|
56
|
+
response.meetingID,
|
|
57
|
+
response.fullname,
|
|
58
|
+
response.voicebridge,
|
|
59
|
+
];
|
|
49
60
|
if (required.some((value) => typeof value !== "string" || !value)) {
|
|
50
61
|
throw new ParseError("Incomplete webinar participant credentials");
|
|
51
62
|
}
|
|
@@ -60,18 +71,39 @@ export function parseWebinarSession(opts) {
|
|
|
60
71
|
media.searchParams.set("sessionToken", token);
|
|
61
72
|
const enabled = (value) => value === true;
|
|
62
73
|
return {
|
|
63
|
-
server: {
|
|
74
|
+
server: {
|
|
75
|
+
origin: url.origin,
|
|
76
|
+
version,
|
|
77
|
+
build: typeof app.html5ClientBuild === "number" ? app.html5ClientBuild : null,
|
|
78
|
+
},
|
|
64
79
|
protocol: "ddp",
|
|
65
80
|
mediaBackend: "kurento",
|
|
66
81
|
sessionToken: token,
|
|
67
82
|
authToken: string(response.authToken),
|
|
68
83
|
externalUserId: string(response.externUserID),
|
|
69
|
-
user: {
|
|
70
|
-
|
|
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
|
+
},
|
|
71
94
|
connections: { state: state.href, media: media.href },
|
|
72
95
|
iceServers: opts.iceServers,
|
|
96
|
+
mediaSettings: {
|
|
97
|
+
listenOnlyOffering: record(opts.config.media).listenOnlyOffering !== false,
|
|
98
|
+
...(/^[A-Za-z0-9_-]{1,64}$/u.test(string(kurento.listenOnlyMediaServer))
|
|
99
|
+
? { listenOnlyMediaServer: string(kurento.listenOnlyMediaServer) }
|
|
100
|
+
: {}),
|
|
101
|
+
forceRelay: record(opts.config.media).forceRelay === true,
|
|
102
|
+
forceRelayOnFirefox: kurento.forceRelayOnFirefox === true,
|
|
103
|
+
},
|
|
73
104
|
features: {
|
|
74
105
|
chat: enabled(chat.enabled),
|
|
106
|
+
typing: enabled(record(chat.typingIndicator).enabled),
|
|
75
107
|
notes: enabled(record(opts.config.note).enabled),
|
|
76
108
|
audio: enabled(kurento.enableListenOnly),
|
|
77
109
|
video: enabled(kurento.enableVideo),
|
|
@@ -81,26 +113,42 @@ export function parseWebinarSession(opts) {
|
|
|
81
113
|
},
|
|
82
114
|
notesUrl: safeWebinarUrl(record(opts.config.note).url, url.origin),
|
|
83
115
|
publicChatId: string(chat.public_group_id) || "MAIN-PUBLIC-GROUP-CHAT",
|
|
84
|
-
|
|
85
|
-
|
|
116
|
+
publicTypingId: string(chat.public_id) ||
|
|
117
|
+
string(chat.public_group_id) ||
|
|
118
|
+
"MAIN-PUBLIC-GROUP-CHAT",
|
|
119
|
+
chatPageSize: typeof chat.itemsPerPage === "number" && chat.itemsPerPage > 0
|
|
120
|
+
? chat.itemsPerPage
|
|
121
|
+
: 100,
|
|
122
|
+
maxMessageLength: typeof chat.max_message_length === "number" && chat.max_message_length > 0
|
|
123
|
+
? chat.max_message_length
|
|
124
|
+
: 5_000,
|
|
86
125
|
};
|
|
87
126
|
}
|
|
88
127
|
export function parseWebinarIceServers(body) {
|
|
89
128
|
try {
|
|
90
129
|
const response = record(JSON.parse(body));
|
|
91
|
-
if (!Array.isArray(response.stunServers) ||
|
|
130
|
+
if (!Array.isArray(response.stunServers) ||
|
|
131
|
+
!Array.isArray(response.turnServers))
|
|
92
132
|
throw new Error();
|
|
93
133
|
const servers = [];
|
|
94
|
-
for (const stun of Array.isArray(response.stunServers)
|
|
134
|
+
for (const stun of Array.isArray(response.stunServers)
|
|
135
|
+
? response.stunServers
|
|
136
|
+
: []) {
|
|
95
137
|
const url = string(record(stun).url) || string(stun);
|
|
96
138
|
if (/^stuns?:/u.test(url))
|
|
97
139
|
servers.push({ urls: url });
|
|
98
140
|
}
|
|
99
|
-
for (const turn of Array.isArray(response.turnServers)
|
|
141
|
+
for (const turn of Array.isArray(response.turnServers)
|
|
142
|
+
? response.turnServers
|
|
143
|
+
: []) {
|
|
100
144
|
const data = record(turn);
|
|
101
145
|
const url = string(data.url);
|
|
102
146
|
if (/^turns?:/u.test(url))
|
|
103
|
-
servers.push({
|
|
147
|
+
servers.push({
|
|
148
|
+
urls: url,
|
|
149
|
+
username: string(data.username),
|
|
150
|
+
credential: string(data.password),
|
|
151
|
+
});
|
|
104
152
|
}
|
|
105
153
|
return servers;
|
|
106
154
|
}
|
|
@@ -10,6 +10,8 @@ export declare class WebinarPlayback {
|
|
|
10
10
|
private closed;
|
|
11
11
|
private started;
|
|
12
12
|
private answered;
|
|
13
|
+
private offering;
|
|
14
|
+
private audioFlowing;
|
|
13
15
|
private localCandidates;
|
|
14
16
|
private remoteCandidates;
|
|
15
17
|
private pendingReceive;
|
|
@@ -21,6 +23,7 @@ export declare class WebinarPlayback {
|
|
|
21
23
|
private abort;
|
|
22
24
|
private signal;
|
|
23
25
|
constructor(session: WebinarSession, kind: WebinarPlaybackKind, socket: WebinarSocket, opts: WebinarMediaOptions, streamId?: string, hasAudio?: boolean);
|
|
26
|
+
private resolveWhenReady;
|
|
24
27
|
connect(timeout: number, opts?: WebinarReceiveOptions): Promise<void>;
|
|
25
28
|
private send;
|
|
26
29
|
private receive;
|
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,8 @@ export class WebinarPlayback {
|
|
|
12
12
|
closed = false;
|
|
13
13
|
started = false;
|
|
14
14
|
answered = false;
|
|
15
|
+
offering;
|
|
16
|
+
audioFlowing = false;
|
|
15
17
|
localCandidates = [];
|
|
16
18
|
remoteCandidates = [];
|
|
17
19
|
pendingReceive = Promise.resolve();
|
|
@@ -25,9 +27,19 @@ export class WebinarPlayback {
|
|
|
25
27
|
constructor(session, kind, socket, opts, streamId, hasAudio = false) {
|
|
26
28
|
this.kind = kind;
|
|
27
29
|
this.socket = socket;
|
|
30
|
+
this.offering =
|
|
31
|
+
kind !== "audio" || session.mediaSettings?.listenOnlyOffering !== false;
|
|
28
32
|
this.messages = webinarMediaMessages(session, kind, streamId, hasAudio);
|
|
29
33
|
this.stream = new MediaStream();
|
|
30
|
-
this.connection = (opts.peerFactory ?? ((config) => new RTCPeerConnection(config)))({
|
|
34
|
+
this.connection = (opts.peerFactory ?? ((config) => new RTCPeerConnection(config)))({
|
|
35
|
+
iceServers: session.iceServers,
|
|
36
|
+
iceTransportPolicy: session.mediaSettings?.forceRelay ||
|
|
37
|
+
(session.mediaSettings?.forceRelayOnFirefox &&
|
|
38
|
+
typeof navigator !== "undefined" &&
|
|
39
|
+
/Firefox\//u.test(navigator.userAgent))
|
|
40
|
+
? "relay"
|
|
41
|
+
: "all",
|
|
42
|
+
});
|
|
31
43
|
if (kind !== "camera" && (kind === "audio" || hasAudio))
|
|
32
44
|
this.connection.addTransceiver("audio", { direction: "recvonly" });
|
|
33
45
|
if (kind !== "audio")
|
|
@@ -35,6 +47,7 @@ export class WebinarPlayback {
|
|
|
35
47
|
this.connection.addEventListener("track", (event) => {
|
|
36
48
|
if (!this.stream.getTracks().some((track) => track.id === event.track.id))
|
|
37
49
|
this.stream.addTrack(event.track);
|
|
50
|
+
this.resolveWhenReady();
|
|
38
51
|
});
|
|
39
52
|
this.connection.addEventListener("icecandidate", (event) => {
|
|
40
53
|
if (!event.candidate || this.closed)
|
|
@@ -46,19 +59,20 @@ export class WebinarPlayback {
|
|
|
46
59
|
this.send(this.messages.candidate(candidate));
|
|
47
60
|
});
|
|
48
61
|
this.connection.addEventListener("connectionstatechange", () => {
|
|
49
|
-
|
|
50
|
-
this.connectionResolve?.();
|
|
62
|
+
this.resolveWhenReady();
|
|
51
63
|
if (!this.closed && this.connection.connectionState === "failed")
|
|
52
64
|
this.fail(new WebinarProtocolError("Webinar media connection failed"));
|
|
53
65
|
});
|
|
54
66
|
socket.addEventListener("message", (event) => {
|
|
55
|
-
this.pendingReceive = this.pendingReceive
|
|
67
|
+
this.pendingReceive = this.pendingReceive
|
|
68
|
+
.then(async () => {
|
|
56
69
|
if (this.closed)
|
|
57
70
|
return;
|
|
58
71
|
if (typeof event.data !== "string")
|
|
59
72
|
throw new WebinarProtocolError("Invalid media frame");
|
|
60
73
|
await this.receive(record(JSON.parse(event.data)));
|
|
61
|
-
})
|
|
74
|
+
})
|
|
75
|
+
.catch(() => this.fail(new WebinarProtocolError("Webinar media negotiation failed")));
|
|
62
76
|
});
|
|
63
77
|
socket.addEventListener("close", () => {
|
|
64
78
|
if (!this.closed)
|
|
@@ -69,6 +83,15 @@ export class WebinarPlayback {
|
|
|
69
83
|
this.fail(new WebinarProtocolError("Webinar media signaling failed"));
|
|
70
84
|
});
|
|
71
85
|
}
|
|
86
|
+
resolveWhenReady() {
|
|
87
|
+
if (this.connection.connectionState !== "connected")
|
|
88
|
+
return;
|
|
89
|
+
if (this.kind === "audio" &&
|
|
90
|
+
(!this.audioFlowing ||
|
|
91
|
+
!this.stream.getTracks().some((track) => track.kind === "audio")))
|
|
92
|
+
return;
|
|
93
|
+
this.connectionResolve?.();
|
|
94
|
+
}
|
|
72
95
|
async connect(timeout, opts = {}) {
|
|
73
96
|
if (this.closed || this.started)
|
|
74
97
|
throw new WebinarProtocolError("Playback already opened or closed");
|
|
@@ -90,12 +113,15 @@ export class WebinarPlayback {
|
|
|
90
113
|
await openWebinarSocket(this.socket, timeout);
|
|
91
114
|
if (this.closed)
|
|
92
115
|
throw new WebinarProtocolError("Webinar playback closed");
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
let offer;
|
|
117
|
+
if (this.offering) {
|
|
118
|
+
offer = await this.connection.createOffer();
|
|
119
|
+
await this.connection.setLocalDescription(offer);
|
|
120
|
+
}
|
|
95
121
|
if (this.closed)
|
|
96
122
|
throw new WebinarProtocolError("Webinar playback closed");
|
|
97
123
|
this.started = true;
|
|
98
|
-
this.send(this.messages.start(offer
|
|
124
|
+
this.send(this.messages.start(offer?.sdp));
|
|
99
125
|
this.pingTimer = setInterval(() => this.send({ id: "ping" }), 10_000);
|
|
100
126
|
await connected;
|
|
101
127
|
}
|
|
@@ -117,7 +143,17 @@ export class WebinarPlayback {
|
|
|
117
143
|
if (message.id === "startResponse") {
|
|
118
144
|
if (message.response !== "accepted" || !string(message.sdpAnswer))
|
|
119
145
|
throw new WebinarProtocolError("Webinar media offer rejected");
|
|
120
|
-
await this.connection.setRemoteDescription({
|
|
146
|
+
await this.connection.setRemoteDescription({
|
|
147
|
+
type: this.offering ? "answer" : "offer",
|
|
148
|
+
sdp: string(message.sdpAnswer),
|
|
149
|
+
});
|
|
150
|
+
if (!this.offering) {
|
|
151
|
+
const answer = await this.connection.createAnswer();
|
|
152
|
+
await this.connection.setLocalDescription(answer);
|
|
153
|
+
if (this.closed)
|
|
154
|
+
return;
|
|
155
|
+
this.send(this.messages.answer(answer.sdp ?? ""));
|
|
156
|
+
}
|
|
121
157
|
this.answered = true;
|
|
122
158
|
for (const candidate of this.remoteCandidates.splice(0))
|
|
123
159
|
await this.connection.addIceCandidate(candidate);
|
|
@@ -131,6 +167,12 @@ export class WebinarPlayback {
|
|
|
131
167
|
else
|
|
132
168
|
await this.connection.addIceCandidate(candidate);
|
|
133
169
|
}
|
|
170
|
+
else if (message.id === "webRTCAudioSuccess" && this.kind === "audio") {
|
|
171
|
+
if (message.success !== "MEDIA_FLOWING" && message.success !== true)
|
|
172
|
+
throw new WebinarProtocolError("Webinar audio is not flowing");
|
|
173
|
+
this.audioFlowing = true;
|
|
174
|
+
this.resolveWhenReady();
|
|
175
|
+
}
|
|
134
176
|
else if (["error", "webRTCAudioError"].includes(string(message.id))) {
|
|
135
177
|
throw new WebinarProtocolError("Webinar media rejected by server");
|
|
136
178
|
}
|
|
@@ -140,11 +182,15 @@ export class WebinarPlayback {
|
|
|
140
182
|
}
|
|
141
183
|
onError(listener) {
|
|
142
184
|
this.errorListeners.add(listener);
|
|
143
|
-
return () => {
|
|
185
|
+
return () => {
|
|
186
|
+
this.errorListeners.delete(listener);
|
|
187
|
+
};
|
|
144
188
|
}
|
|
145
189
|
onClose(listener) {
|
|
146
190
|
this.closeListeners.add(listener);
|
|
147
|
-
return () => {
|
|
191
|
+
return () => {
|
|
192
|
+
this.closeListeners.delete(listener);
|
|
193
|
+
};
|
|
148
194
|
}
|
|
149
195
|
fail(error) {
|
|
150
196
|
if (this.closed)
|
|
@@ -154,11 +200,15 @@ export class WebinarPlayback {
|
|
|
154
200
|
try {
|
|
155
201
|
listener(error);
|
|
156
202
|
}
|
|
157
|
-
catch {
|
|
203
|
+
catch {
|
|
204
|
+
/* Caller owns listener errors. */
|
|
205
|
+
}
|
|
158
206
|
}
|
|
159
207
|
this.close();
|
|
160
208
|
}
|
|
161
|
-
getStats() {
|
|
209
|
+
getStats() {
|
|
210
|
+
return this.connection.getStats();
|
|
211
|
+
}
|
|
162
212
|
close() {
|
|
163
213
|
if (this.closed)
|
|
164
214
|
return;
|
|
@@ -181,7 +231,9 @@ export class WebinarPlayback {
|
|
|
181
231
|
try {
|
|
182
232
|
listener();
|
|
183
233
|
}
|
|
184
|
-
catch {
|
|
234
|
+
catch {
|
|
235
|
+
/* Caller owns listener errors. */
|
|
236
|
+
}
|
|
185
237
|
}
|
|
186
238
|
this.closeListeners.clear();
|
|
187
239
|
}
|
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
|
});
|