@netless/slide 1.4.60-alpha.0 → 1.4.61-beta.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/lib/Lock.js ADDED
@@ -0,0 +1,54 @@
1
+ /*
2
+ 防止信令收发延迟高的时候, 用户狂点, 导致短时间触发多次信令的修改, 按照事件类型加同步锁, 即同一个事件类型仅有第一个事件生效, 多点不生效
3
+ */
4
+ var Lock = /** @class */ (function () {
5
+ function Lock(available) {
6
+ this.autoUnlock = Object.create(null);
7
+ this.localKeyAutoRemove = Object.create(null);
8
+ this.localKeys = Object.create(null);
9
+ this.locks = Object.create(null);
10
+ this.available = false;
11
+ this.available = available;
12
+ }
13
+ Lock.prototype.addLock = function (type, key) {
14
+ var _this = this;
15
+ if (!this.available) {
16
+ return;
17
+ }
18
+ this.locks[type] = key;
19
+ this.localKeys[key] = true;
20
+ this.localKeyAutoRemove[key] = window.setTimeout(function () {
21
+ delete _this.localKeys[key];
22
+ delete _this.localKeyAutoRemove[key];
23
+ }, 60 * 1000);
24
+ this.autoUnlock[type] = window.setTimeout(function () {
25
+ delete _this.locks[type];
26
+ delete _this.autoUnlock[type];
27
+ }, 3000);
28
+ };
29
+ Lock.prototype.unlock = function (type, key) {
30
+ if (!this.available) {
31
+ return false;
32
+ }
33
+ var isLocalEvent = !!key && !!this.localKeys[key];
34
+ if (key && isLocalEvent) {
35
+ window.clearTimeout(this.localKeyAutoRemove[key]);
36
+ delete this.localKeys[key];
37
+ delete this.localKeyAutoRemove[key];
38
+ }
39
+ if (key && this.locks[type] && this.locks[type] === key) {
40
+ window.clearTimeout(this.autoUnlock[type]);
41
+ delete this.locks[type];
42
+ delete this.autoUnlock[type];
43
+ }
44
+ return isLocalEvent;
45
+ };
46
+ Lock.prototype.isLocked = function (type) {
47
+ if (!this.available) {
48
+ return false;
49
+ }
50
+ return !!this.locks[type];
51
+ };
52
+ return Lock;
53
+ }());
54
+ export { Lock };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Wait for the browser to finish releasing a destroyed WebGL context before
3
+ * creating a replacement player. Uses rAF when available, but always settles
4
+ * within a bounded timeout so hidden/background WebViews cannot hang release.
5
+ */
6
+ export function waitForPlayerContextRelease(platform) {
7
+ var isMobile = platform.isIOS() || platform.isAndroid();
8
+ var minFrames = isMobile ? 4 : 2;
9
+ var settleMs = isMobile ? 100 : 16;
10
+ var maxWaitMs = isMobile ? 500 : 200;
11
+ return new Promise(function (resolve) {
12
+ var settled = false;
13
+ var complete = function () {
14
+ if (settled) {
15
+ return;
16
+ }
17
+ settled = true;
18
+ setTimeout(resolve, settleMs);
19
+ };
20
+ var timeoutId = setTimeout(complete, maxWaitMs);
21
+ var frameCount = 0;
22
+ var nextFrame = function () {
23
+ if (settled) {
24
+ return;
25
+ }
26
+ frameCount += 1;
27
+ if (frameCount >= minFrames) {
28
+ clearTimeout(timeoutId);
29
+ complete();
30
+ return;
31
+ }
32
+ if (typeof window.requestAnimationFrame === "function") {
33
+ window.requestAnimationFrame(nextFrame);
34
+ }
35
+ else {
36
+ setTimeout(nextFrame, 0);
37
+ }
38
+ };
39
+ nextFrame();
40
+ });
41
+ }
@@ -0,0 +1,175 @@
1
+ import { GUI } from "dat.gui";
2
+ var PlayerConfig = /** @class */ (function () {
3
+ function PlayerConfig(player) {
4
+ this.player = player;
5
+ }
6
+ ;
7
+ Object.defineProperty(PlayerConfig.prototype, "frameRate", {
8
+ get: function () {
9
+ return this.player.fps.value;
10
+ },
11
+ set: function (_) { },
12
+ enumerable: false,
13
+ configurable: true
14
+ });
15
+ Object.defineProperty(PlayerConfig.prototype, "drawFrames", {
16
+ get: function () {
17
+ return this.player.runtime.fps;
18
+ },
19
+ set: function (_) { },
20
+ enumerable: false,
21
+ configurable: true
22
+ });
23
+ Object.defineProperty(PlayerConfig.prototype, "drawCall", {
24
+ get: function () {
25
+ return this.player.runtime.drawCall;
26
+ },
27
+ set: function (_) { },
28
+ enumerable: false,
29
+ configurable: true
30
+ });
31
+ Object.defineProperty(PlayerConfig.prototype, "resolution", {
32
+ get: function () {
33
+ return this.player.config.resolution;
34
+ },
35
+ set: function (value) {
36
+ this.player.updateConfig({ resolution: value });
37
+ },
38
+ enumerable: false,
39
+ configurable: true
40
+ });
41
+ Object.defineProperty(PlayerConfig.prototype, "size", {
42
+ get: function () {
43
+ var _a, _b;
44
+ return ((_a = this.player.view) === null || _a === void 0 ? void 0 : _a.width) + "*" + ((_b = this.player.view) === null || _b === void 0 ? void 0 : _b.height);
45
+ },
46
+ set: function (_) { },
47
+ enumerable: false,
48
+ configurable: true
49
+ });
50
+ Object.defineProperty(PlayerConfig.prototype, "minFPS", {
51
+ get: function () {
52
+ return this.player.config.minFPS;
53
+ },
54
+ set: function (value) {
55
+ this.player.updateConfig({ minFPS: value, maxFPS: this.player.config.maxFPS });
56
+ },
57
+ enumerable: false,
58
+ configurable: true
59
+ });
60
+ Object.defineProperty(PlayerConfig.prototype, "maxFPS", {
61
+ get: function () {
62
+ return this.player.config.maxFPS;
63
+ },
64
+ set: function (value) {
65
+ this.player.updateConfig({ maxFPS: value, minFPS: this.player.config.minFPS });
66
+ },
67
+ enumerable: false,
68
+ configurable: true
69
+ });
70
+ Object.defineProperty(PlayerConfig.prototype, "autoResolution", {
71
+ get: function () {
72
+ return this.player.config.autoResolution;
73
+ },
74
+ set: function (value) {
75
+ this.player.updateConfig({ autoResolution: value });
76
+ },
77
+ enumerable: false,
78
+ configurable: true
79
+ });
80
+ Object.defineProperty(PlayerConfig.prototype, "autoFPS", {
81
+ get: function () {
82
+ return this.player.config.autoFPS;
83
+ },
84
+ set: function (value) {
85
+ this.player.updateConfig({ autoFPS: value });
86
+ },
87
+ enumerable: false,
88
+ configurable: true
89
+ });
90
+ Object.defineProperty(PlayerConfig.prototype, "backgroundColor", {
91
+ get: function () {
92
+ return this.player.config.transactionBgColor;
93
+ },
94
+ set: function (value) {
95
+ this.player.updateConfig({ transactionBgColor: value });
96
+ },
97
+ enumerable: false,
98
+ configurable: true
99
+ });
100
+ Object.defineProperty(PlayerConfig.prototype, "maxResolutionLevel", {
101
+ get: function () {
102
+ return this.player.config.maxResolutionLevel;
103
+ },
104
+ set: function (value) {
105
+ this.player.updateConfig({ maxResolutionLevel: value });
106
+ },
107
+ enumerable: false,
108
+ configurable: true
109
+ });
110
+ return PlayerConfig;
111
+ }());
112
+ export { PlayerConfig };
113
+ var PlayerController = /** @class */ (function () {
114
+ function PlayerController(player, anchor) {
115
+ var _a;
116
+ this.config = new PlayerConfig(player);
117
+ this.anchor = anchor;
118
+ _a = this.createControllerGUI(), this.gui = _a[0], this.controller = _a[1];
119
+ this.createStats();
120
+ }
121
+ PlayerController.prototype.createStats = function () {
122
+ var _this = this;
123
+ this.stateId = setInterval(function () {
124
+ _this.controller.frameRate.updateDisplay();
125
+ _this.controller.size.updateDisplay();
126
+ _this.controller.minFPS.updateDisplay();
127
+ _this.controller.drawFrames.updateDisplay();
128
+ _this.controller.maxFPS.updateDisplay();
129
+ _this.controller.resolution.updateDisplay();
130
+ _this.controller.autoFps.updateDisplay();
131
+ _this.controller.autoResolution.updateDisplay();
132
+ _this.controller.drawCall.updateDisplay();
133
+ }, 16);
134
+ };
135
+ PlayerController.prototype.createControllerGUI = function () {
136
+ var gui = new GUI({
137
+ autoPlace: true,
138
+ closed: true,
139
+ });
140
+ gui.domElement.style.opacity = ".6";
141
+ gui.domElement.style.transformOrigin = "100% 0";
142
+ gui.domElement.style.transform = "scale(1)";
143
+ this.anchor.appendChild(gui.domElement);
144
+ gui.domElement.style.position = "absolute";
145
+ gui.domElement.style.right = "0";
146
+ gui.domElement.style.top = "0";
147
+ gui.domElement.style.zIndex = "2";
148
+ var controller = {
149
+ frameRate: gui.add(this.config, "frameRate"),
150
+ drawFrames: gui.add(this.config, "drawFrames"),
151
+ drawCall: gui.add(this.config, "drawCall"),
152
+ size: gui.add(this.config, "size"),
153
+ minFPS: gui.add(this.config, "minFPS", 0, 60),
154
+ maxFPS: gui.add(this.config, "maxFPS", 0, 60),
155
+ resolution: gui.add(this.config, "resolution", 0.5, 8, 0.5),
156
+ autoResolution: gui.add(this.config, "autoResolution"),
157
+ autoFps: gui.add(this.config, "autoFPS"),
158
+ maxResolutionLevel: gui.add(this.config, "maxResolutionLevel", 0, 4, 1),
159
+ transactionBgColor: gui.addColor(this.config, "backgroundColor"),
160
+ };
161
+ return [gui, controller];
162
+ };
163
+ PlayerController.prototype.destroy = function () {
164
+ try {
165
+ window.clearInterval(this.stateId);
166
+ this.anchor.removeChild(this.gui.domElement);
167
+ this.gui.destroy();
168
+ }
169
+ catch (_a) {
170
+ //
171
+ }
172
+ };
173
+ return PlayerController;
174
+ }());
175
+ export { PlayerController };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Reveal a completed live render and remove its fallback image.
3
+ * Frozen and release states own visibility while their player transition is active.
4
+ */
5
+ export function updateRenderSlideVisibility(isReleasing, player, frame, cacheImage) {
6
+ if (isReleasing || !(player === null || player === void 0 ? void 0 : player.view)) {
7
+ return;
8
+ }
9
+ if (player.view.style.visibility === "hidden") {
10
+ player.view.style.visibility = "visible";
11
+ }
12
+ if (frame.style.visibility === "hidden") {
13
+ frame.style.visibility = "visible";
14
+ }
15
+ cacheImage.style.display = "none";
16
+ }
@@ -0,0 +1,230 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (_) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ import EventEmitter from "eventemitter3";
53
+ var RenderTaskCancelledError = /** @class */ (function (_super) {
54
+ __extends(RenderTaskCancelledError, _super);
55
+ function RenderTaskCancelledError(message) {
56
+ if (message === void 0) { message = "render task cancelled"; }
57
+ var _this = _super.call(this, message) || this;
58
+ _this.code = "RENDER_TASK_CANCELLED";
59
+ _this.name = "AbortError";
60
+ return _this;
61
+ }
62
+ return RenderTaskCancelledError;
63
+ }(Error));
64
+ export { RenderTaskCancelledError };
65
+ var Task = /** @class */ (function () {
66
+ function Task(index, slideIndex, fn, eventHub, id) {
67
+ this.state = "idle";
68
+ this.index = -1;
69
+ this.slideIndex = -1;
70
+ this.cancelled = false;
71
+ this.fn = fn;
72
+ this.index = index;
73
+ this.slideIndex = slideIndex;
74
+ this.eventHub = eventHub;
75
+ this.id = id;
76
+ }
77
+ Task.prototype.apply = function () {
78
+ return __awaiter(this, void 0, void 0, function () {
79
+ var e_1;
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0:
83
+ if (this.cancelled) {
84
+ return [2 /*return*/];
85
+ }
86
+ this.eventHub.emit("task-start", this);
87
+ _a.label = 1;
88
+ case 1:
89
+ _a.trys.push([1, 3, , 4]);
90
+ this.state = "start";
91
+ return [4 /*yield*/, this.fn()];
92
+ case 2:
93
+ _a.sent();
94
+ if (this.cancelled) {
95
+ return [2 /*return*/];
96
+ }
97
+ this.state = "end";
98
+ this.eventHub.emit("task-end", this);
99
+ return [3 /*break*/, 4];
100
+ case 3:
101
+ e_1 = _a.sent();
102
+ if (this.cancelled) {
103
+ return [2 /*return*/];
104
+ }
105
+ if (e_1 instanceof RenderTaskCancelledError) {
106
+ this.cancel();
107
+ this.eventHub.emit("task-cancel", {
108
+ task: this,
109
+ error: e_1,
110
+ });
111
+ return [2 /*return*/];
112
+ }
113
+ this.eventHub.emit("task-error", {
114
+ task: this,
115
+ error: e_1,
116
+ });
117
+ return [3 /*break*/, 4];
118
+ case 4: return [2 /*return*/];
119
+ }
120
+ });
121
+ });
122
+ };
123
+ Task.prototype.cancel = function () {
124
+ this.cancelled = true;
125
+ };
126
+ return Task;
127
+ }());
128
+ export { Task };
129
+ var RenderingTaskManager = /** @class */ (function () {
130
+ function RenderingTaskManager() {
131
+ var _this = this;
132
+ this.eventHub = new EventEmitter();
133
+ this.tasks = [];
134
+ this.index = 0;
135
+ this.destroyed = false;
136
+ this.eventHub.on("task-end", function (task) {
137
+ var _a;
138
+ var selfIndex = _this.tasks.findIndex(function (t) { return t.index === task.index; });
139
+ var nextIndex = selfIndex + 1;
140
+ if (nextIndex >= 0) {
141
+ (_a = _this.tasks[nextIndex]) === null || _a === void 0 ? void 0 : _a.apply();
142
+ }
143
+ if (selfIndex >= 0) {
144
+ _this.tasks.splice(selfIndex, 1);
145
+ _this.replaceIdleTask();
146
+ }
147
+ _this.eventHub.emit("task-end-" + task.id);
148
+ });
149
+ this.eventHub.on("task-error", function (_a) {
150
+ var _b;
151
+ var task = _a.task, error = _a.error;
152
+ var selfIndex = _this.tasks.findIndex(function (t) { return t.index === task.index; });
153
+ var wasRunning = task.state === "start";
154
+ if (selfIndex >= 0) {
155
+ _this.tasks.splice(selfIndex, 1);
156
+ _this.replaceIdleTask();
157
+ if (wasRunning && !_this.destroyed) {
158
+ (_b = _this.tasks[selfIndex]) === null || _b === void 0 ? void 0 : _b.apply();
159
+ }
160
+ }
161
+ _this.eventHub.emit("task-error-" + task.id, error);
162
+ });
163
+ this.eventHub.on("task-cancel", function (_a) {
164
+ var _b;
165
+ var task = _a.task, error = _a.error;
166
+ var selfIndex = _this.tasks.findIndex(function (t) { return t.index === task.index; });
167
+ var wasRunning = task.state === "start";
168
+ if (selfIndex >= 0) {
169
+ _this.tasks.splice(selfIndex, 1);
170
+ if (wasRunning && !_this.destroyed) {
171
+ (_b = _this.tasks[selfIndex]) === null || _b === void 0 ? void 0 : _b.apply();
172
+ }
173
+ }
174
+ _this.eventHub.emit("task-cancel-" + task.id, error);
175
+ });
176
+ }
177
+ RenderingTaskManager.prototype.cancelTask = function (task) {
178
+ var error = new RenderTaskCancelledError();
179
+ task.cancel();
180
+ this.eventHub.emit("task-cancel", { task: task, error: error });
181
+ };
182
+ RenderingTaskManager.prototype.replaceIdleTask = function () {
183
+ var _this = this;
184
+ var _a;
185
+ var ids = new Set();
186
+ for (var i = 0, len = this.tasks.length; i < len; i++) {
187
+ if (this.tasks[i].state === "idle" && ((_a = this.tasks[i + 1]) === null || _a === void 0 ? void 0 : _a.state) === "idle") {
188
+ ids.add(i);
189
+ }
190
+ }
191
+ // Remove from the end so deleting one idle task does not shift the
192
+ // indexes selected for the remaining cancellations.
193
+ Array.from(ids).sort(function (a, b) { return b - a; }).forEach(function (id) {
194
+ var task = _this.tasks.splice(id, 1)[0];
195
+ if (task) {
196
+ _this.cancelTask(task);
197
+ }
198
+ });
199
+ };
200
+ RenderingTaskManager.prototype.addTask = function (fn, slideIndex, id) {
201
+ if (this.destroyed) {
202
+ return undefined;
203
+ }
204
+ var task = new Task(this.index++, slideIndex, fn, this.eventHub, id);
205
+ this.tasks.push(task);
206
+ this.tasks.sort(function (a, b) { return a.index - b.index; });
207
+ this.replaceIdleTask();
208
+ if (this.tasks.length === 1) {
209
+ task.apply();
210
+ }
211
+ return task;
212
+ };
213
+ RenderingTaskManager.prototype.hasStartTask = function () {
214
+ return this.tasks.some(function (t) { return t.state === "start"; });
215
+ };
216
+ RenderingTaskManager.prototype.destroy = function () {
217
+ var _this = this;
218
+ if (this.destroyed) {
219
+ return;
220
+ }
221
+ this.destroyed = true;
222
+ var tasks = this.tasks.splice(0);
223
+ tasks.forEach(function (task) {
224
+ _this.cancelTask(task);
225
+ });
226
+ this.eventHub.removeAllListeners();
227
+ };
228
+ return RenderingTaskManager;
229
+ }());
230
+ export { RenderingTaskManager };
package/lib/Slide.d.ts CHANGED
@@ -460,6 +460,7 @@ export declare class Slide extends Slide_base {
460
460
  private lifecycle;
461
461
  private lifecycleGeneration;
462
462
  private renderVisibilityTimers;
463
+ private destroyPromise?;
463
464
  private isLoading;
464
465
  private isReleasing;
465
466
  private interactive;
@@ -718,12 +719,12 @@ export declare class Slide extends Slide_base {
718
719
  /**
719
720
  * Enter freeze state, cache the ppt screen as an image, and release the WebGL context.
720
721
  */
721
- frozen(callback?: () => void): void;
722
+ frozen(callback?: () => void): Promise<void>;
722
723
  private _doRelease;
723
724
  /**
724
725
  * Recover from frozen state.
725
726
  */
726
- release(callback?: () => void): void;
727
+ release(callback?: () => void): Promise<void>;
727
728
  private _doDestroy;
728
729
  private waitLoadEnd;
729
730
  /**
@@ -735,7 +736,7 @@ export declare class Slide extends Slide_base {
735
736
  /**
736
737
  * Destruction method.
737
738
  */
738
- destroy(): void;
739
+ destroy(): Promise<void>;
739
740
  /**
740
741
  * Destroy the local cache of the current Slide instance, need to be called before destroy.
741
742
  */