@netless/slide 1.4.55-alpha.4 → 1.4.55-alpha.6

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.
@@ -0,0 +1,18 @@
1
+ export function captureFrozenMediaTimes(mediaState, frozenTime) {
2
+ var frozenMediaTimes = Object.create(null);
3
+ for (var key in mediaState) {
4
+ if (mediaState[key].type === "play") {
5
+ frozenMediaTimes[key] = frozenTime;
6
+ }
7
+ }
8
+ return frozenMediaTimes;
9
+ }
10
+ export function applyFrozenMediaTimes(mediaState, frozenMediaTimes, releaseTime) {
11
+ for (var key in mediaState) {
12
+ var media = mediaState[key];
13
+ var frozenTime = frozenMediaTimes[key];
14
+ if (media.type === "play" && frozenTime !== undefined) {
15
+ media.time = releaseTime - (Math.max(frozenTime, media.time) - media.time);
16
+ }
17
+ }
18
+ }
package/lib/Lock.js CHANGED
@@ -4,6 +4,8 @@
4
4
  var Lock = /** @class */ (function () {
5
5
  function Lock(available) {
6
6
  this.autoUnlock = Object.create(null);
7
+ this.localKeyAutoRemove = Object.create(null);
8
+ this.localKeys = Object.create(null);
7
9
  this.locks = Object.create(null);
8
10
  this.available = false;
9
11
  this.available = available;
@@ -14,18 +16,32 @@ var Lock = /** @class */ (function () {
14
16
  return;
15
17
  }
16
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);
17
24
  this.autoUnlock[type] = window.setTimeout(function () {
18
25
  delete _this.locks[type];
26
+ delete _this.autoUnlock[type];
19
27
  }, 3000);
20
28
  };
21
29
  Lock.prototype.unlock = function (type, key) {
22
30
  if (!this.available) {
23
- return;
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];
24
38
  }
25
39
  if (key && this.locks[type] && this.locks[type] === key) {
26
40
  window.clearTimeout(this.autoUnlock[type]);
27
41
  delete this.locks[type];
42
+ delete this.autoUnlock[type];
28
43
  }
44
+ return isLocalEvent;
29
45
  };
30
46
  Lock.prototype.isLocked = function (type) {
31
47
  if (!this.available) {