@netless/slide 1.4.59-alpha.3 → 1.4.59-alpha.4
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 +8 -0
- package/lib/Slide.d.ts +12 -0
- package/lib/Slide.js +2 -2
- package/package.json +2 -3
- package/lib/AliTrackLogger.js +0 -516
- package/lib/FrozenTaskManager.js +0 -59
- package/lib/Lock.js +0 -54
- package/lib/PlayerController.js +0 -175
- package/lib/RenderSlideVisibility.js +0 -16
- package/lib/RenderingTaskManager.js +0 -230
- package/lib/SyncTaskManager.js +0 -206
- package/lib/global.js +0 -118
package/lib/PlayerController.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
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 };
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,230 +0,0 @@
|
|
|
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/SyncTaskManager.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
function assertSyncEventQueuePolicy(policy) {
|
|
2
|
-
if (policy !== "fifo" && policy !== "latest-pending-render") {
|
|
3
|
-
throw new Error("Invalid sync event queue policy: " + policy);
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
export function resolveSyncEventQueuePolicy(mode, policy) {
|
|
7
|
-
if (policy === void 0) { policy = "fifo"; }
|
|
8
|
-
assertSyncEventQueuePolicy(policy);
|
|
9
|
-
return mode === "interactive" ? policy : "fifo";
|
|
10
|
-
}
|
|
11
|
-
function isPageScopedEvent(event) {
|
|
12
|
-
switch (event.type) {
|
|
13
|
-
case "renderSlide":
|
|
14
|
-
case "nextStep":
|
|
15
|
-
case "prevStep":
|
|
16
|
-
case "interactiveAnim":
|
|
17
|
-
case "mediaPlay":
|
|
18
|
-
case "mediaPause":
|
|
19
|
-
case "mediaSeek":
|
|
20
|
-
case "mediaFullscreen":
|
|
21
|
-
return true;
|
|
22
|
-
default:
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
var SyncTaskManager = /** @class */ (function () {
|
|
27
|
-
function SyncTaskManager(fn, options) {
|
|
28
|
-
var _this = this;
|
|
29
|
-
if (options === void 0) { options = {}; }
|
|
30
|
-
this.tasks = [];
|
|
31
|
-
this.isDestroy = false;
|
|
32
|
-
this.isScheduling = false;
|
|
33
|
-
this.isTaskRunning = false;
|
|
34
|
-
this.isCatchingUp = false;
|
|
35
|
-
this.compactedTasks = new WeakMap();
|
|
36
|
-
this.finishTask = function () {
|
|
37
|
-
_this.isTaskRunning = false;
|
|
38
|
-
_this.runningTask = undefined;
|
|
39
|
-
if (_this.isDestroy) {
|
|
40
|
-
_this.tasks.length = 0;
|
|
41
|
-
_this.isScheduling = false;
|
|
42
|
-
}
|
|
43
|
-
else if (_this.tasks.length > 0) {
|
|
44
|
-
window.requestAnimationFrame(_this.schedule);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
_this.isScheduling = false;
|
|
48
|
-
_this.setCatchUpState(false);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
this.schedule = function () {
|
|
52
|
-
if (_this.isDestroy) {
|
|
53
|
-
_this.tasks.length = 0;
|
|
54
|
-
_this.isScheduling = false;
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
_this.isScheduling = true;
|
|
58
|
-
var task = _this.tasks.shift();
|
|
59
|
-
if (!task) {
|
|
60
|
-
_this.isScheduling = false;
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
_this.isTaskRunning = true;
|
|
64
|
-
_this.runningTask = task;
|
|
65
|
-
var compactInfo = _this.compactedTasks.get(task);
|
|
66
|
-
try {
|
|
67
|
-
_this.fn(task).then(function () {
|
|
68
|
-
var _a;
|
|
69
|
-
_this.compactedTasks.delete(task);
|
|
70
|
-
if (compactInfo && !_this.isDestroy) {
|
|
71
|
-
try {
|
|
72
|
-
(_a = _this.onCompactedRenderComplete) === null || _a === void 0 ? void 0 : _a.call(_this, compactInfo, Date.now());
|
|
73
|
-
}
|
|
74
|
-
catch ( /* Observability must not interrupt synchronization. */_b) { /* Observability must not interrupt synchronization. */ }
|
|
75
|
-
}
|
|
76
|
-
_this.finishTask();
|
|
77
|
-
}, function () {
|
|
78
|
-
_this.compactedTasks.delete(task);
|
|
79
|
-
_this.finishTask();
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
catch (_a) {
|
|
83
|
-
_this.compactedTasks.delete(task);
|
|
84
|
-
_this.finishTask();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
this.fn = fn;
|
|
88
|
-
this.policy = options.policy || "fifo";
|
|
89
|
-
this.onCompact = options.onCompact;
|
|
90
|
-
this.onCompactedRenderComplete = options.onCompactedRenderComplete;
|
|
91
|
-
this.onCatchUpStateChange = options.onCatchUpStateChange;
|
|
92
|
-
this.shouldTrackCatchUpEvent = options.shouldTrackCatchUpEvent;
|
|
93
|
-
assertSyncEventQueuePolicy(this.policy);
|
|
94
|
-
}
|
|
95
|
-
SyncTaskManager.prototype.destroy = function () {
|
|
96
|
-
this.isDestroy = true;
|
|
97
|
-
this.isCatchingUp = false;
|
|
98
|
-
this.runningTask = undefined;
|
|
99
|
-
this.tasks.length = 0;
|
|
100
|
-
};
|
|
101
|
-
SyncTaskManager.prototype.setPolicy = function (policy) {
|
|
102
|
-
assertSyncEventQueuePolicy(policy);
|
|
103
|
-
this.policy = policy;
|
|
104
|
-
};
|
|
105
|
-
SyncTaskManager.prototype.setCatchUpState = function (isCatchingUp) {
|
|
106
|
-
var _a;
|
|
107
|
-
if (this.isCatchingUp === isCatchingUp) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.isCatchingUp = isCatchingUp;
|
|
111
|
-
try {
|
|
112
|
-
(_a = this.onCatchUpStateChange) === null || _a === void 0 ? void 0 : _a.call(this, isCatchingUp);
|
|
113
|
-
}
|
|
114
|
-
catch ( /* Observability must not interrupt synchronization. */_b) { /* Observability must not interrupt synchronization. */ }
|
|
115
|
-
};
|
|
116
|
-
SyncTaskManager.prototype.isCatchUpEvent = function (event) {
|
|
117
|
-
var _a, _b;
|
|
118
|
-
try {
|
|
119
|
-
return (_b = (_a = this.shouldTrackCatchUpEvent) === null || _a === void 0 ? void 0 : _a.call(this, event)) !== null && _b !== void 0 ? _b : true;
|
|
120
|
-
}
|
|
121
|
-
catch (_c) {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
SyncTaskManager.prototype.compactForRender = function (event) {
|
|
126
|
-
var droppedEventTypes = {};
|
|
127
|
-
var droppedEventCount = 0;
|
|
128
|
-
var droppedRenderCount = 0;
|
|
129
|
-
var droppedStepCount = 0;
|
|
130
|
-
var droppedAnimationCount = 0;
|
|
131
|
-
var droppedMediaCount = 0;
|
|
132
|
-
while (this.tasks.length > 0) {
|
|
133
|
-
var pendingEvent = this.tasks[this.tasks.length - 1];
|
|
134
|
-
if (!isPageScopedEvent(pendingEvent)) {
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
this.tasks.pop();
|
|
138
|
-
this.compactedTasks.delete(pendingEvent);
|
|
139
|
-
droppedEventCount += 1;
|
|
140
|
-
droppedEventTypes[pendingEvent.type] = (droppedEventTypes[pendingEvent.type] || 0) + 1;
|
|
141
|
-
if (pendingEvent.type === "renderSlide") {
|
|
142
|
-
droppedRenderCount += 1;
|
|
143
|
-
}
|
|
144
|
-
else if (pendingEvent.type === "nextStep" || pendingEvent.type === "prevStep") {
|
|
145
|
-
droppedStepCount += 1;
|
|
146
|
-
}
|
|
147
|
-
else if (pendingEvent.type === "interactiveAnim") {
|
|
148
|
-
droppedAnimationCount += 1;
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
droppedMediaCount += 1;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (droppedEventCount === 0) {
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
var boundaryEvent = this.tasks[this.tasks.length - 1];
|
|
158
|
-
return {
|
|
159
|
-
policy: "latest-pending-render",
|
|
160
|
-
droppedEventCount: droppedEventCount,
|
|
161
|
-
droppedRenderCount: droppedRenderCount,
|
|
162
|
-
droppedStepCount: droppedStepCount,
|
|
163
|
-
droppedAnimationCount: droppedAnimationCount,
|
|
164
|
-
droppedMediaCount: droppedMediaCount,
|
|
165
|
-
droppedOperationCount: droppedEventCount - droppedRenderCount,
|
|
166
|
-
droppedEventTypes: droppedEventTypes,
|
|
167
|
-
retainedSlideIndex: event.index,
|
|
168
|
-
retainedRenderReceivedAt: Date.now(),
|
|
169
|
-
hasRunningTask: this.isTaskRunning,
|
|
170
|
-
hardBoundaryType: boundaryEvent === null || boundaryEvent === void 0 ? void 0 : boundaryEvent.type,
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
SyncTaskManager.prototype.addTask = function (event) {
|
|
174
|
-
var _this = this;
|
|
175
|
-
var _a;
|
|
176
|
-
if (this.isDestroy) {
|
|
177
|
-
return undefined;
|
|
178
|
-
}
|
|
179
|
-
var hasPendingWork = this.isTaskRunning || this.tasks.length > 0;
|
|
180
|
-
var isIncomingCatchUpEvent = this.policy === "latest-pending-render" && this.isCatchUpEvent(event);
|
|
181
|
-
var hasCatchUpEvent = this.policy === "latest-pending-render" && (isIncomingCatchUpEvent ||
|
|
182
|
-
(!!this.runningTask && this.isCatchUpEvent(this.runningTask)) ||
|
|
183
|
-
this.tasks.some(function (pendingEvent) { return _this.isCatchUpEvent(pendingEvent); }));
|
|
184
|
-
var compactInfo = this.policy === "latest-pending-render" && event.type === "renderSlide" ?
|
|
185
|
-
this.compactForRender(event) :
|
|
186
|
-
undefined;
|
|
187
|
-
this.tasks.push(event);
|
|
188
|
-
var shouldStartCatchUp = hasCatchUpEvent && (hasPendingWork || (isIncomingCatchUpEvent && event.type === "renderSlide"));
|
|
189
|
-
if (shouldStartCatchUp) {
|
|
190
|
-
this.setCatchUpState(true);
|
|
191
|
-
}
|
|
192
|
-
if (compactInfo) {
|
|
193
|
-
this.compactedTasks.set(event, compactInfo);
|
|
194
|
-
try {
|
|
195
|
-
(_a = this.onCompact) === null || _a === void 0 ? void 0 : _a.call(this, compactInfo);
|
|
196
|
-
}
|
|
197
|
-
catch ( /* Observability must not interrupt synchronization. */_b) { /* Observability must not interrupt synchronization. */ }
|
|
198
|
-
}
|
|
199
|
-
if (!this.isScheduling) {
|
|
200
|
-
this.schedule();
|
|
201
|
-
}
|
|
202
|
-
return compactInfo;
|
|
203
|
-
};
|
|
204
|
-
return SyncTaskManager;
|
|
205
|
-
}());
|
|
206
|
-
export { SyncTaskManager };
|