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.
Files changed (58) 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.js +2 -1
  38. package/dist/webinar/client.d.ts +11 -0
  39. package/dist/webinar/client.js +136 -33
  40. package/dist/webinar/ddp.js +40 -13
  41. package/dist/webinar/events.js +7 -2
  42. package/dist/webinar/gateway.js +57 -16
  43. package/dist/webinar/media-protocol.d.ts +2 -1
  44. package/dist/webinar/media-protocol.js +27 -5
  45. package/dist/webinar/media.js +10 -4
  46. package/dist/webinar/parse.js +59 -14
  47. package/dist/webinar/playback.d.ts +1 -0
  48. package/dist/webinar/playback.js +49 -13
  49. package/dist/webinar/socket.js +4 -1
  50. package/dist/webinar/state.js +73 -26
  51. package/dist/webinar/types.d.ts +12 -0
  52. package/dist/webinar/typing.d.ts +8 -0
  53. package/dist/webinar/typing.js +36 -0
  54. package/docs/fixture-review.md +44 -44
  55. package/docs/student-portal.md +11 -2
  56. package/docs/v5-migration.md +85 -88
  57. package/docs/webinar.md +15 -2
  58. 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
@@ -11,7 +11,8 @@ export async function subscribeToWebinarChat(transport, chatIds, format) {
11
11
  }
12
12
  catch (error) {
13
13
  // Only a signature mismatch permits another signature, never an auth/transport failure.
14
- if (!(error instanceof WebinarProtocolError) || (error.code !== 400 && error.code !== "400"))
14
+ if (!(error instanceof WebinarProtocolError) ||
15
+ (error.code !== 400 && error.code !== "400"))
15
16
  throw error;
16
17
  await transport.subscribe("group-chat-msg", [chatIds.length]);
17
18
  return "count";
@@ -20,6 +20,17 @@ export declare class WebinarClient {
20
20
  getMessages(opts?: {
21
21
  chatId?: string;
22
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>;
23
34
  getPresentations(): import("./types.js").WebinarPresentation[];
24
35
  getCurrentPresentation(): import("./types.js").WebinarPresentation | null;
25
36
  getMediaStreams(): import("./types.js").WebinarMediaStream[];
@@ -3,7 +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
+ import { subscribeToWebinarChat, } from "./chat-subscription.js";
7
7
  import { buildWebinarSnapshot, normalizeWebinarMessage } from "./state.js";
8
8
  import { WebinarPermissionError, WebinarProtocolError, } from "./types.js";
9
9
  /** Live participant state and explicit actions; never auto-connects media. */
@@ -25,12 +25,23 @@ export class WebinarClient {
25
25
  this.ddp.onChange((collection, id, removed) => {
26
26
  this.emit({ type: "change", collection });
27
27
  if (collection === "group-chat-msg" && !removed) {
28
- 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);
29
31
  if (doc)
30
- 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
+ });
31
39
  }
32
40
  });
33
- this.ddp.onDisconnect(() => { this.ready = false; this.emit({ type: "disconnected" }); });
41
+ this.ddp.onDisconnect(() => {
42
+ this.ready = false;
43
+ this.emit({ type: "disconnected" });
44
+ });
34
45
  this.ddp.onError((error) => this.emit({ type: "error", error }));
35
46
  }
36
47
  async connect() {
@@ -39,18 +50,40 @@ export class WebinarClient {
39
50
  this.started = true;
40
51
  try {
41
52
  await this.ddp.connect(this.session.connections.state);
42
- await this.ddp.call("validateAuthToken", [this.session.meeting.id, this.session.user.id,
43
- this.session.authToken, this.session.externalUserId]);
44
- await this.ddp.subscribe("auth-token-validation", [{ meetingId: this.session.meeting.id, userId: this.session.user.id }]);
45
- 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));
46
64
  if (validation.validationStatus !== 3)
47
65
  throw new AuthError("Webinar participant authentication rejected");
48
66
  await Promise.all([
49
- "current-user", "users", "users-persistent-data", "meetings", "voiceUsers",
50
- "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",
51
80
  ].map((name) => this.ddp.subscribe(name)));
52
- const chatIds = this.ddp.documents("group-chat").map((chat) => string(chat.chatId));
81
+ const chatIds = this.ddp
82
+ .documents("group-chat")
83
+ .map((chat) => string(chat.chatId));
53
84
  this.chatSubscriptionFormat = await subscribeToWebinarChat(this.ddp, chatIds, this.chatSubscriptionFormat);
85
+ if (this.session.features.typing)
86
+ await this.ddp.subscribe("users-typing");
54
87
  this.ready = true;
55
88
  if (this.session.features.chat)
56
89
  await this.loadMessages();
@@ -68,18 +101,59 @@ export class WebinarClient {
68
101
  this.assertConnected();
69
102
  return buildWebinarSnapshot(this.ddp, this.session, this.history);
70
103
  }
71
- getUsers() { return this.getSnapshot().users; }
72
- getPresenter() { return this.getUsers().find((user) => user.presenter) ?? null; }
73
- getModerators() { return this.getUsers().filter((user) => user.moderator); }
74
- 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
+ }
75
116
  getMessages(opts) {
76
117
  const chatId = opts?.chatId ?? this.session.publicChatId;
77
118
  return this.getSnapshot().messages.filter((message) => message.chatId === chatId);
78
119
  }
79
- getPresentations() { return this.getSnapshot().presentations; }
80
- getCurrentPresentation() { return this.getPresentations().find((presentation) => presentation.current) ?? null; }
81
- getMediaStreams() { return this.getSnapshot().streams; }
82
- 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
+ }
83
157
  /** Reads historical pages; live messages arrive through events(). */
84
158
  async loadMessages(opts = {}) {
85
159
  this.assertConnected();
@@ -97,11 +171,18 @@ export class WebinarClient {
97
171
  if (doc.chatId === chatId)
98
172
  this.history.set(string(doc.id) || string(doc._id), doc);
99
173
  this.emit({ type: "change", collection: "group-chat-msg" });
100
- 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
+ ]));
101
180
  }
102
181
  subscribe(listener) {
103
182
  this.listeners.add(listener);
104
- return () => { this.listeners.delete(listener); };
183
+ return () => {
184
+ this.listeners.delete(listener);
185
+ };
105
186
  }
106
187
  events(opts) {
107
188
  return webinarEvents((listener) => this.subscribe(listener), opts);
@@ -112,7 +193,9 @@ export class WebinarClient {
112
193
  try {
113
194
  listener(event);
114
195
  }
115
- catch { /* Listener errors belong to the caller. */ }
196
+ catch {
197
+ /* Listener errors belong to the caller. */
198
+ }
116
199
  }
117
200
  }
118
201
  assertPermission(feature, lock) {
@@ -121,7 +204,10 @@ export class WebinarClient {
121
204
  throw new WebinarPermissionError(`Webinar feature disabled: ${feature}`);
122
205
  const user = this.getUsers().find((user) => user.id === this.session.user.id);
123
206
  const meeting = this.ddp.documents("meetings")[0];
124
- 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) {
125
211
  throw new WebinarPermissionError(`Webinar permission locked: ${feature}`);
126
212
  }
127
213
  }
@@ -129,7 +215,10 @@ export class WebinarClient {
129
215
  if (typeof raised !== "boolean")
130
216
  throw new TypeError("Raised hand must be boolean");
131
217
  this.assertPermission("raiseHand");
132
- 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
+ ]);
133
222
  }
134
223
  async sendMessage(opts) {
135
224
  const chatId = opts.chatId ?? this.session.publicChatId;
@@ -140,11 +229,17 @@ export class WebinarClient {
140
229
  const text = opts.text.trim();
141
230
  if (!text || text.length > this.session.maxMessageLength)
142
231
  throw new RangeError("Invalid webinar message length");
143
- await this.ddp.call("sendGroupChatMsg", [chatId, {
144
- 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",
145
238
  correlationId: `${this.session.user.id}-${Date.now()}`,
146
- sender: { id: this.session.user.id, name: this.session.user.name }, message: text,
147
- }]);
239
+ sender: { id: this.session.user.id, name: this.session.user.name },
240
+ message: text,
241
+ },
242
+ ]);
148
243
  }
149
244
  async openPrivateChat(opts) {
150
245
  this.assertPermission("chat", "disablePrivateChat");
@@ -156,15 +251,20 @@ export class WebinarClient {
156
251
  const user = this.getUsers().find((user) => user.id === opts.userId);
157
252
  if (!user)
158
253
  throw new RangeError("Invalid private chat recipient");
159
- await this.ddp.call("createGroupChat", [{ userId: user.id, name: user.name }]);
160
- await this.ddp.waitFor("group-chat", (chat) => chat.access === "PRIVATE_ACCESS"
161
- && 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));
162
261
  const chat = this.getChats().find((chat) => chat.private && chat.userIds.includes(user.id));
163
262
  this.chatSubscriptionFormat = await subscribeToWebinarChat(this.ddp, this.getChats().map((chat) => chat.id), this.chatSubscriptionFormat);
164
263
  return chat;
165
264
  }
166
265
  async sendPrivateMessage(opts) {
167
- if (!opts.text.trim() || opts.text.trim().length > this.session.maxMessageLength)
266
+ if (!opts.text.trim() ||
267
+ opts.text.trim().length > this.session.maxMessageLength)
168
268
  throw new RangeError("Invalid webinar message length");
169
269
  const chat = await this.openPrivateChat(opts);
170
270
  await this.sendMessage({ chatId: chat.id, text: opts.text });
@@ -186,7 +286,10 @@ export class WebinarClient {
186
286
  this.close();
187
287
  return Promise.resolve();
188
288
  }
189
- this.leaving = this.ddp.call("userLeftMeeting").then(() => undefined).finally(() => this.close());
289
+ this.leaving = this.ddp
290
+ .call("userLeftMeeting")
291
+ .then(() => undefined)
292
+ .finally(() => this.close());
190
293
  return this.leaving;
191
294
  }
192
295
  /** Closes local transport; use leave() for an explicit room exit. */
@@ -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))
@@ -157,8 +174,11 @@ export class WebinarDdp {
157
174
  case "nosub":
158
175
  case "result": {
159
176
  const error = data.error !== null && typeof data.error === "object"
160
- ? data.error : {};
161
- const code = typeof error.error === "number" || typeof error.error === "string" ? error.error : undefined;
177
+ ? data.error
178
+ : {};
179
+ const code = typeof error.error === "number" || typeof error.error === "string"
180
+ ? error.error
181
+ : undefined;
162
182
  this.settle(String(data.id), data.result, data.error
163
183
  ? new WebinarProtocolError(`Webinar ${data.msg === "nosub" ? "subscription" : "method"} rejected`, code)
164
184
  : undefined);
@@ -177,9 +197,16 @@ export class WebinarDdp {
177
197
  if (data.msg === "removed")
178
198
  collection.delete(data.id);
179
199
  else {
180
- const fields = data.fields !== null && typeof data.fields === "object" && !Array.isArray(data.fields)
181
- ? data.fields : {};
182
- 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
+ };
183
210
  if (Array.isArray(data.cleared))
184
211
  for (const field of data.cleared)
185
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 {