chuvsu-js 5.4.0 → 5.5.0
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 +32 -3
- package/dist/common/http.d.ts +3 -1
- package/dist/common/http.js +9 -2
- package/dist/{tt/utils → common}/lesson-type.d.ts +4 -2
- package/dist/{tt/utils → common}/lesson-type.js +17 -2
- package/dist/core.d.ts +13 -5
- package/dist/core.js +7 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lk/client.d.ts +23 -1
- package/dist/lk/client.js +95 -0
- package/dist/lk/parse/grade-value.d.ts +4 -0
- package/dist/lk/parse/grade-value.js +16 -0
- package/dist/lk/parse/portfolio-content.d.ts +10 -0
- package/dist/lk/parse/portfolio-content.js +116 -0
- package/dist/lk/parse/portfolio-grades.d.ts +8 -0
- package/dist/lk/parse/portfolio-grades.js +41 -0
- package/dist/lk/parse/portfolio-performance.d.ts +2 -0
- package/dist/lk/parse/portfolio-performance.js +44 -0
- package/dist/lk/parse/portfolio.d.ts +6 -0
- package/dist/lk/parse/portfolio.js +64 -0
- package/dist/lk/parse/webinar-lesson.d.ts +7 -0
- package/dist/lk/parse/webinar-lesson.js +28 -0
- package/dist/lk/parse/webinars.d.ts +3 -0
- package/dist/lk/parse/webinars.js +67 -0
- package/dist/lk/portfolio-types.d.ts +113 -0
- package/dist/lk/portfolio-types.js +1 -0
- package/dist/lk/types.d.ts +29 -0
- package/dist/{tt → lk}/webinars.d.ts +3 -1
- package/dist/lk/webinars.js +52 -0
- package/dist/parsers.d.ts +3 -1
- package/dist/parsers.js +3 -1
- package/dist/tt/client.d.ts +1 -11
- package/dist/tt/client.js +1 -45
- package/dist/tt/domain/schedule.js +5 -1
- package/dist/tt/domain/substitution-occurrences.d.ts +3 -0
- package/dist/tt/domain/substitution-occurrences.js +75 -0
- package/dist/tt/domain/types.d.ts +1 -1
- package/dist/tt/observations.js +2 -1
- package/dist/tt/parse/index.d.ts +0 -1
- package/dist/tt/parse/index.js +0 -1
- package/dist/tt/types.d.ts +0 -21
- package/dist/tt/utils/index.d.ts +0 -1
- package/dist/tt/utils/index.js +0 -1
- package/dist/webinar/client.d.ts +52 -0
- package/dist/webinar/client.js +184 -0
- package/dist/webinar/ddp.d.ts +31 -0
- package/dist/webinar/ddp.js +208 -0
- package/dist/webinar/events.d.ts +6 -0
- package/dist/webinar/events.js +38 -0
- package/dist/webinar/gateway.d.ts +30 -0
- package/dist/webinar/gateway.js +114 -0
- package/dist/webinar/media-protocol.d.ts +9 -0
- package/dist/webinar/media-protocol.js +24 -0
- package/dist/webinar/media-types.d.ts +10 -0
- package/dist/webinar/media-types.js +1 -0
- package/dist/webinar/media.d.ts +21 -0
- package/dist/webinar/media.js +76 -0
- package/dist/webinar/parse.d.ts +14 -0
- package/dist/webinar/parse.js +113 -0
- package/dist/webinar/playback.d.ts +32 -0
- package/dist/webinar/playback.js +188 -0
- package/dist/webinar/socket.d.ts +3 -0
- package/dist/webinar/socket.js +18 -0
- package/dist/webinar/state.d.ts +4 -0
- package/dist/webinar/state.js +98 -0
- package/dist/webinar/types.d.ts +148 -0
- package/dist/webinar/types.js +12 -0
- package/docs/student-portal.md +151 -0
- package/docs/testing.md +13 -0
- package/docs/v5-migration.md +25 -2
- package/docs/webinar.md +145 -0
- package/package.json +2 -2
- package/dist/tt/parse/webinars.d.ts +0 -2
- package/dist/tt/parse/webinars.js +0 -97
- package/dist/tt/webinars.js +0 -39
package/dist/tt/types.d.ts
CHANGED
|
@@ -130,26 +130,6 @@ export interface SemesterWeek {
|
|
|
130
130
|
start: Date;
|
|
131
131
|
end: Date;
|
|
132
132
|
}
|
|
133
|
-
export interface Webinar {
|
|
134
|
-
/** Internal tt.chuvsu.ru webinar id used by `/webinar/getjoin`. */
|
|
135
|
-
id: string;
|
|
136
|
-
/** Webinar table type argument (`idwt`) used by `/webinar/getjoin`. */
|
|
137
|
-
idType: number;
|
|
138
|
-
/** True for "Вебинары по расписанию"; false for external webinars. */
|
|
139
|
-
scheduled: boolean;
|
|
140
|
-
scheduledDate?: LocalDate;
|
|
141
|
-
slotNumber?: number;
|
|
142
|
-
time: TimeRange;
|
|
143
|
-
subject: string;
|
|
144
|
-
type: string;
|
|
145
|
-
teacher: Teacher;
|
|
146
|
-
groups: string[];
|
|
147
|
-
subgroup?: number;
|
|
148
|
-
/** Free-form title/topic from the second table column. */
|
|
149
|
-
title: string;
|
|
150
|
-
/** Raw first-column text as rendered by tt.chuvsu.ru. */
|
|
151
|
-
raw: string;
|
|
152
|
-
}
|
|
153
133
|
export interface CacheConfig {
|
|
154
134
|
schedule?: number;
|
|
155
135
|
faculties?: number;
|
|
@@ -161,7 +141,6 @@ export interface CacheConfig {
|
|
|
161
141
|
teacherPhotos?: number;
|
|
162
142
|
roomInfo?: number;
|
|
163
143
|
roomImages?: number;
|
|
164
|
-
webinars?: number;
|
|
165
144
|
}
|
|
166
145
|
export interface TimetableClientOptions {
|
|
167
146
|
educationLevel?: EducationLevel;
|
package/dist/tt/utils/index.d.ts
CHANGED
|
@@ -2,6 +2,5 @@ export { formatLocalDate, getMonday, getWeekdayName, isSameDay, isLocalDate, par
|
|
|
2
2
|
export { getAdjacentSemester, getCurrentPeriod, isSessionPeriod, } from "./period.js";
|
|
3
3
|
export { getSemesterStart, getSemesterWeeks, getWeekNumber, } from "./semester.js";
|
|
4
4
|
export { getStandardScheduleBlocks } from "./time-slots.js";
|
|
5
|
-
export { LessonType, parseLessonType } from "./lesson-type.js";
|
|
6
5
|
export { getCompensatingWorkDays, getEffectiveHolidays, getHolidayTransfers, isHoliday, RUSSIAN_HOLIDAYS, } from "./holidays.js";
|
|
7
6
|
export type { Holiday, HolidayTransfer } from "./holidays.js";
|
package/dist/tt/utils/index.js
CHANGED
|
@@ -2,5 +2,4 @@ export { formatLocalDate, getMonday, getWeekdayName, isSameDay, isLocalDate, par
|
|
|
2
2
|
export { getAdjacentSemester, getCurrentPeriod, isSessionPeriod, } from "./period.js";
|
|
3
3
|
export { getSemesterStart, getSemesterWeeks, getWeekNumber, } from "./semester.js";
|
|
4
4
|
export { getStandardScheduleBlocks } from "./time-slots.js";
|
|
5
|
-
export { LessonType, parseLessonType } from "./lesson-type.js";
|
|
6
5
|
export { getCompensatingWorkDays, getEffectiveHolidays, getHolidayTransfers, isHoliday, RUSSIAN_HOLIDAYS, } from "./holidays.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type WebinarClientOptions, type WebinarEvent, type WebinarSession } from "./types.js";
|
|
2
|
+
/** Live participant state and explicit actions; never auto-connects media. */
|
|
3
|
+
export declare class WebinarClient {
|
|
4
|
+
private ddp;
|
|
5
|
+
private session;
|
|
6
|
+
private history;
|
|
7
|
+
private listeners;
|
|
8
|
+
private ready;
|
|
9
|
+
private started;
|
|
10
|
+
constructor(session: WebinarSession, opts?: WebinarClientOptions);
|
|
11
|
+
connect(): Promise<void>;
|
|
12
|
+
private assertConnected;
|
|
13
|
+
getSnapshot(): import("./types.js").WebinarSnapshot;
|
|
14
|
+
getUsers(): import("./types.js").WebinarUser[];
|
|
15
|
+
getPresenter(): import("./types.js").WebinarUser | null;
|
|
16
|
+
getModerators(): import("./types.js").WebinarUser[];
|
|
17
|
+
getChats(): import("./types.js").WebinarChat[];
|
|
18
|
+
getMessages(opts?: {
|
|
19
|
+
chatId?: string;
|
|
20
|
+
}): import("./types.js").WebinarMessage[];
|
|
21
|
+
getPresentations(): import("./types.js").WebinarPresentation[];
|
|
22
|
+
getCurrentPresentation(): import("./types.js").WebinarPresentation | null;
|
|
23
|
+
getMediaStreams(): import("./types.js").WebinarMediaStream[];
|
|
24
|
+
getNotes(): import("./types.js").WebinarNotes | null;
|
|
25
|
+
/** Reads historical pages; live messages arrive through events(). */
|
|
26
|
+
loadMessages(opts?: {
|
|
27
|
+
chatId?: string;
|
|
28
|
+
page?: number;
|
|
29
|
+
}): Promise<import("./types.js").WebinarMessage[]>;
|
|
30
|
+
subscribe(listener: (event: WebinarEvent) => void): () => void;
|
|
31
|
+
events(opts?: {
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
bufferSize?: number;
|
|
34
|
+
}): AsyncGenerator<WebinarEvent, any, any>;
|
|
35
|
+
private emit;
|
|
36
|
+
private assertPermission;
|
|
37
|
+
setRaisedHand(raised: boolean): Promise<void>;
|
|
38
|
+
sendMessage(opts: {
|
|
39
|
+
text: string;
|
|
40
|
+
chatId?: string;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
openPrivateChat(opts: {
|
|
43
|
+
userId: string;
|
|
44
|
+
}): Promise<import("./types.js").WebinarChat>;
|
|
45
|
+
sendPrivateMessage(opts: {
|
|
46
|
+
userId: string;
|
|
47
|
+
text: string;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
setMuted(muted: boolean): Promise<void>;
|
|
50
|
+
/** Closes local transport; does not issue userLeftMeeting or alter other users. */
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { AuthError } from "../common/types.js";
|
|
2
|
+
import { WebinarDdp } from "./ddp.js";
|
|
3
|
+
import { webinarEvents } from "./events.js";
|
|
4
|
+
import { record, string } from "./parse.js";
|
|
5
|
+
import { browserWebinarSocket } from "./socket.js";
|
|
6
|
+
import { buildWebinarSnapshot, normalizeWebinarMessage } from "./state.js";
|
|
7
|
+
import { WebinarPermissionError, WebinarProtocolError, } from "./types.js";
|
|
8
|
+
/** Live participant state and explicit actions; never auto-connects media. */
|
|
9
|
+
export class WebinarClient {
|
|
10
|
+
ddp;
|
|
11
|
+
session;
|
|
12
|
+
history = new Map();
|
|
13
|
+
listeners = new Set();
|
|
14
|
+
ready = false;
|
|
15
|
+
started = false;
|
|
16
|
+
constructor(session, opts = {}) {
|
|
17
|
+
if (session.protocol !== "ddp" || !/^2\.3(?:\.|$)/u.test(session.server.version)) {
|
|
18
|
+
throw new WebinarProtocolError("Unsupported webinar participant protocol");
|
|
19
|
+
}
|
|
20
|
+
this.session = structuredClone(session);
|
|
21
|
+
this.ddp = new WebinarDdp(opts.socketFactory ?? browserWebinarSocket, opts.timeout);
|
|
22
|
+
this.ddp.onChange((collection, id, removed) => {
|
|
23
|
+
this.emit({ type: "change", collection });
|
|
24
|
+
if (collection === "group-chat-msg" && !removed) {
|
|
25
|
+
const doc = this.ddp.documents(collection).find((message) => message._id === id);
|
|
26
|
+
if (doc)
|
|
27
|
+
this.emit({ type: "message", message: normalizeWebinarMessage(doc, [...this.ddp.documents("users"), ...this.ddp.documents("users-persistent-data")]) });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
this.ddp.onDisconnect(() => { this.ready = false; this.emit({ type: "disconnected" }); });
|
|
31
|
+
this.ddp.onError((error) => this.emit({ type: "error", error }));
|
|
32
|
+
}
|
|
33
|
+
async connect() {
|
|
34
|
+
if (this.started)
|
|
35
|
+
throw new WebinarProtocolError("Create a new client to reconnect");
|
|
36
|
+
this.started = true;
|
|
37
|
+
try {
|
|
38
|
+
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));
|
|
43
|
+
if (validation.validationStatus !== 3)
|
|
44
|
+
throw new AuthError("Webinar participant authentication rejected");
|
|
45
|
+
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",
|
|
48
|
+
].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]);
|
|
51
|
+
this.ready = true;
|
|
52
|
+
if (this.session.features.chat)
|
|
53
|
+
await this.loadMessages();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
this.close();
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
assertConnected() {
|
|
61
|
+
if (!this.ready)
|
|
62
|
+
throw new WebinarProtocolError("Webinar is disconnected");
|
|
63
|
+
}
|
|
64
|
+
getSnapshot() {
|
|
65
|
+
this.assertConnected();
|
|
66
|
+
return buildWebinarSnapshot(this.ddp, this.session, this.history);
|
|
67
|
+
}
|
|
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; }
|
|
72
|
+
getMessages(opts) {
|
|
73
|
+
const chatId = opts?.chatId ?? this.session.publicChatId;
|
|
74
|
+
return this.getSnapshot().messages.filter((message) => message.chatId === chatId);
|
|
75
|
+
}
|
|
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; }
|
|
80
|
+
/** Reads historical pages; live messages arrive through events(). */
|
|
81
|
+
async loadMessages(opts = {}) {
|
|
82
|
+
this.assertConnected();
|
|
83
|
+
const chatId = opts.chatId ?? this.session.publicChatId;
|
|
84
|
+
if (!this.getChats().some((chat) => chat.id === chatId))
|
|
85
|
+
throw new WebinarPermissionError("Chat is not accessible");
|
|
86
|
+
const page = opts.page ?? 1;
|
|
87
|
+
if (!Number.isInteger(page) || page < 1)
|
|
88
|
+
throw new RangeError("Chat page must be a positive integer");
|
|
89
|
+
const result = await this.ddp.call("fetchMessagePerPage", [chatId, page]);
|
|
90
|
+
if (!Array.isArray(result))
|
|
91
|
+
throw new WebinarProtocolError("Invalid webinar chat history");
|
|
92
|
+
const docs = result.map(record);
|
|
93
|
+
for (const doc of docs)
|
|
94
|
+
if (doc.chatId === chatId)
|
|
95
|
+
this.history.set(string(doc.id) || string(doc._id), doc);
|
|
96
|
+
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")]));
|
|
98
|
+
}
|
|
99
|
+
subscribe(listener) {
|
|
100
|
+
this.listeners.add(listener);
|
|
101
|
+
return () => { this.listeners.delete(listener); };
|
|
102
|
+
}
|
|
103
|
+
events(opts) {
|
|
104
|
+
return webinarEvents((listener) => this.subscribe(listener), opts);
|
|
105
|
+
}
|
|
106
|
+
emit(event) {
|
|
107
|
+
for (const listener of this.listeners) {
|
|
108
|
+
// A UI listener must not corrupt or disconnect the network transport.
|
|
109
|
+
try {
|
|
110
|
+
listener(event);
|
|
111
|
+
}
|
|
112
|
+
catch { /* Listener errors belong to the caller. */ }
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
assertPermission(feature, lock) {
|
|
116
|
+
this.assertConnected();
|
|
117
|
+
if (!this.session.features[feature])
|
|
118
|
+
throw new WebinarPermissionError(`Webinar feature disabled: ${feature}`);
|
|
119
|
+
const user = this.getUsers().find((user) => user.id === this.session.user.id);
|
|
120
|
+
const meeting = this.ddp.documents("meetings")[0];
|
|
121
|
+
if (lock && user?.locked && !user.moderator && record(meeting?.lockSettingsProps)[lock] === true) {
|
|
122
|
+
throw new WebinarPermissionError(`Webinar permission locked: ${feature}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async setRaisedHand(raised) {
|
|
126
|
+
if (typeof raised !== "boolean")
|
|
127
|
+
throw new TypeError("Raised hand must be boolean");
|
|
128
|
+
this.assertPermission("raiseHand");
|
|
129
|
+
await this.ddp.call("setEmojiStatus", [this.session.user.id, raised ? "raiseHand" : "none"]);
|
|
130
|
+
}
|
|
131
|
+
async sendMessage(opts) {
|
|
132
|
+
const chatId = opts.chatId ?? this.session.publicChatId;
|
|
133
|
+
const chat = this.getChats().find((chat) => chat.id === chatId);
|
|
134
|
+
if (!chat)
|
|
135
|
+
throw new WebinarPermissionError("Chat is not accessible");
|
|
136
|
+
this.assertPermission("chat", chat.private ? "disablePrivateChat" : "disablePublicChat");
|
|
137
|
+
const text = opts.text.trim();
|
|
138
|
+
if (!text || text.length > this.session.maxMessageLength)
|
|
139
|
+
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",
|
|
142
|
+
correlationId: `${this.session.user.id}-${Date.now()}`,
|
|
143
|
+
sender: { id: this.session.user.id, name: this.session.user.name }, message: text,
|
|
144
|
+
}]);
|
|
145
|
+
}
|
|
146
|
+
async openPrivateChat(opts) {
|
|
147
|
+
this.assertPermission("chat", "disablePrivateChat");
|
|
148
|
+
if (opts.userId === this.session.user.id)
|
|
149
|
+
throw new RangeError("Invalid private chat recipient");
|
|
150
|
+
const existing = this.getChats().find((chat) => chat.private && chat.userIds.includes(opts.userId));
|
|
151
|
+
if (existing)
|
|
152
|
+
return existing;
|
|
153
|
+
const user = this.getUsers().find((user) => user.id === opts.userId);
|
|
154
|
+
if (!user)
|
|
155
|
+
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));
|
|
159
|
+
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)]);
|
|
161
|
+
return chat;
|
|
162
|
+
}
|
|
163
|
+
async sendPrivateMessage(opts) {
|
|
164
|
+
if (!opts.text.trim() || opts.text.trim().length > this.session.maxMessageLength)
|
|
165
|
+
throw new RangeError("Invalid webinar message length");
|
|
166
|
+
const chat = await this.openPrivateChat(opts);
|
|
167
|
+
await this.sendMessage({ chatId: chat.id, text: opts.text });
|
|
168
|
+
}
|
|
169
|
+
async setMuted(muted) {
|
|
170
|
+
if (typeof muted !== "boolean")
|
|
171
|
+
throw new TypeError("Muted state must be boolean");
|
|
172
|
+
this.assertConnected();
|
|
173
|
+
const user = this.getUsers().find((user) => user.id === this.session.user.id);
|
|
174
|
+
if (!user?.audio.joined || user.audio.listenOnly)
|
|
175
|
+
throw new WebinarPermissionError("Microphone audio is not connected");
|
|
176
|
+
await this.ddp.call("muteToggle", [this.session.user.id, muted]);
|
|
177
|
+
}
|
|
178
|
+
/** Closes local transport; does not issue userLeftMeeting or alter other users. */
|
|
179
|
+
close() {
|
|
180
|
+
this.ready = false;
|
|
181
|
+
this.ddp.close();
|
|
182
|
+
this.history.clear();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type WebinarSocketFactory } from "./types.js";
|
|
2
|
+
export type WebinarDocument = Record<string, unknown>;
|
|
3
|
+
/** DDP transport: no Meteor runtime and no profile/settings writes. */
|
|
4
|
+
export declare class WebinarDdp {
|
|
5
|
+
private factory;
|
|
6
|
+
private timeout;
|
|
7
|
+
private socket;
|
|
8
|
+
private sequence;
|
|
9
|
+
private pending;
|
|
10
|
+
private collections;
|
|
11
|
+
private listeners;
|
|
12
|
+
private disconnectListeners;
|
|
13
|
+
private errorListeners;
|
|
14
|
+
private subscriptions;
|
|
15
|
+
private connected;
|
|
16
|
+
constructor(factory: WebinarSocketFactory, timeout?: number);
|
|
17
|
+
onChange(listener: (collection: string, id: string, removed: boolean) => void): () => void;
|
|
18
|
+
onDisconnect(listener: () => void): () => void;
|
|
19
|
+
onError(listener: (error: Error) => void): () => void;
|
|
20
|
+
documents(collection: string): WebinarDocument[];
|
|
21
|
+
connect(url: string): Promise<void>;
|
|
22
|
+
private wait;
|
|
23
|
+
private settle;
|
|
24
|
+
private send;
|
|
25
|
+
call(method: string, params?: unknown[]): Promise<unknown>;
|
|
26
|
+
subscribe(name: string, params?: unknown[]): Promise<void>;
|
|
27
|
+
waitFor(collection: string, predicate: (doc: WebinarDocument) => boolean): Promise<WebinarDocument>;
|
|
28
|
+
private receive;
|
|
29
|
+
private disconnected;
|
|
30
|
+
close(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { openWebinarSocket } from "./socket.js";
|
|
2
|
+
import { WebinarProtocolError } from "./types.js";
|
|
3
|
+
/** DDP transport: no Meteor runtime and no profile/settings writes. */
|
|
4
|
+
export class WebinarDdp {
|
|
5
|
+
factory;
|
|
6
|
+
timeout;
|
|
7
|
+
socket = null;
|
|
8
|
+
sequence = 0;
|
|
9
|
+
pending = new Map();
|
|
10
|
+
collections = new Map();
|
|
11
|
+
listeners = new Set();
|
|
12
|
+
disconnectListeners = new Set();
|
|
13
|
+
errorListeners = new Set();
|
|
14
|
+
subscriptions = new Map();
|
|
15
|
+
connected = false;
|
|
16
|
+
constructor(factory, timeout = 15_000) {
|
|
17
|
+
this.factory = factory;
|
|
18
|
+
this.timeout = timeout;
|
|
19
|
+
if (!Number.isFinite(timeout) || timeout <= 0)
|
|
20
|
+
throw new RangeError("Invalid webinar timeout");
|
|
21
|
+
}
|
|
22
|
+
onChange(listener) {
|
|
23
|
+
this.listeners.add(listener);
|
|
24
|
+
return () => { this.listeners.delete(listener); };
|
|
25
|
+
}
|
|
26
|
+
onDisconnect(listener) {
|
|
27
|
+
this.disconnectListeners.add(listener);
|
|
28
|
+
return () => { this.disconnectListeners.delete(listener); };
|
|
29
|
+
}
|
|
30
|
+
onError(listener) {
|
|
31
|
+
this.errorListeners.add(listener);
|
|
32
|
+
return () => { this.errorListeners.delete(listener); };
|
|
33
|
+
}
|
|
34
|
+
documents(collection) {
|
|
35
|
+
return structuredClone([...this.collections.get(collection)?.values() ?? []]);
|
|
36
|
+
}
|
|
37
|
+
async connect(url) {
|
|
38
|
+
if (this.socket)
|
|
39
|
+
throw new WebinarProtocolError("Webinar transport already opened");
|
|
40
|
+
const socket = this.factory(url);
|
|
41
|
+
this.socket = socket;
|
|
42
|
+
socket.addEventListener("message", (event) => {
|
|
43
|
+
try {
|
|
44
|
+
if (typeof event.data !== "string")
|
|
45
|
+
throw new WebinarProtocolError("Invalid DDP frame");
|
|
46
|
+
this.receive(JSON.parse(event.data));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
const error = new WebinarProtocolError("Invalid webinar DDP response");
|
|
50
|
+
for (const listener of this.errorListeners)
|
|
51
|
+
listener(error);
|
|
52
|
+
this.close();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
socket.addEventListener("close", () => this.disconnected());
|
|
56
|
+
socket.addEventListener("error", () => this.close());
|
|
57
|
+
await openWebinarSocket(socket, this.timeout);
|
|
58
|
+
const ready = this.wait("connect");
|
|
59
|
+
this.send({ msg: "connect", version: "1", support: ["1"] });
|
|
60
|
+
await ready;
|
|
61
|
+
this.connected = true;
|
|
62
|
+
}
|
|
63
|
+
wait(id) {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
const timer = setTimeout(() => {
|
|
66
|
+
this.pending.delete(id);
|
|
67
|
+
reject(new WebinarProtocolError("Webinar request timed out"));
|
|
68
|
+
}, this.timeout);
|
|
69
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
settle(id, value, error) {
|
|
73
|
+
const request = this.pending.get(id);
|
|
74
|
+
if (!request)
|
|
75
|
+
return;
|
|
76
|
+
clearTimeout(request.timer);
|
|
77
|
+
this.pending.delete(id);
|
|
78
|
+
if (error)
|
|
79
|
+
request.reject(error);
|
|
80
|
+
else
|
|
81
|
+
request.resolve(value);
|
|
82
|
+
}
|
|
83
|
+
send(message) {
|
|
84
|
+
if (this.socket?.readyState !== 1)
|
|
85
|
+
throw new WebinarProtocolError("Webinar is disconnected");
|
|
86
|
+
this.socket.send(JSON.stringify(message));
|
|
87
|
+
}
|
|
88
|
+
async call(method, params = []) {
|
|
89
|
+
if (!this.connected)
|
|
90
|
+
throw new WebinarProtocolError("Webinar is disconnected");
|
|
91
|
+
const id = `method:${++this.sequence}`;
|
|
92
|
+
const result = this.wait(id);
|
|
93
|
+
this.send({ msg: "method", id, method, params });
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
async subscribe(name, params = []) {
|
|
97
|
+
if (!this.connected)
|
|
98
|
+
throw new WebinarProtocolError("Webinar is disconnected");
|
|
99
|
+
const key = JSON.stringify([name, params]);
|
|
100
|
+
const existing = this.subscriptions.get(key);
|
|
101
|
+
if (existing)
|
|
102
|
+
return existing;
|
|
103
|
+
const id = `sub:${++this.sequence}`;
|
|
104
|
+
const ready = this.wait(id);
|
|
105
|
+
const subscription = ready.then(() => undefined).catch((error) => {
|
|
106
|
+
this.subscriptions.delete(key);
|
|
107
|
+
throw error;
|
|
108
|
+
});
|
|
109
|
+
this.subscriptions.set(key, subscription);
|
|
110
|
+
this.send({ msg: "sub", id, name, params });
|
|
111
|
+
return subscription;
|
|
112
|
+
}
|
|
113
|
+
async waitFor(collection, predicate) {
|
|
114
|
+
const existing = this.documents(collection).find(predicate);
|
|
115
|
+
if (existing)
|
|
116
|
+
return existing;
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
const timer = setTimeout(() => {
|
|
119
|
+
unsubscribe();
|
|
120
|
+
disconnected();
|
|
121
|
+
reject(new WebinarProtocolError("Webinar state timed out"));
|
|
122
|
+
}, this.timeout);
|
|
123
|
+
const finish = () => { clearTimeout(timer); unsubscribe(); disconnected(); };
|
|
124
|
+
const unsubscribe = this.onChange((changed) => {
|
|
125
|
+
if (changed !== collection)
|
|
126
|
+
return;
|
|
127
|
+
const doc = this.documents(collection).find(predicate);
|
|
128
|
+
if (doc) {
|
|
129
|
+
finish();
|
|
130
|
+
resolve(doc);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const disconnected = this.onDisconnect(() => {
|
|
134
|
+
finish();
|
|
135
|
+
reject(new WebinarProtocolError("Webinar is disconnected"));
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
receive(data) {
|
|
140
|
+
if (!data || typeof data !== "object")
|
|
141
|
+
throw new WebinarProtocolError("Invalid DDP message");
|
|
142
|
+
switch (data.msg) {
|
|
143
|
+
case "connected":
|
|
144
|
+
this.settle("connect", undefined);
|
|
145
|
+
break;
|
|
146
|
+
case "failed":
|
|
147
|
+
this.settle("connect", undefined, new WebinarProtocolError("DDP version rejected"));
|
|
148
|
+
break;
|
|
149
|
+
case "ping":
|
|
150
|
+
this.send({ msg: "pong", ...(data.id === undefined ? {} : { id: data.id }) });
|
|
151
|
+
break;
|
|
152
|
+
case "ready":
|
|
153
|
+
if (Array.isArray(data.subs))
|
|
154
|
+
for (const id of data.subs)
|
|
155
|
+
this.settle(String(id), undefined);
|
|
156
|
+
break;
|
|
157
|
+
case "nosub":
|
|
158
|
+
case "result":
|
|
159
|
+
this.settle(String(data.id), data.result, data.error
|
|
160
|
+
? new WebinarProtocolError(`Webinar ${data.msg === "nosub" ? "subscription" : "method"} rejected`)
|
|
161
|
+
: undefined);
|
|
162
|
+
break;
|
|
163
|
+
case "added":
|
|
164
|
+
case "changed":
|
|
165
|
+
case "removed": {
|
|
166
|
+
if (typeof data.collection !== "string" || typeof data.id !== "string")
|
|
167
|
+
return;
|
|
168
|
+
let collection = this.collections.get(data.collection);
|
|
169
|
+
if (!collection) {
|
|
170
|
+
collection = new Map();
|
|
171
|
+
this.collections.set(data.collection, collection);
|
|
172
|
+
}
|
|
173
|
+
if (data.msg === "removed")
|
|
174
|
+
collection.delete(data.id);
|
|
175
|
+
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 };
|
|
179
|
+
if (Array.isArray(data.cleared))
|
|
180
|
+
for (const field of data.cleared)
|
|
181
|
+
if (field !== "_id")
|
|
182
|
+
delete doc[String(field)];
|
|
183
|
+
collection.set(data.id, doc);
|
|
184
|
+
}
|
|
185
|
+
for (const listener of this.listeners)
|
|
186
|
+
listener(data.collection, data.id, data.msg === "removed");
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
disconnected() {
|
|
192
|
+
if (!this.socket)
|
|
193
|
+
return;
|
|
194
|
+
this.connected = false;
|
|
195
|
+
this.socket = null;
|
|
196
|
+
for (const [id] of this.pending)
|
|
197
|
+
this.settle(id, undefined, new WebinarProtocolError("Webinar is disconnected"));
|
|
198
|
+
for (const listener of this.disconnectListeners)
|
|
199
|
+
listener();
|
|
200
|
+
}
|
|
201
|
+
close() {
|
|
202
|
+
const socket = this.socket;
|
|
203
|
+
this.disconnected();
|
|
204
|
+
socket?.close();
|
|
205
|
+
this.collections.clear();
|
|
206
|
+
this.subscriptions.clear();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { WebinarEvent } from "./types.js";
|
|
2
|
+
/** Bounded stream: slow consumers get an error rather than missing changes silently. */
|
|
3
|
+
export declare function webinarEvents(subscribe: (listener: (event: WebinarEvent) => void) => () => void, opts?: {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
bufferSize?: number;
|
|
6
|
+
}): AsyncGenerator<WebinarEvent>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Bounded stream: slow consumers get an error rather than missing changes silently. */
|
|
2
|
+
export async function* webinarEvents(subscribe, opts = {}) {
|
|
3
|
+
const limit = opts.bufferSize ?? 512;
|
|
4
|
+
if (!Number.isInteger(limit) || limit < 1)
|
|
5
|
+
throw new RangeError("Invalid webinar event buffer size");
|
|
6
|
+
const queue = [];
|
|
7
|
+
let wake;
|
|
8
|
+
let done = opts.signal?.aborted ?? false;
|
|
9
|
+
let overflow = false;
|
|
10
|
+
const unsubscribe = subscribe((event) => {
|
|
11
|
+
if (queue.length >= limit) {
|
|
12
|
+
overflow = true;
|
|
13
|
+
done = true;
|
|
14
|
+
}
|
|
15
|
+
else
|
|
16
|
+
queue.push(event);
|
|
17
|
+
if (event.type === "disconnected")
|
|
18
|
+
done = true;
|
|
19
|
+
wake?.();
|
|
20
|
+
});
|
|
21
|
+
const abort = () => { done = true; wake?.(); };
|
|
22
|
+
opts.signal?.addEventListener("abort", abort, { once: true });
|
|
23
|
+
try {
|
|
24
|
+
while (queue.length || !done) {
|
|
25
|
+
if (overflow)
|
|
26
|
+
throw new Error("Webinar event buffer overflow; refresh the snapshot");
|
|
27
|
+
const event = queue.shift();
|
|
28
|
+
if (event)
|
|
29
|
+
yield event;
|
|
30
|
+
else
|
|
31
|
+
await new Promise((resolve) => { wake = resolve; });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
unsubscribe();
|
|
36
|
+
opts.signal?.removeEventListener("abort", abort);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type WebinarSession, type WebinarSlide } from "./types.js";
|
|
2
|
+
import { WebinarClient } from "./client.js";
|
|
3
|
+
/** Backend-only LK/BBB bootstrap and same-server presentation HTTP access. */
|
|
4
|
+
export declare class WebinarGateway {
|
|
5
|
+
private http;
|
|
6
|
+
private session;
|
|
7
|
+
private client;
|
|
8
|
+
getSession(): WebinarSession;
|
|
9
|
+
openSession(opts: {
|
|
10
|
+
joinUrl: string;
|
|
11
|
+
}): Promise<WebinarSession>;
|
|
12
|
+
/** Opens state only. Browser media is connected separately by WebinarMediaClient. */
|
|
13
|
+
connect(): Promise<WebinarClient>;
|
|
14
|
+
/** Downloads only when the live participant state exposes this permission. */
|
|
15
|
+
downloadPresentation(opts: {
|
|
16
|
+
presentationId: string;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
body: Buffer;
|
|
19
|
+
contentType: string;
|
|
20
|
+
filename: string;
|
|
21
|
+
}>;
|
|
22
|
+
downloadSlide(opts: {
|
|
23
|
+
slide: WebinarSlide;
|
|
24
|
+
format?: "svg" | "thumbnail" | "text";
|
|
25
|
+
}): Promise<{
|
|
26
|
+
body: Buffer;
|
|
27
|
+
contentType: string;
|
|
28
|
+
filename: string;
|
|
29
|
+
}>;
|
|
30
|
+
}
|