@netless/forge-slide 1.1.0-beta.1 → 1.1.0-beta.2
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/Slide.d.ts +10 -0
- package/dist/Slide.d.ts.map +1 -1
- package/dist/SlideApplication.d.ts +2 -1
- package/dist/SlideApplication.d.ts.map +1 -1
- package/dist/slide.esm.js +140 -18
- package/dist/slide.esm.js.map +4 -4
- package/dist/slide.js +140 -18
- package/dist/slide.js.map +4 -4
- package/package.json +3 -3
- package/src/Slide.ts +11 -0
- package/src/SlideApplication.ts +31 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/forge-slide",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/slide.js",
|
|
6
6
|
"module": "dist/slide.esm.js",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"eventemitter3": "^5.0.1",
|
|
13
13
|
"yjs": "^13.6.18",
|
|
14
14
|
"uuid": "^11.0.5",
|
|
15
|
-
"@netless/forge-room": "1.1.0-beta.
|
|
16
|
-
"@netless/forge-whiteboard": "1.1.0-beta.
|
|
15
|
+
"@netless/forge-room": "1.1.0-beta.2",
|
|
16
|
+
"@netless/forge-whiteboard": "1.1.0-beta.2"
|
|
17
17
|
},
|
|
18
18
|
"keywords": [],
|
|
19
19
|
"author": "",
|
package/src/Slide.ts
CHANGED
|
@@ -93,4 +93,15 @@ export class SlideForge extends EventEmitter<SlideEvents> implements Application
|
|
|
93
93
|
* @param {number} index 页面索引
|
|
94
94
|
*/
|
|
95
95
|
public imgSize!: (index: number) => Promise<{width: number, height: number}>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 冻结当前幻灯片, 释放资源
|
|
99
|
+
* @param {() => void} [callback] 冻结完成回调
|
|
100
|
+
*/
|
|
101
|
+
public frozen!: (callback?: () => void) => void;
|
|
102
|
+
/**
|
|
103
|
+
* 解冻冻结的幻灯片, 重新获取资源
|
|
104
|
+
* @param {() => void} [callback] 解冻完成回调
|
|
105
|
+
*/
|
|
106
|
+
public release!: (callback?: () => void) => void;
|
|
96
107
|
}
|
package/src/SlideApplication.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { FooterView } from './FooterView';
|
|
|
7
7
|
import * as Y from 'yjs';
|
|
8
8
|
import { SideBarView } from './SiderBarView';
|
|
9
9
|
import { deepEqual } from './utils';
|
|
10
|
+
import { SlidePool } from './SlidePool';
|
|
10
11
|
|
|
11
12
|
export interface SlideApplicationOption {
|
|
12
13
|
prefix: string;
|
|
@@ -30,6 +31,7 @@ export const Slide_APP_NAME = 'forge_slide';
|
|
|
30
31
|
export class SlideApplication extends AbstractApplication<SlideApplicationOption, SlideForge> {
|
|
31
32
|
|
|
32
33
|
static applicationName = Slide_APP_NAME;
|
|
34
|
+
static slidePool: SlidePool = new SlidePool();
|
|
33
35
|
|
|
34
36
|
public readonly name: string = Slide_APP_NAME;
|
|
35
37
|
public readonly emitter: SlideForge = new SlideForge();
|
|
@@ -228,7 +230,20 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
228
230
|
return this.getImageSize(pageIndex);
|
|
229
231
|
},
|
|
230
232
|
});
|
|
231
|
-
this.
|
|
233
|
+
Object.defineProperty(this.emitter, 'frozen', {
|
|
234
|
+
writable: false,
|
|
235
|
+
enumerable: false,
|
|
236
|
+
value: (callback?: () => void) => {
|
|
237
|
+
return this.slide.frozen(callback);
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(this.emitter, 'release', {
|
|
241
|
+
writable: false,
|
|
242
|
+
enumerable: false,
|
|
243
|
+
value: (callback?: () => void) => {
|
|
244
|
+
return this.slide.release(callback);
|
|
245
|
+
},
|
|
246
|
+
});
|
|
232
247
|
}
|
|
233
248
|
|
|
234
249
|
private getPreviewImageUrl (pageIndex: number) {
|
|
@@ -276,27 +291,19 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
276
291
|
return preview.src;
|
|
277
292
|
}
|
|
278
293
|
|
|
279
|
-
private
|
|
280
|
-
this.isSyncing = false;
|
|
281
|
-
requestAnimationFrame(() => {
|
|
282
|
-
this.applySlideState().catch((error) => {
|
|
283
|
-
console.error('Error in applySlideState:', error);
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
private applySlideState = async () => {
|
|
294
|
+
private applySlideState = async (): Promise<void> => {
|
|
289
295
|
if (this.isSyncing) {
|
|
296
|
+
requestAnimationFrame(this.applySlideState);
|
|
290
297
|
return;
|
|
291
298
|
}
|
|
292
299
|
|
|
293
300
|
const lastSyncMessage = this.syncMessageQueue.pop();
|
|
294
301
|
if (!lastSyncMessage) {
|
|
295
|
-
return
|
|
302
|
+
return;
|
|
296
303
|
}
|
|
297
304
|
|
|
298
|
-
this.syncMessageQueue = [];
|
|
299
305
|
this.isSyncing = true;
|
|
306
|
+
this.syncMessageQueue = [];
|
|
300
307
|
const { state, dispatch } = lastSyncMessage;
|
|
301
308
|
let ignoreKeys: string[] | undefined = undefined;
|
|
302
309
|
if ( dispatch.type === 'mediaPlay' || dispatch.type === 'mediaPause' || dispatch.type === 'mediaFullscreen') {
|
|
@@ -305,7 +312,6 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
305
312
|
if (this.slide.slideState.currentSlideIndex < 0 || state.currentSlideIndex < 0) {
|
|
306
313
|
// @ts-ignore
|
|
307
314
|
await this.slide.receiveSyncHandler(dispatch);
|
|
308
|
-
return this.nextTick();
|
|
309
315
|
} else if (!deepEqual(this.slide.slideState, state, ignoreKeys)) {
|
|
310
316
|
await this.slide.setSlideState(state);
|
|
311
317
|
// @ts-ignore
|
|
@@ -313,7 +319,7 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
313
319
|
} else {
|
|
314
320
|
this.slide.emit(SLIDE_EVENTS.syncReceive, dispatch);
|
|
315
321
|
}
|
|
316
|
-
|
|
322
|
+
this.isSyncing = false;
|
|
317
323
|
|
|
318
324
|
};
|
|
319
325
|
|
|
@@ -358,7 +364,7 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
358
364
|
|
|
359
365
|
private async onFocusInstance() {
|
|
360
366
|
this.bindKeyBoardEvent();
|
|
361
|
-
|
|
367
|
+
await SlideApplication.slidePool.active(this.appId, this.slide);
|
|
362
368
|
}
|
|
363
369
|
|
|
364
370
|
private onRefocusInstance() {
|
|
@@ -421,11 +427,14 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
421
427
|
}
|
|
422
428
|
|
|
423
429
|
this.whiteboard.setViewModeToMain();
|
|
424
|
-
|
|
430
|
+
for (let i = 0; i < json.slideCount; i++) {
|
|
431
|
+
this.whiteboardApp.addPage(String(i), true);
|
|
432
|
+
}
|
|
433
|
+
this.whiteboard.setViewModeToFree();
|
|
425
434
|
|
|
426
435
|
this.slideContainer.setAttribute('builder', 'slide-builder');
|
|
427
436
|
|
|
428
|
-
|
|
437
|
+
await SlideApplication.slidePool.waitUntilReady(this.appId);
|
|
429
438
|
this.slide = new Slide({
|
|
430
439
|
...option.options,
|
|
431
440
|
interactive: true,
|
|
@@ -473,8 +482,7 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
473
482
|
if (slideIndex >= 0) {
|
|
474
483
|
this.sideBar.pauseGetPreviewImageSchedule();
|
|
475
484
|
this.whiteboardApp.emitter.view.style.opacity = '0';
|
|
476
|
-
this.whiteboardApp.emitter.
|
|
477
|
-
this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
|
|
485
|
+
this.whiteboardApp.emitter.gotoPage(String(slideIndex));
|
|
478
486
|
this.sideBar.hidden();
|
|
479
487
|
this.footer.changeIconToPause();
|
|
480
488
|
this.emitter.emit('renderStart', slideIndex);
|
|
@@ -487,8 +495,8 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
487
495
|
this.currentSlideIndex = slideIndex;
|
|
488
496
|
this.whiteboardApp.emitter.view.style.opacity = '1';
|
|
489
497
|
this.footer.setCurrentPageIndex(slideIndex);
|
|
490
|
-
|
|
491
|
-
|
|
498
|
+
SlideApplication.slidePool.active(this.appId, this.slide);
|
|
499
|
+
SlideApplication.slidePool.onRenderEnd(this.appId, this.window?.focused ?? false);
|
|
492
500
|
this.footer.changeIconToNextStep();
|
|
493
501
|
this.emitter.emit('renderEnd', slideIndex);
|
|
494
502
|
}
|
|
@@ -571,7 +579,7 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
571
579
|
this.getMap(this.name).unobserve(this.onSlideEventHandler);
|
|
572
580
|
this.permissions.dispose();
|
|
573
581
|
this.footer.dispose();
|
|
574
|
-
|
|
582
|
+
SlideApplication.slidePool.remove(this.appId);
|
|
575
583
|
}
|
|
576
584
|
|
|
577
585
|
}
|