chuvsu-js 5.5.2 → 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.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 +27 -5
- package/dist/webinar/media.js +10 -4
- package/dist/webinar/parse.js +59 -14
- 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 +12 -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 +15 -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,44 @@ 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;
|
|
@@ -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,36 @@ 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
|
+
forceRelay: record(opts.config.media).forceRelay === true,
|
|
99
|
+
forceRelayOnFirefox: kurento.forceRelayOnFirefox === true,
|
|
100
|
+
},
|
|
73
101
|
features: {
|
|
74
102
|
chat: enabled(chat.enabled),
|
|
103
|
+
typing: enabled(record(chat.typingIndicator).enabled),
|
|
75
104
|
notes: enabled(record(opts.config.note).enabled),
|
|
76
105
|
audio: enabled(kurento.enableListenOnly),
|
|
77
106
|
video: enabled(kurento.enableVideo),
|
|
@@ -81,26 +110,42 @@ export function parseWebinarSession(opts) {
|
|
|
81
110
|
},
|
|
82
111
|
notesUrl: safeWebinarUrl(record(opts.config.note).url, url.origin),
|
|
83
112
|
publicChatId: string(chat.public_group_id) || "MAIN-PUBLIC-GROUP-CHAT",
|
|
84
|
-
|
|
85
|
-
|
|
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,
|
|
86
122
|
};
|
|
87
123
|
}
|
|
88
124
|
export function parseWebinarIceServers(body) {
|
|
89
125
|
try {
|
|
90
126
|
const response = record(JSON.parse(body));
|
|
91
|
-
if (!Array.isArray(response.stunServers) ||
|
|
127
|
+
if (!Array.isArray(response.stunServers) ||
|
|
128
|
+
!Array.isArray(response.turnServers))
|
|
92
129
|
throw new Error();
|
|
93
130
|
const servers = [];
|
|
94
|
-
for (const stun of Array.isArray(response.stunServers)
|
|
131
|
+
for (const stun of Array.isArray(response.stunServers)
|
|
132
|
+
? response.stunServers
|
|
133
|
+
: []) {
|
|
95
134
|
const url = string(record(stun).url) || string(stun);
|
|
96
135
|
if (/^stuns?:/u.test(url))
|
|
97
136
|
servers.push({ urls: url });
|
|
98
137
|
}
|
|
99
|
-
for (const turn of Array.isArray(response.turnServers)
|
|
138
|
+
for (const turn of Array.isArray(response.turnServers)
|
|
139
|
+
? response.turnServers
|
|
140
|
+
: []) {
|
|
100
141
|
const data = record(turn);
|
|
101
142
|
const url = string(data.url);
|
|
102
143
|
if (/^turns?:/u.test(url))
|
|
103
|
-
servers.push({
|
|
144
|
+
servers.push({
|
|
145
|
+
urls: url,
|
|
146
|
+
username: string(data.username),
|
|
147
|
+
credential: string(data.password),
|
|
148
|
+
});
|
|
104
149
|
}
|
|
105
150
|
return servers;
|
|
106
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
|
});
|