@netless/fastboard-core 0.3.12 → 0.3.13-canary.1

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/dist/lite.d.ts ADDED
@@ -0,0 +1,480 @@
1
+ import { Size, SceneDefinition, ConvertedFile, RoomPhase as RoomPhase$1, ApplianceNames, ShapeType, MemberState, RoomState, CameraState, Camera, AnimationMode, Rectangle, Color, ConversionResponse, WhiteWebSdkConfiguration, JoinRoomParams, RoomCallbacks, WhiteWebSdk, Room, HotKeys, PlayerPhase as PlayerPhase$1, PlayerState, PlayerSeekingResult, ReplayRoomParams, PlayerCallbacks, Player, ViewCallbacks, View } from 'white-web-sdk';
2
+ export { AnimationMode, ApplianceNames, Camera, CameraState, Color, ConversionResponse, HotKey, HotKeys, JoinRoomParams, MemberState, PlayerSeekingResult, Rectangle, Room, RoomCallbacks, RoomState, SceneDefinition, ShapeType, ViewCallbacks, WhiteWebSdk, WhiteWebSdkConfiguration } from 'white-web-sdk';
3
+ import { AddPageParams, MountParams, NetlessApp, WindowManager, RegisterParams, PublicEvent } from '@netless/window-manager';
4
+ export { AddPageParams, MountParams, NetlessApp, PublicEvent, WindowManager } from '@netless/window-manager';
5
+ import { SyncedStore } from '@netless/synced-store';
6
+ export { Diff, DiffOne, Storage, SyncedStore } from '@netless/synced-store';
7
+
8
+ type Subscriber<T> = (value: T) => void;
9
+ type Unsubscriber = () => void;
10
+ type Updater<T> = (value: T) => T;
11
+ type StartStopNotifier<T> = (set: Subscriber<T>) => Unsubscriber | void;
12
+ interface Readable<T> {
13
+ readonly value: T;
14
+ subscribe(this: void, run: Subscriber<T>): Unsubscriber;
15
+ reaction(this: void, run: Subscriber<T>): Unsubscriber;
16
+ }
17
+ interface Writable<T> extends Readable<T> {
18
+ set(this: void, value: T): void;
19
+ update(this: void, updater: Updater<T>): void;
20
+ }
21
+ declare function readable<T>(value: T, start?: StartStopNotifier<T>): Readable<T>;
22
+ declare function writable<T>(value: T, start: StartStopNotifier<T> | undefined, set: Subscriber<T>): Writable<T>;
23
+
24
+ declare function getImageSize(url: string, fallback: Size, crossOrigin?: boolean | string): Promise<Size>;
25
+ declare function makeSlideParams(scenes: SceneDefinition[]): {
26
+ scenes: SceneDefinition[];
27
+ taskId: string;
28
+ url: string;
29
+ };
30
+ declare function convertedFileToScene(f: ConvertedFile, i: number): SceneDefinition;
31
+
32
+ declare function genUID(): string;
33
+
34
+ declare const warnings: {
35
+ readonly "no-ppt-in-scenes": "You're probably inserting the slide app in a wrong way, there shouldn't exist `scenes[0].ppt`.";
36
+ };
37
+ declare function warn(id: keyof typeof warnings): void;
38
+
39
+ declare class FastboardAppBase<TEventData extends Record<string, any> = any> {
40
+ readonly sdk: WhiteWebSdk;
41
+ readonly room: Room;
42
+ readonly manager: WindowManager;
43
+ readonly hotKeys: Partial<HotKeys>;
44
+ readonly syncedStore: SyncedStore<TEventData>;
45
+ constructor(sdk: WhiteWebSdk, room: Room, manager: WindowManager, hotKeys: Partial<HotKeys>, syncedStore: SyncedStore<TEventData>);
46
+ protected _destroyed: boolean;
47
+ /**
48
+ * Destroy fastboard (disconnect from the whiteboard room).
49
+ */
50
+ destroy(): Promise<void>;
51
+ }
52
+ type RoomPhase = `${RoomPhase$1}`;
53
+
54
+ /** pencil, eraser, rectangle... */
55
+ type Appliance = `${ApplianceNames}`;
56
+ /** triangle, star... */
57
+ type Shape = `${ShapeType}`;
58
+ /** Params for static docs, they are rendered as many images. */
59
+ interface InsertDocsStatic {
60
+ readonly fileType: "pdf";
61
+ /** Unique string for binding whiteboard view to the doc. Must start with `/`. */
62
+ readonly scenePath: string;
63
+ /** @example [{ name: '1', ppt: { src: 'url/to/ppt/1.png' } }] */
64
+ readonly scenes: SceneDefinition[];
65
+ /** Window title. */
66
+ readonly title?: string;
67
+ }
68
+ /** Params for slides, they are rendered in @netless/app-slide with animations. */
69
+ interface InsertDocsDynamic {
70
+ readonly fileType: "pptx";
71
+ /** Unique string for binding whiteboard view to the doc. Must start with `/`. */
72
+ readonly scenePath: string;
73
+ /** Conversion task id, see https://developer.netless.link/server-en/home/server-conversion#get-query-task-conversion-progress. */
74
+ readonly taskId: string;
75
+ /** Window title. */
76
+ readonly title?: string;
77
+ /** Where the slide resource placed. @default `https://convertcdn.netless.link/dynamicConvert` */
78
+ readonly url?: string;
79
+ /** @example [{ name: '1' }, { name: '2' }, { name: '3' }] */
80
+ readonly scenes?: SceneDefinition[];
81
+ }
82
+ type InsertDocsParams = InsertDocsStatic | InsertDocsDynamic;
83
+ interface ProjectorResponse {
84
+ uuid: string;
85
+ status: "Waiting" | "Converting" | "Finished" | "Fail";
86
+ type: "dynamic" | "static";
87
+ /** 0..100 */
88
+ convertedPercentage: number;
89
+ /** https://example.org/path/to/dynamicConvert, only when type=dynamic */
90
+ prefix?: string;
91
+ pageCount?: number;
92
+ /** {1:"{prefix}/{taskId}/preview/1.png"}, only when type=dynamic and preview=true */
93
+ previews?: Record<number, string>;
94
+ /** {prefix}/{taskId}/jsonOutput/note.json */
95
+ note?: string;
96
+ /** {1:{width,height,url}}, only when type=static */
97
+ images?: Record<number, {
98
+ width: number;
99
+ height: number;
100
+ url: string;
101
+ }>;
102
+ /** 20xxxxx */
103
+ errorCode?: string;
104
+ errorMessage?: string;
105
+ }
106
+ type SetMemberStateFn = (partialMemberState: Partial<MemberState>) => void;
107
+ type RoomStateChanged = (diff: Partial<RoomState>) => void;
108
+ /** App download progress. */
109
+ interface AppsStatus {
110
+ [kind: string]: {
111
+ status: "idle" | "loading" | "failed";
112
+ /** Exist if status is `failed`. */
113
+ reason?: string;
114
+ };
115
+ }
116
+ declare class FastboardApp<TEventData extends Record<string, any> = any> extends FastboardAppBase<TEventData> {
117
+ /**
118
+ * Render this app to some DOM.
119
+ */
120
+ bindContainer(container: HTMLElement): void;
121
+ /**
122
+ * Move window-manager's collector to some place.
123
+ */
124
+ bindCollector(container: HTMLElement): void;
125
+ /**
126
+ * Is current room writable?
127
+ */
128
+ readonly writable: Writable<boolean>;
129
+ /**
130
+ * Is current room online?
131
+ */
132
+ readonly phase: Readable<"connecting" | "connected" | "reconnecting" | "disconnecting" | "disconnected">;
133
+ /**
134
+ * Current window-manager's windows' state (is it maximized?).
135
+ */
136
+ readonly boxState: Readable<"normal" | "minimized" | "maximized" | undefined>;
137
+ /**
138
+ * Current window-manager's focused app's id.
139
+ * @example "HelloWorld-1A2b3C4d"
140
+ */
141
+ readonly focusedApp: Readable<string | undefined>;
142
+ /**
143
+ * How many times can I call `app.redo()`?
144
+ */
145
+ readonly canRedoSteps: Readable<number>;
146
+ /**
147
+ * How many times can I call `app.undo()`?
148
+ */
149
+ readonly canUndoSteps: Readable<number>;
150
+ /**
151
+ * Current camera information of main view.
152
+ *
153
+ * Change the camera position by `app.moveCamera()`.
154
+ */
155
+ readonly camera: Readable<CameraState>;
156
+ /**
157
+ * Current tool's info, like "is using pencil?", "what color?".
158
+ *
159
+ * Change the tool by `app.setAppliance()`.
160
+ */
161
+ readonly memberState: Readable<MemberState>;
162
+ /**
163
+ * 0..n-1, current index of main view scenes.
164
+ */
165
+ readonly sceneIndex: Writable<number>;
166
+ /**
167
+ * How many pages are in the main view?
168
+ */
169
+ readonly sceneLength: Readable<number>;
170
+ /**
171
+ * Apps status.
172
+ */
173
+ readonly appsStatus: Readable<AppsStatus>;
174
+ /**
175
+ * Undo a step on main view.
176
+ */
177
+ undo(): void;
178
+ /**
179
+ * Redo a step on main view.
180
+ */
181
+ redo(): void;
182
+ /**
183
+ * Move current main view's camera position.
184
+ */
185
+ moveCamera(camera: Partial<Camera> & {
186
+ animationMode?: AnimationMode | undefined;
187
+ }): void;
188
+ /**
189
+ * Move current main view's camera to include a rectangle.
190
+ */
191
+ moveCameraToContain(rectangle: Rectangle & {
192
+ animationMode?: AnimationMode;
193
+ }): void;
194
+ /**
195
+ * Delete all things on the main view.
196
+ */
197
+ cleanCurrentScene(): void;
198
+ /**
199
+ * Set current tool, like "pencil".
200
+ */
201
+ setAppliance(appliance: ApplianceNames | Appliance, shape?: ShapeType | Shape): void;
202
+ /**
203
+ * Set pencil and shape's thickness.
204
+ */
205
+ setStrokeWidth(strokeWidth: number): void;
206
+ /**
207
+ * Set pencil and shape's color.
208
+ */
209
+ setStrokeColor(strokeColor: Color): void;
210
+ /**
211
+ * Set text size. Default is 16.
212
+ */
213
+ setTextSize(textSize: number): void;
214
+ /**
215
+ * Set text color.
216
+ *
217
+ * @example
218
+ * setTextColor([0x66, 0xcc, 0xff])
219
+ */
220
+ setTextColor(textColor: Color): void;
221
+ /**
222
+ * Toggle dotted line effect on pencil.
223
+ */
224
+ toggleDottedLine(force?: boolean): void;
225
+ /**
226
+ * Set pencil eraser size.
227
+ */
228
+ setPencilEraserSize(size: number): void;
229
+ /**
230
+ * Goto previous page (the main whiteboard view).
231
+ */
232
+ prevPage(): Promise<boolean>;
233
+ /**
234
+ * Goto next page (the main whiteboard view).
235
+ */
236
+ nextPage(): Promise<boolean>;
237
+ /**
238
+ * Goto any page (index range: 0..n-1)
239
+ */
240
+ jumpPage(index: number): Promise<boolean>;
241
+ /**
242
+ * Add one page to the main whiteboard view.
243
+ *
244
+ * @example
245
+ * addPage({ after: true }) // add one page right after current one.
246
+ * nextPage() // then, goto that page.
247
+ */
248
+ addPage(params?: AddPageParams): Promise<void>;
249
+ /**
250
+ * Remove one page at given index or current page (by default).
251
+ *
252
+ * Requires `@netless/window-manager` >= 0.4.30.
253
+ *
254
+ * @example
255
+ * removePage() // remove current page
256
+ */
257
+ removePage(index?: number): Promise<boolean>;
258
+ /**
259
+ * Insert an image to the main view.
260
+ *
261
+ * @param crossOrigin Whether to load the image with CORS enabled, default is `true`.
262
+ *
263
+ * @example
264
+ * insertImage("https://i.imgur.com/CzXTtJV.jpg")
265
+ */
266
+ insertImage(url: string, crossOrigin?: boolean | string): Promise<void>;
267
+ /**
268
+ * Insert PDF/PPTX from conversion result.
269
+ * @param status https://developer.netless.link/server-en/home/server-conversion#get-query-task-conversion-progress
270
+ */
271
+ insertDocs(filename: string, status: ConversionResponse): Promise<string | undefined>;
272
+ /**
273
+ * Insert PDF/PPTX from projector conversion result.
274
+ * @param response https://developer.netless.link/server-zh/home/server-projector#get-%E6%9F%A5%E8%AF%A2%E4%BB%BB%E5%8A%A1%E8%BD%AC%E6%8D%A2%E8%BF%9B%E5%BA%A6
275
+ */
276
+ insertDocs(filename: string, response: ProjectorResponse): Promise<string | undefined>;
277
+ /**
278
+ * Manual way.
279
+ * @example
280
+ * app.insertDocs({
281
+ * fileType: 'pptx',
282
+ * scenePath: `/pptx/${conversion.taskId}`,
283
+ * taskId: conversion.taskId,
284
+ * title: 'Title',
285
+ * })
286
+ */
287
+ insertDocs(params: InsertDocsParams): Promise<string | undefined>;
288
+ /**
289
+ * Insert the Media Player app.
290
+ */
291
+ insertMedia(title: string, src: string): Promise<string | undefined>;
292
+ /**
293
+ * Insert the Monaco Code Editor app.
294
+ * @deprecated Use `app.manager.addApp({ kind: 'Monaco' })` instead.
295
+ */
296
+ insertCodeEditor(): Promise<string | undefined>;
297
+ /**
298
+ * Insert the Countdown app.
299
+ * @deprecated Use `app.manager.addApp({ kind: 'Countdown' })` instead.
300
+ */
301
+ insertCountdown(): Promise<string | undefined>;
302
+ /**
303
+ * Insert the GeoGebra app.
304
+ * @deprecated Use `app.manager.addApp({ kind: 'GeoGebra' })` instead.
305
+ */
306
+ insertGeoGebra(): Promise<string | undefined>;
307
+ }
308
+ interface FastboardOptions {
309
+ sdkConfig: Omit<WhiteWebSdkConfiguration, "useMobXState"> & {
310
+ region: NonNullable<WhiteWebSdkConfiguration["region"]>;
311
+ };
312
+ joinRoom: Omit<JoinRoomParams, "useMultiViews" | "disableNewPencil" | "disableMagixEventDispatchLimit"> & {
313
+ callbacks?: Partial<Omit<RoomCallbacks, "onCanRedoStepsUpdate" | "onCanUndoStepsUpdate">>;
314
+ };
315
+ managerConfig?: Omit<MountParams, "room">;
316
+ netlessApps?: NetlessApp[];
317
+ }
318
+ /**
319
+ * Create a FastboardApp instance.
320
+ * @example
321
+ * let app = await createFastboard({
322
+ * sdkConfig: {
323
+ * appIdentifier: import.meta.env.VITE_APPID,
324
+ * region: 'cn-hz',
325
+ * },
326
+ * joinRoom: {
327
+ * uid: unique_id,
328
+ * uuid: import.meta.env.VITE_ROOM_UUID,
329
+ * roomToken: import.meta.env.VITE_ROOM_TOKEN,
330
+ * },
331
+ * })
332
+ */
333
+ declare function createFastboard<TEventData extends Record<string, any> = any>({ sdkConfig, joinRoom: { callbacks, ...joinRoomParams }, managerConfig, netlessApps, }: FastboardOptions): Promise<FastboardApp<TEventData>>;
334
+
335
+ declare class FastboardPlayerBase<TEventData extends Record<string, any> = any> {
336
+ readonly sdk: WhiteWebSdk;
337
+ readonly player: Player;
338
+ readonly manager: WindowManager;
339
+ readonly syncedStore: SyncedStore<TEventData>;
340
+ constructor(sdk: WhiteWebSdk, player: Player, manager: WindowManager, syncedStore: SyncedStore<TEventData>);
341
+ protected _destroyed: boolean;
342
+ destroy(): void;
343
+ }
344
+ type PlayerPhase = `${PlayerPhase$1}`;
345
+
346
+ declare class FastboardPlayer<TEventData extends Record<string, any> = any> extends FastboardPlayerBase<TEventData> {
347
+ /**
348
+ * Render this player to some DOM.
349
+ */
350
+ bindContainer(container: HTMLElement): void;
351
+ /**
352
+ * Move window-manager's collector to some place.
353
+ */
354
+ bindCollector(container: HTMLElement): void;
355
+ /**
356
+ * Player current time in milliseconds.
357
+ */
358
+ readonly currentTime: Writable<number>;
359
+ /**
360
+ * Player state, like "is it playing?".
361
+ */
362
+ readonly phase: Readable<"waitingFirstFrame" | "playing" | "pause" | "stop" | "ended" | "buffering">;
363
+ /**
364
+ * Will become true after buffering.
365
+ */
366
+ readonly canplay: Readable<boolean>;
367
+ /**
368
+ * Playback speed, default `1`.
369
+ */
370
+ readonly playbackRate: Writable<number>;
371
+ /**
372
+ * Playback duration in milliseconds.
373
+ */
374
+ readonly duration: Readable<number>;
375
+ /**
376
+ * Get state of room at that time, like "who was in the room?".
377
+ */
378
+ readonly state: Readable<PlayerState>;
379
+ /**
380
+ * Seek to some time in milliseconds.
381
+ */
382
+ seek(timestamp: number): Promise<PlayerSeekingResult>;
383
+ /**
384
+ * Change player state to playing.
385
+ */
386
+ play(): void;
387
+ /**
388
+ * Change player state to paused.
389
+ */
390
+ pause(): void;
391
+ /**
392
+ * Change player state to stopped.
393
+ */
394
+ stop(): void;
395
+ /**
396
+ * Set playback speed, a shortcut for `speed.set(x)`.
397
+ */
398
+ setPlaybackRate(value: number): void;
399
+ }
400
+ interface FastboardReplayOptions {
401
+ sdkConfig: Omit<WhiteWebSdkConfiguration, "useMobXState"> & {
402
+ region: NonNullable<WhiteWebSdkConfiguration["region"]>;
403
+ };
404
+ replayRoom: Omit<ReplayRoomParams, "useMultiViews"> & {
405
+ callbacks?: Partial<PlayerCallbacks>;
406
+ };
407
+ managerConfig?: Omit<MountParams, "room">;
408
+ netlessApps?: NetlessApp[];
409
+ }
410
+ /**
411
+ * Create a FastboardPlayer instance.
412
+ * @example
413
+ * let player = await replayFastboard({
414
+ * sdkConfig: {
415
+ * appIdentifier: import.meta.env.VITE_APPID,
416
+ * region: 'cn-hz',
417
+ * },
418
+ * replayRoom: {
419
+ * room: "room uuid",
420
+ * roomToken: "NETLESSROOM_...",
421
+ * beginTimestamp: 1646619090394,
422
+ * duration: 70448,
423
+ * },
424
+ * })
425
+ */
426
+ declare function replayFastboard<TEventData extends Record<string, any> = any>({ sdkConfig, replayRoom: { callbacks, ...replayRoomParams }, managerConfig, netlessApps, }: FastboardReplayOptions): Promise<FastboardPlayer<TEventData>>;
427
+
428
+ declare const register: typeof WindowManager.register;
429
+ interface AppsConfig {
430
+ [kind: string]: Omit<RegisterParams, "kind">;
431
+ }
432
+ declare const version: string;
433
+
434
+ declare function addRoomListener<K extends keyof RoomCallbacks>(room: Room, name: K, listener: RoomCallbacks[K]): () => void;
435
+ declare function addPlayerListener<K extends keyof PlayerCallbacks>(player: Player, name: K, listener: PlayerCallbacks[K]): () => void;
436
+ /**
437
+ * Note: view listeners will be invalid on reconnection.
438
+ * You have to rebind them after the phase changed.
439
+ * @example
440
+ * const bindCamera = () => addViewListener(mainView, "onCameraUpdated", setCamera)
441
+ * let dispose = bindCamera(), phase_ = "disconnected"
442
+ * setCamera(mainView.camera)
443
+ * addRoomListener(room, "onPhaseChanged", (phase) => {
444
+ * if (phase === "connected" && phase_ === "reconnecting") {
445
+ * dispose()
446
+ * dispose = bindCamera()
447
+ * setCamera(mainView.camera)
448
+ * }
449
+ * phase_ = phase
450
+ * })
451
+ */
452
+ declare function addViewListener<K extends keyof ViewCallbacks>(view: View, name: K, listener: (value: ViewCallbacks[K]) => void): () => void;
453
+ declare function addManagerListener<K extends keyof PublicEvent>(manager: WindowManager, name: K, listener: (value: PublicEvent[K]) => void): () => void;
454
+
455
+ interface DocsEventOptions {
456
+ /** If provided, will dispatch to the specific app. Default to the focused app. */
457
+ appId?: string;
458
+ /** Used by `jumpToPage` event, range from 1 to total pages count. */
459
+ page?: number;
460
+ }
461
+ /**
462
+ * Send specific command to the static docs / slide app.
463
+ * Only works for apps that were created by `insertDocs()`.
464
+ *
465
+ * Returns false if failed to find the app or not writable.
466
+ *
467
+ * For static docs, `nextPage` equals to `nextStep`, as with `prevPage` and `prevStep`.
468
+ *
469
+ * @example
470
+ * ```js
471
+ * // send "next page" to the focused app
472
+ * dispatchDocsEvent(fastboard, "nextPage")
473
+ *
474
+ * // send "prev page" to some app
475
+ * dispatchDocsEvent(fastboard, "prevPage", {appId:"Slide-1a2b3c4d"})
476
+ * ```
477
+ */
478
+ declare function dispatchDocsEvent(fastboard: FastboardApp | WindowManager, event: "prevPage" | "nextPage" | "prevStep" | "nextStep" | "jumpToPage", options?: DocsEventOptions): boolean;
479
+
480
+ export { Appliance, AppsConfig, AppsStatus, DocsEventOptions, FastboardApp, FastboardOptions, FastboardPlayer, FastboardReplayOptions, InsertDocsDynamic, InsertDocsParams, InsertDocsStatic, PlayerPhase, ProjectorResponse, Readable, RoomPhase, RoomStateChanged, SetMemberStateFn, Shape, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable, addManagerListener, addPlayerListener, addRoomListener, addViewListener, convertedFileToScene, createFastboard, dispatchDocsEvent, genUID, getImageSize, makeSlideParams, readable, register, replayFastboard, version, warn, writable };