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.
Files changed (61) hide show
  1. package/README.md +6 -9
  2. package/dist/common/http.js +2 -4
  3. package/dist/common/lesson-type.js +6 -1
  4. package/dist/common/parse.js +3 -1
  5. package/dist/core.d.ts +2 -1
  6. package/dist/core.js +2 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/lk/client.js +10 -4
  9. package/dist/lk/parse/grade-value.js +5 -1
  10. package/dist/lk/parse/portfolio-content.js +58 -16
  11. package/dist/lk/parse/portfolio-grades.js +37 -9
  12. package/dist/lk/parse/portfolio-performance.js +26 -8
  13. package/dist/lk/parse/portfolio.js +31 -13
  14. package/dist/lk/parse/webinar-lesson.js +4 -2
  15. package/dist/lk/parse/webinars.js +7 -3
  16. package/dist/lk/webinars.js +3 -1
  17. package/dist/tt/client.js +15 -7
  18. package/dist/tt/domain/directory.js +2 -4
  19. package/dist/tt/domain/index.d.ts +2 -2
  20. package/dist/tt/domain/index.js +2 -2
  21. package/dist/tt/domain/repository.js +67 -35
  22. package/dist/tt/domain/schedule-snapshot.js +51 -24
  23. package/dist/tt/domain/schedule.js +7 -3
  24. package/dist/tt/observations.js +7 -2
  25. package/dist/tt/parse/audience.js +3 -1
  26. package/dist/tt/parse/entry-parts.js +2 -3
  27. package/dist/tt/parse/full-schedule.js +1 -1
  28. package/dist/tt/parse/groups.js +1 -3
  29. package/dist/tt/parse/index.d.ts +2 -2
  30. package/dist/tt/parse/index.js +2 -2
  31. package/dist/tt/parse/lists.js +3 -3
  32. package/dist/tt/parse/overlays.js +7 -2
  33. package/dist/tt/utils/date.js +2 -2
  34. package/dist/tt/utils/period.js +2 -1
  35. package/dist/tt/utils/semester.js +2 -2
  36. package/dist/tt/utils/time-slots.js +81 -15
  37. package/dist/webinar/chat-subscription.d.ts +5 -0
  38. package/dist/webinar/chat-subscription.js +20 -0
  39. package/dist/webinar/client.d.ts +16 -1
  40. package/dist/webinar/client.js +152 -35
  41. package/dist/webinar/ddp.js +44 -13
  42. package/dist/webinar/events.js +7 -2
  43. package/dist/webinar/gateway.d.ts +3 -1
  44. package/dist/webinar/gateway.js +63 -16
  45. package/dist/webinar/media-protocol.d.ts +3 -2
  46. package/dist/webinar/media-protocol.js +28 -6
  47. package/dist/webinar/media.js +11 -5
  48. package/dist/webinar/parse.js +59 -17
  49. package/dist/webinar/playback.d.ts +1 -0
  50. package/dist/webinar/playback.js +49 -13
  51. package/dist/webinar/socket.js +4 -1
  52. package/dist/webinar/state.js +73 -26
  53. package/dist/webinar/types.d.ts +14 -1
  54. package/dist/webinar/types.js +3 -1
  55. package/dist/webinar/typing.d.ts +8 -0
  56. package/dist/webinar/typing.js +36 -0
  57. package/docs/fixture-review.md +44 -44
  58. package/docs/student-portal.md +11 -2
  59. package/docs/v5-migration.md +85 -88
  60. package/docs/webinar.md +38 -6
  61. package/package.json +1 -1
@@ -16,7 +16,8 @@ export function getCurrentPeriod(opts) {
16
16
  return AcademicPeriod.FallSemester;
17
17
  }
18
18
  export function isSessionPeriod(period) {
19
- return period === AcademicPeriod.WinterSession || period === AcademicPeriod.SummerSession;
19
+ return (period === AcademicPeriod.WinterSession ||
20
+ period === AcademicPeriod.SummerSession);
20
21
  }
21
22
  export function getAdjacentSemester(session) {
22
23
  return session === AcademicPeriod.WinterSession
@@ -7,8 +7,8 @@ function assertSemesterPeriod(period) {
7
7
  }
8
8
  }
9
9
  function calendarDayNumber(date) {
10
- return Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) /
11
- (24 * 60 * 60 * 1000);
10
+ return (Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) /
11
+ (24 * 60 * 60 * 1000));
12
12
  }
13
13
  function getAcademicYearStartYear(date) {
14
14
  const year = date.getFullYear();
@@ -1,22 +1,88 @@
1
1
  import { EducationLevel } from "../../common/types.js";
2
2
  const VO_TIME_SLOTS = [
3
- { slotNumber: 1, time: { start: { hours: 8, minutes: 20 }, end: { hours: 9, minutes: 40 } } },
4
- { slotNumber: 2, time: { start: { hours: 9, minutes: 50 }, end: { hours: 11, minutes: 10 } } },
5
- { slotNumber: 3, time: { start: { hours: 11, minutes: 40 }, end: { hours: 13, minutes: 0 } } },
6
- { slotNumber: 4, time: { start: { hours: 13, minutes: 30 }, end: { hours: 14, minutes: 50 } } },
7
- { slotNumber: 5, time: { start: { hours: 15, minutes: 0 }, end: { hours: 16, minutes: 20 } } },
8
- { slotNumber: 6, time: { start: { hours: 16, minutes: 40 }, end: { hours: 18, minutes: 0 } } },
9
- { slotNumber: 7, time: { start: { hours: 18, minutes: 10 }, end: { hours: 19, minutes: 30 } } },
10
- { slotNumber: 8, time: { start: { hours: 19, minutes: 40 }, end: { hours: 21, minutes: 0 } } },
3
+ {
4
+ slotNumber: 1,
5
+ time: { start: { hours: 8, minutes: 20 }, end: { hours: 9, minutes: 40 } },
6
+ },
7
+ {
8
+ slotNumber: 2,
9
+ time: { start: { hours: 9, minutes: 50 }, end: { hours: 11, minutes: 10 } },
10
+ },
11
+ {
12
+ slotNumber: 3,
13
+ time: { start: { hours: 11, minutes: 40 }, end: { hours: 13, minutes: 0 } },
14
+ },
15
+ {
16
+ slotNumber: 4,
17
+ time: {
18
+ start: { hours: 13, minutes: 30 },
19
+ end: { hours: 14, minutes: 50 },
20
+ },
21
+ },
22
+ {
23
+ slotNumber: 5,
24
+ time: { start: { hours: 15, minutes: 0 }, end: { hours: 16, minutes: 20 } },
25
+ },
26
+ {
27
+ slotNumber: 6,
28
+ time: { start: { hours: 16, minutes: 40 }, end: { hours: 18, minutes: 0 } },
29
+ },
30
+ {
31
+ slotNumber: 7,
32
+ time: {
33
+ start: { hours: 18, minutes: 10 },
34
+ end: { hours: 19, minutes: 30 },
35
+ },
36
+ },
37
+ {
38
+ slotNumber: 8,
39
+ time: { start: { hours: 19, minutes: 40 }, end: { hours: 21, minutes: 0 } },
40
+ },
11
41
  ];
12
42
  const SPO_TIME_SLOTS = [
13
- { slotNumber: 1, time: { start: { hours: 8, minutes: 10 }, end: { hours: 9, minutes: 40 } } },
14
- { slotNumber: 2, time: { start: { hours: 9, minutes: 55 }, end: { hours: 11, minutes: 25 } } },
15
- { slotNumber: 3, time: { start: { hours: 11, minutes: 55 }, end: { hours: 13, minutes: 25 } } },
16
- { slotNumber: 4, time: { start: { hours: 13, minutes: 40 }, end: { hours: 15, minutes: 10 } } },
17
- { slotNumber: 5, time: { start: { hours: 15, minutes: 25 }, end: { hours: 16, minutes: 55 } } },
18
- { slotNumber: 6, time: { start: { hours: 17, minutes: 10 }, end: { hours: 18, minutes: 40 } } },
19
- { slotNumber: 7, time: { start: { hours: 18, minutes: 55 }, end: { hours: 20, minutes: 25 } } },
43
+ {
44
+ slotNumber: 1,
45
+ time: { start: { hours: 8, minutes: 10 }, end: { hours: 9, minutes: 40 } },
46
+ },
47
+ {
48
+ slotNumber: 2,
49
+ time: { start: { hours: 9, minutes: 55 }, end: { hours: 11, minutes: 25 } },
50
+ },
51
+ {
52
+ slotNumber: 3,
53
+ time: {
54
+ start: { hours: 11, minutes: 55 },
55
+ end: { hours: 13, minutes: 25 },
56
+ },
57
+ },
58
+ {
59
+ slotNumber: 4,
60
+ time: {
61
+ start: { hours: 13, minutes: 40 },
62
+ end: { hours: 15, minutes: 10 },
63
+ },
64
+ },
65
+ {
66
+ slotNumber: 5,
67
+ time: {
68
+ start: { hours: 15, minutes: 25 },
69
+ end: { hours: 16, minutes: 55 },
70
+ },
71
+ },
72
+ {
73
+ slotNumber: 6,
74
+ time: {
75
+ start: { hours: 17, minutes: 10 },
76
+ end: { hours: 18, minutes: 40 },
77
+ },
78
+ },
79
+ {
80
+ slotNumber: 7,
81
+ time: {
82
+ start: { hours: 18, minutes: 55 },
83
+ end: { hours: 20, minutes: 25 },
84
+ },
85
+ },
20
86
  ];
21
87
  export function getStandardScheduleBlocks(educationLevel) {
22
88
  const blocks = educationLevel === EducationLevel.VocationalEducation
@@ -0,0 +1,5 @@
1
+ export type WebinarChatSubscriptionFormat = "ids" | "count";
2
+ /** Negotiate the subscription signature, then retain it for this participant. */
3
+ export declare function subscribeToWebinarChat(transport: {
4
+ subscribe(name: string, params: unknown[]): Promise<void>;
5
+ }, chatIds: string[], format: WebinarChatSubscriptionFormat | null): Promise<WebinarChatSubscriptionFormat>;
@@ -0,0 +1,20 @@
1
+ import { WebinarProtocolError } from "./types.js";
2
+ /** Negotiate the subscription signature, then retain it for this participant. */
3
+ export async function subscribeToWebinarChat(transport, chatIds, format) {
4
+ if (format !== null) {
5
+ await transport.subscribe("group-chat-msg", format === "ids" ? [chatIds] : [chatIds.length]);
6
+ return format;
7
+ }
8
+ try {
9
+ await transport.subscribe("group-chat-msg", [chatIds]);
10
+ return "ids";
11
+ }
12
+ catch (error) {
13
+ // Only a signature mismatch permits another signature, never an auth/transport failure.
14
+ if (!(error instanceof WebinarProtocolError) ||
15
+ (error.code !== 400 && error.code !== "400"))
16
+ throw error;
17
+ await transport.subscribe("group-chat-msg", [chatIds.length]);
18
+ return "count";
19
+ }
20
+ }
@@ -7,6 +7,8 @@ export declare class WebinarClient {
7
7
  private listeners;
8
8
  private ready;
9
9
  private started;
10
+ private chatSubscriptionFormat;
11
+ private leaving;
10
12
  constructor(session: WebinarSession, opts?: WebinarClientOptions);
11
13
  connect(): Promise<void>;
12
14
  private assertConnected;
@@ -18,6 +20,17 @@ export declare class WebinarClient {
18
20
  getMessages(opts?: {
19
21
  chatId?: string;
20
22
  }): import("./types.js").WebinarMessage[];
23
+ getTypingUsers(opts?: {
24
+ chatId?: string;
25
+ }): {
26
+ userId: string;
27
+ name: string;
28
+ chatId: string;
29
+ }[];
30
+ /** Explicit typing state only; opening/reading a room never sends typing events. */
31
+ setTyping(typing: boolean, opts?: {
32
+ chatId?: string;
33
+ }): Promise<void>;
21
34
  getPresentations(): import("./types.js").WebinarPresentation[];
22
35
  getCurrentPresentation(): import("./types.js").WebinarPresentation | null;
23
36
  getMediaStreams(): import("./types.js").WebinarMediaStream[];
@@ -47,6 +60,8 @@ export declare class WebinarClient {
47
60
  text: string;
48
61
  }): Promise<void>;
49
62
  setMuted(muted: boolean): Promise<void>;
50
- /** Closes local transport; does not issue userLeftMeeting or alter other users. */
63
+ /** Explicitly leaves this participant, then closes transport even if BBB rejects the request. */
64
+ leave(): Promise<void>;
65
+ /** Closes local transport; use leave() for an explicit room exit. */
51
66
  close(): void;
52
67
  }
@@ -3,6 +3,7 @@ import { WebinarDdp } from "./ddp.js";
3
3
  import { webinarEvents } from "./events.js";
4
4
  import { record, string } from "./parse.js";
5
5
  import { browserWebinarSocket } from "./socket.js";
6
+ import { subscribeToWebinarChat, } from "./chat-subscription.js";
6
7
  import { buildWebinarSnapshot, normalizeWebinarMessage } from "./state.js";
7
8
  import { WebinarPermissionError, WebinarProtocolError, } from "./types.js";
8
9
  /** Live participant state and explicit actions; never auto-connects media. */
@@ -13,8 +14,10 @@ export class WebinarClient {
13
14
  listeners = new Set();
14
15
  ready = false;
15
16
  started = false;
17
+ chatSubscriptionFormat = null;
18
+ leaving = null;
16
19
  constructor(session, opts = {}) {
17
- if (session.protocol !== "ddp" || !/^2\.3(?:\.|$)/u.test(session.server.version)) {
20
+ if (session.protocol !== "ddp") {
18
21
  throw new WebinarProtocolError("Unsupported webinar participant protocol");
19
22
  }
20
23
  this.session = structuredClone(session);
@@ -22,12 +25,23 @@ export class WebinarClient {
22
25
  this.ddp.onChange((collection, id, removed) => {
23
26
  this.emit({ type: "change", collection });
24
27
  if (collection === "group-chat-msg" && !removed) {
25
- const doc = this.ddp.documents(collection).find((message) => message._id === id);
28
+ const doc = this.ddp
29
+ .documents(collection)
30
+ .find((message) => message._id === id);
26
31
  if (doc)
27
- this.emit({ type: "message", message: normalizeWebinarMessage(doc, [...this.ddp.documents("users"), ...this.ddp.documents("users-persistent-data")]) });
32
+ this.emit({
33
+ type: "message",
34
+ message: normalizeWebinarMessage(doc, [
35
+ ...this.ddp.documents("users"),
36
+ ...this.ddp.documents("users-persistent-data"),
37
+ ]),
38
+ });
28
39
  }
29
40
  });
30
- this.ddp.onDisconnect(() => { this.ready = false; this.emit({ type: "disconnected" }); });
41
+ this.ddp.onDisconnect(() => {
42
+ this.ready = false;
43
+ this.emit({ type: "disconnected" });
44
+ });
31
45
  this.ddp.onError((error) => this.emit({ type: "error", error }));
32
46
  }
33
47
  async connect() {
@@ -36,18 +50,40 @@ export class WebinarClient {
36
50
  this.started = true;
37
51
  try {
38
52
  await this.ddp.connect(this.session.connections.state);
39
- await this.ddp.call("validateAuthToken", [this.session.meeting.id, this.session.user.id,
40
- this.session.authToken, this.session.externalUserId]);
41
- await this.ddp.subscribe("auth-token-validation", [{ meetingId: this.session.meeting.id, userId: this.session.user.id }]);
42
- const validation = await this.ddp.waitFor("auth-token-validation", (doc) => doc.userId === this.session.user.id && (doc.validationStatus === 3 || doc.validationStatus === 4));
53
+ await this.ddp.call("validateAuthToken", [
54
+ this.session.meeting.id,
55
+ this.session.user.id,
56
+ this.session.authToken,
57
+ this.session.externalUserId,
58
+ ]);
59
+ await this.ddp.subscribe("auth-token-validation", [
60
+ { meetingId: this.session.meeting.id, userId: this.session.user.id },
61
+ ]);
62
+ const validation = await this.ddp.waitFor("auth-token-validation", (doc) => doc.userId === this.session.user.id &&
63
+ (doc.validationStatus === 3 || doc.validationStatus === 4));
43
64
  if (validation.validationStatus !== 3)
44
65
  throw new AuthError("Webinar participant authentication rejected");
45
66
  await Promise.all([
46
- "current-user", "users", "users-persistent-data", "meetings", "voiceUsers",
47
- "presentations", "slides", "slide-positions", "presentation-pods", "video-streams", "screenshare", "note", "group-chat",
67
+ "current-user",
68
+ "users",
69
+ "users-persistent-data",
70
+ "meetings",
71
+ "voiceUsers",
72
+ "presentations",
73
+ "slides",
74
+ "slide-positions",
75
+ "presentation-pods",
76
+ "video-streams",
77
+ "screenshare",
78
+ "note",
79
+ "group-chat",
48
80
  ].map((name) => this.ddp.subscribe(name)));
49
- const chatIds = this.ddp.documents("group-chat").map((chat) => string(chat.chatId));
50
- await this.ddp.subscribe("group-chat-msg", [chatIds]);
81
+ const chatIds = this.ddp
82
+ .documents("group-chat")
83
+ .map((chat) => string(chat.chatId));
84
+ this.chatSubscriptionFormat = await subscribeToWebinarChat(this.ddp, chatIds, this.chatSubscriptionFormat);
85
+ if (this.session.features.typing)
86
+ await this.ddp.subscribe("users-typing");
51
87
  this.ready = true;
52
88
  if (this.session.features.chat)
53
89
  await this.loadMessages();
@@ -65,18 +101,59 @@ export class WebinarClient {
65
101
  this.assertConnected();
66
102
  return buildWebinarSnapshot(this.ddp, this.session, this.history);
67
103
  }
68
- getUsers() { return this.getSnapshot().users; }
69
- getPresenter() { return this.getUsers().find((user) => user.presenter) ?? null; }
70
- getModerators() { return this.getUsers().filter((user) => user.moderator); }
71
- getChats() { return this.getSnapshot().chats; }
104
+ getUsers() {
105
+ return this.getSnapshot().users;
106
+ }
107
+ getPresenter() {
108
+ return this.getUsers().find((user) => user.presenter) ?? null;
109
+ }
110
+ getModerators() {
111
+ return this.getUsers().filter((user) => user.moderator);
112
+ }
113
+ getChats() {
114
+ return this.getSnapshot().chats;
115
+ }
72
116
  getMessages(opts) {
73
117
  const chatId = opts?.chatId ?? this.session.publicChatId;
74
118
  return this.getSnapshot().messages.filter((message) => message.chatId === chatId);
75
119
  }
76
- getPresentations() { return this.getSnapshot().presentations; }
77
- getCurrentPresentation() { return this.getPresentations().find((presentation) => presentation.current) ?? null; }
78
- getMediaStreams() { return this.getSnapshot().streams; }
79
- getNotes() { return this.getSnapshot().notes; }
120
+ getTypingUsers(opts = {}) {
121
+ const chatId = opts.chatId ?? this.session.publicChatId;
122
+ return (this.getSnapshot().typingUsers ?? []).filter((user) => user.chatId === chatId);
123
+ }
124
+ /** Explicit typing state only; opening/reading a room never sends typing events. */
125
+ async setTyping(typing, opts = {}) {
126
+ if (typeof typing !== "boolean")
127
+ throw new TypeError("Typing state must be boolean");
128
+ const chatId = opts.chatId ?? this.session.publicChatId;
129
+ const chat = this.getChats().find((chat) => chat.id === chatId);
130
+ if (!chat)
131
+ throw new WebinarPermissionError("Chat is not accessible");
132
+ this.assertPermission("typing", chat.private ? "disablePrivateChat" : "disablePublicChat");
133
+ if (!typing) {
134
+ await this.ddp.call("stopUserTyping");
135
+ return;
136
+ }
137
+ const target = chat.private
138
+ ? chat.userIds.find((id) => id !== this.session.user.id)
139
+ : (this.session.publicTypingId ?? this.session.publicChatId);
140
+ if (!target)
141
+ throw new WebinarPermissionError("Typing recipient is not available");
142
+ await this.ddp.call("startUserTyping", [target]);
143
+ }
144
+ getPresentations() {
145
+ return this.getSnapshot().presentations;
146
+ }
147
+ getCurrentPresentation() {
148
+ return (this.getPresentations().find((presentation) => presentation.current) ??
149
+ null);
150
+ }
151
+ getMediaStreams() {
152
+ return this.getSnapshot().streams;
153
+ }
154
+ getNotes() {
155
+ return this.getSnapshot().notes;
156
+ }
80
157
  /** Reads historical pages; live messages arrive through events(). */
81
158
  async loadMessages(opts = {}) {
82
159
  this.assertConnected();
@@ -94,11 +171,18 @@ export class WebinarClient {
94
171
  if (doc.chatId === chatId)
95
172
  this.history.set(string(doc.id) || string(doc._id), doc);
96
173
  this.emit({ type: "change", collection: "group-chat-msg" });
97
- return docs.filter((doc) => doc.chatId === chatId).map((doc) => normalizeWebinarMessage(doc, [...this.ddp.documents("users"), ...this.ddp.documents("users-persistent-data")]));
174
+ return docs
175
+ .filter((doc) => doc.chatId === chatId)
176
+ .map((doc) => normalizeWebinarMessage(doc, [
177
+ ...this.ddp.documents("users"),
178
+ ...this.ddp.documents("users-persistent-data"),
179
+ ]));
98
180
  }
99
181
  subscribe(listener) {
100
182
  this.listeners.add(listener);
101
- return () => { this.listeners.delete(listener); };
183
+ return () => {
184
+ this.listeners.delete(listener);
185
+ };
102
186
  }
103
187
  events(opts) {
104
188
  return webinarEvents((listener) => this.subscribe(listener), opts);
@@ -109,7 +193,9 @@ export class WebinarClient {
109
193
  try {
110
194
  listener(event);
111
195
  }
112
- catch { /* Listener errors belong to the caller. */ }
196
+ catch {
197
+ /* Listener errors belong to the caller. */
198
+ }
113
199
  }
114
200
  }
115
201
  assertPermission(feature, lock) {
@@ -118,7 +204,10 @@ export class WebinarClient {
118
204
  throw new WebinarPermissionError(`Webinar feature disabled: ${feature}`);
119
205
  const user = this.getUsers().find((user) => user.id === this.session.user.id);
120
206
  const meeting = this.ddp.documents("meetings")[0];
121
- if (lock && user?.locked && !user.moderator && record(meeting?.lockSettingsProps)[lock] === true) {
207
+ if (lock &&
208
+ user?.locked &&
209
+ !user.moderator &&
210
+ record(meeting?.lockSettingsProps)[lock] === true) {
122
211
  throw new WebinarPermissionError(`Webinar permission locked: ${feature}`);
123
212
  }
124
213
  }
@@ -126,7 +215,10 @@ export class WebinarClient {
126
215
  if (typeof raised !== "boolean")
127
216
  throw new TypeError("Raised hand must be boolean");
128
217
  this.assertPermission("raiseHand");
129
- await this.ddp.call("setEmojiStatus", [this.session.user.id, raised ? "raiseHand" : "none"]);
218
+ await this.ddp.call("setEmojiStatus", [
219
+ this.session.user.id,
220
+ raised ? "raiseHand" : "none",
221
+ ]);
130
222
  }
131
223
  async sendMessage(opts) {
132
224
  const chatId = opts.chatId ?? this.session.publicChatId;
@@ -137,11 +229,17 @@ export class WebinarClient {
137
229
  const text = opts.text.trim();
138
230
  if (!text || text.length > this.session.maxMessageLength)
139
231
  throw new RangeError("Invalid webinar message length");
140
- await this.ddp.call("sendGroupChatMsg", [chatId, {
141
- color: string(this.ddp.documents("users").find((user) => user.userId === this.session.user.id)?.color) || "0",
232
+ await this.ddp.call("sendGroupChatMsg", [
233
+ chatId,
234
+ {
235
+ color: string(this.ddp
236
+ .documents("users")
237
+ .find((user) => user.userId === this.session.user.id)?.color) || "0",
142
238
  correlationId: `${this.session.user.id}-${Date.now()}`,
143
- sender: { id: this.session.user.id, name: this.session.user.name }, message: text,
144
- }]);
239
+ sender: { id: this.session.user.id, name: this.session.user.name },
240
+ message: text,
241
+ },
242
+ ]);
145
243
  }
146
244
  async openPrivateChat(opts) {
147
245
  this.assertPermission("chat", "disablePrivateChat");
@@ -153,15 +251,20 @@ export class WebinarClient {
153
251
  const user = this.getUsers().find((user) => user.id === opts.userId);
154
252
  if (!user)
155
253
  throw new RangeError("Invalid private chat recipient");
156
- await this.ddp.call("createGroupChat", [{ userId: user.id, name: user.name }]);
157
- await this.ddp.waitFor("group-chat", (chat) => chat.access === "PRIVATE_ACCESS"
158
- && Array.isArray(chat.users) && chat.users.includes(user.id) && chat.users.includes(this.session.user.id));
254
+ await this.ddp.call("createGroupChat", [
255
+ { userId: user.id, name: user.name },
256
+ ]);
257
+ await this.ddp.waitFor("group-chat", (chat) => chat.access === "PRIVATE_ACCESS" &&
258
+ Array.isArray(chat.users) &&
259
+ chat.users.includes(user.id) &&
260
+ chat.users.includes(this.session.user.id));
159
261
  const chat = this.getChats().find((chat) => chat.private && chat.userIds.includes(user.id));
160
- await this.ddp.subscribe("group-chat-msg", [this.getChats().map((chat) => chat.id)]);
262
+ this.chatSubscriptionFormat = await subscribeToWebinarChat(this.ddp, this.getChats().map((chat) => chat.id), this.chatSubscriptionFormat);
161
263
  return chat;
162
264
  }
163
265
  async sendPrivateMessage(opts) {
164
- if (!opts.text.trim() || opts.text.trim().length > this.session.maxMessageLength)
266
+ if (!opts.text.trim() ||
267
+ opts.text.trim().length > this.session.maxMessageLength)
165
268
  throw new RangeError("Invalid webinar message length");
166
269
  const chat = await this.openPrivateChat(opts);
167
270
  await this.sendMessage({ chatId: chat.id, text: opts.text });
@@ -175,7 +278,21 @@ export class WebinarClient {
175
278
  throw new WebinarPermissionError("Microphone audio is not connected");
176
279
  await this.ddp.call("muteToggle", [this.session.user.id, muted]);
177
280
  }
178
- /** Closes local transport; does not issue userLeftMeeting or alter other users. */
281
+ /** Explicitly leaves this participant, then closes transport even if BBB rejects the request. */
282
+ leave() {
283
+ if (this.leaving)
284
+ return this.leaving;
285
+ if (!this.ready) {
286
+ this.close();
287
+ return Promise.resolve();
288
+ }
289
+ this.leaving = this.ddp
290
+ .call("userLeftMeeting")
291
+ .then(() => undefined)
292
+ .finally(() => this.close());
293
+ return this.leaving;
294
+ }
295
+ /** Closes local transport; use leave() for an explicit room exit. */
179
296
  close() {
180
297
  this.ready = false;
181
298
  this.ddp.close();
@@ -1,5 +1,5 @@
1
1
  import { openWebinarSocket } from "./socket.js";
2
- import { WebinarProtocolError } from "./types.js";
2
+ import { WebinarProtocolError, } from "./types.js";
3
3
  /** DDP transport: no Meteor runtime and no profile/settings writes. */
4
4
  export class WebinarDdp {
5
5
  factory;
@@ -21,18 +21,26 @@ export class WebinarDdp {
21
21
  }
22
22
  onChange(listener) {
23
23
  this.listeners.add(listener);
24
- return () => { this.listeners.delete(listener); };
24
+ return () => {
25
+ this.listeners.delete(listener);
26
+ };
25
27
  }
26
28
  onDisconnect(listener) {
27
29
  this.disconnectListeners.add(listener);
28
- return () => { this.disconnectListeners.delete(listener); };
30
+ return () => {
31
+ this.disconnectListeners.delete(listener);
32
+ };
29
33
  }
30
34
  onError(listener) {
31
35
  this.errorListeners.add(listener);
32
- return () => { this.errorListeners.delete(listener); };
36
+ return () => {
37
+ this.errorListeners.delete(listener);
38
+ };
33
39
  }
34
40
  documents(collection) {
35
- return structuredClone([...this.collections.get(collection)?.values() ?? []]);
41
+ return structuredClone([
42
+ ...(this.collections.get(collection)?.values() ?? []),
43
+ ]);
36
44
  }
37
45
  async connect(url) {
38
46
  if (this.socket)
@@ -102,7 +110,9 @@ export class WebinarDdp {
102
110
  return existing;
103
111
  const id = `sub:${++this.sequence}`;
104
112
  const ready = this.wait(id);
105
- const subscription = ready.then(() => undefined).catch((error) => {
113
+ const subscription = ready
114
+ .then(() => undefined)
115
+ .catch((error) => {
106
116
  this.subscriptions.delete(key);
107
117
  throw error;
108
118
  });
@@ -120,7 +130,11 @@ export class WebinarDdp {
120
130
  disconnected();
121
131
  reject(new WebinarProtocolError("Webinar state timed out"));
122
132
  }, this.timeout);
123
- const finish = () => { clearTimeout(timer); unsubscribe(); disconnected(); };
133
+ const finish = () => {
134
+ clearTimeout(timer);
135
+ unsubscribe();
136
+ disconnected();
137
+ };
124
138
  const unsubscribe = this.onChange((changed) => {
125
139
  if (changed !== collection)
126
140
  return;
@@ -147,7 +161,10 @@ export class WebinarDdp {
147
161
  this.settle("connect", undefined, new WebinarProtocolError("DDP version rejected"));
148
162
  break;
149
163
  case "ping":
150
- this.send({ msg: "pong", ...(data.id === undefined ? {} : { id: data.id }) });
164
+ this.send({
165
+ msg: "pong",
166
+ ...(data.id === undefined ? {} : { id: data.id }),
167
+ });
151
168
  break;
152
169
  case "ready":
153
170
  if (Array.isArray(data.subs))
@@ -155,11 +172,18 @@ export class WebinarDdp {
155
172
  this.settle(String(id), undefined);
156
173
  break;
157
174
  case "nosub":
158
- case "result":
175
+ case "result": {
176
+ const error = data.error !== null && typeof data.error === "object"
177
+ ? data.error
178
+ : {};
179
+ const code = typeof error.error === "number" || typeof error.error === "string"
180
+ ? error.error
181
+ : undefined;
159
182
  this.settle(String(data.id), data.result, data.error
160
- ? new WebinarProtocolError(`Webinar ${data.msg === "nosub" ? "subscription" : "method"} rejected`)
183
+ ? new WebinarProtocolError(`Webinar ${data.msg === "nosub" ? "subscription" : "method"} rejected`, code)
161
184
  : undefined);
162
185
  break;
186
+ }
163
187
  case "added":
164
188
  case "changed":
165
189
  case "removed": {
@@ -173,9 +197,16 @@ export class WebinarDdp {
173
197
  if (data.msg === "removed")
174
198
  collection.delete(data.id);
175
199
  else {
176
- const fields = data.fields !== null && typeof data.fields === "object" && !Array.isArray(data.fields)
177
- ? data.fields : {};
178
- const doc = { ...(data.msg === "added" ? {} : collection.get(data.id)), ...fields, _id: data.id };
200
+ const fields = data.fields !== null &&
201
+ typeof data.fields === "object" &&
202
+ !Array.isArray(data.fields)
203
+ ? data.fields
204
+ : {};
205
+ const doc = {
206
+ ...(data.msg === "added" ? {} : collection.get(data.id)),
207
+ ...fields,
208
+ _id: data.id,
209
+ };
179
210
  if (Array.isArray(data.cleared))
180
211
  for (const field of data.cleared)
181
212
  if (field !== "_id")
@@ -18,7 +18,10 @@ export async function* webinarEvents(subscribe, opts = {}) {
18
18
  done = true;
19
19
  wake?.();
20
20
  });
21
- const abort = () => { done = true; wake?.(); };
21
+ const abort = () => {
22
+ done = true;
23
+ wake?.();
24
+ };
22
25
  opts.signal?.addEventListener("abort", abort, { once: true });
23
26
  try {
24
27
  while (queue.length || !done) {
@@ -28,7 +31,9 @@ export async function* webinarEvents(subscribe, opts = {}) {
28
31
  if (event)
29
32
  yield event;
30
33
  else
31
- await new Promise((resolve) => { wake = resolve; });
34
+ await new Promise((resolve) => {
35
+ wake = resolve;
36
+ });
32
37
  }
33
38
  }
34
39
  finally {
@@ -1,4 +1,4 @@
1
- import { type WebinarSession, type WebinarSlide } from "./types.js";
1
+ import { type WebinarSession, type WebinarSlide, type WebinarSocket } from "./types.js";
2
2
  import { WebinarClient } from "./client.js";
3
3
  /** Backend-only LK/BBB bootstrap and same-server presentation HTTP access. */
4
4
  export declare class WebinarGateway {
@@ -6,6 +6,8 @@ export declare class WebinarGateway {
6
6
  private session;
7
7
  private client;
8
8
  getSession(): WebinarSession;
9
+ /** Cookie-authenticated signaling socket; audio/video WebRTC stays in the browser. */
10
+ createMediaSocket(): WebinarSocket;
9
11
  openSession(opts: {
10
12
  joinUrl: string;
11
13
  }): Promise<WebinarSession>;