timingsrc 1.2.8 → 1.2.9

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.
Files changed (2) hide show
  1. package/build/es5/bundle.js +38 -76
  2. package/package.json +11 -11
@@ -25,8 +25,8 @@
25
25
  var createSetCurrentTime = function createSetCurrentTime(currentTimeAssignments) {
26
26
  return function (mediaElement, previousValue, nextValue) {
27
27
  var currentTimeAssignment = currentTimeAssignments.get(mediaElement);
28
-
29
- if (currentTimeAssignment === undefined || // Bug #5: Safari limits the precision of the value after a while.
28
+ if (currentTimeAssignment === undefined ||
29
+ // Bug #5: Safari limits the precision of the value after a while.
30
30
  Math.abs(currentTimeAssignment[0] - previousValue) > 0.0001 || currentTimeAssignment[1] !== nextValue) {
31
31
  mediaElement.currentTime = nextValue;
32
32
  currentTimeAssignments.set(mediaElement, [mediaElement.currentTime, nextValue]);
@@ -37,7 +37,6 @@
37
37
  var createSetPlaybackRate = function createSetPlaybackRate(playbackRateAssignments) {
38
38
  return function (mediaElement, previousValue, nextValue) {
39
39
  var playbackRateAssignment = playbackRateAssignments.get(mediaElement);
40
-
41
40
  if (playbackRateAssignment === undefined || playbackRateAssignment[0] !== previousValue || playbackRateAssignment[1] !== nextValue) {
42
41
  // There is currently a bug in Firefox which causes problems when switching back to a playbackRate of exactly 1.
43
42
  mediaElement.playbackRate = nextValue === 1 ? previousValue > 1 ? 1.00001 : 0.99999 : nextValue;
@@ -57,30 +56,26 @@
57
56
  return function (mediaElement, timingObject, updateFunction) {
58
57
  var prepareTimingStateVector = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
59
58
  var previousUpdateVectorWithCustomState = null;
60
-
61
59
  var update = function update() {
62
60
  var currentTime = mediaElement.currentTime,
63
- duration = mediaElement.duration,
64
- playbackRate = mediaElement.playbackRate;
61
+ duration = mediaElement.duration,
62
+ playbackRate = mediaElement.playbackRate;
65
63
  var timingStateVector = timingObject.query();
66
64
  previousUpdateVectorWithCustomState = updateFunction(prepareTimingStateVector === null ? timingStateVector : prepareTimingStateVector(timingStateVector), currentTime, previousUpdateVectorWithCustomState);
67
65
  var sanitizedDuration = typeof duration === 'number' && !isNaN(duration) ? duration : 0;
68
66
  var _previousUpdateVector = previousUpdateVectorWithCustomState,
69
- position = _previousUpdateVector.position,
70
- velocity = _previousUpdateVector.velocity;
67
+ position = _previousUpdateVector.position,
68
+ velocity = _previousUpdateVector.velocity;
71
69
  updateMediaElement(currentTime, sanitizedDuration, mediaElement, playbackRate, position, velocity);
72
70
  return velocity !== 0;
73
71
  };
74
-
75
72
  var unsubscribe;
76
-
77
73
  var updateOnce = function updateOnce() {
78
74
  if (!update()) {
79
75
  unsubscribe();
80
76
  unsubscribe = updateReactively();
81
77
  }
82
78
  };
83
-
84
79
  var updateConsistently = function updateConsistently() {
85
80
  var unsubscribeFunctions = [animationFrame()(function () {
86
81
  return updateOnce();
@@ -95,7 +90,6 @@
95
90
  });
96
91
  };
97
92
  };
98
-
99
93
  var updateReactively = function updateReactively() {
100
94
  return on(timingObject, 'change')(function () {
101
95
  if (update()) {
@@ -104,7 +98,6 @@
104
98
  }
105
99
  });
106
100
  };
107
-
108
101
  unsubscribe = update() ? updateConsistently() : updateReactively();
109
102
  return function () {
110
103
  return unsubscribe();
@@ -114,18 +107,15 @@
114
107
 
115
108
  var createUpdateGradually = function createUpdateGradually(computeVelocity, _ref, threshold, tolerance, updateVectorWithNewPosition) {
116
109
  var _ref2 = _slicedToArray__default["default"](_ref, 2),
117
- minValue = _ref2[0],
118
- maxValue = _ref2[1];
119
-
110
+ minValue = _ref2[0],
111
+ maxValue = _ref2[1];
120
112
  return function (_ref3, currentTime, previousUpdateVectorWithCustomState) {
121
113
  var position = _ref3.position,
122
- velocity = _ref3.velocity;
123
-
114
+ velocity = _ref3.velocity;
124
115
  var _ref4 = previousUpdateVectorWithCustomState !== null && previousUpdateVectorWithCustomState !== void 0 ? previousUpdateVectorWithCustomState : {
125
- mediaElementDelay: 0
126
- },
127
- mediaElementDelay = _ref4.mediaElementDelay;
128
-
116
+ mediaElementDelay: 0
117
+ },
118
+ mediaElementDelay = _ref4.mediaElementDelay;
129
119
  if (velocity < minValue || velocity > maxValue) {
130
120
  return {
131
121
  mediaElementDelay: mediaElementDelay,
@@ -133,7 +123,6 @@
133
123
  velocity: 0
134
124
  };
135
125
  }
136
-
137
126
  if (position < 0 || velocity === 0) {
138
127
  return {
139
128
  mediaElementDelay: mediaElementDelay,
@@ -141,33 +130,27 @@
141
130
  velocity: velocity
142
131
  };
143
132
  }
144
-
145
133
  var positionDifference = currentTime - position;
146
134
  var absolutePositionDifference = Math.abs(positionDifference);
147
-
148
135
  if (absolutePositionDifference > threshold) {
149
136
  var _ref5 = previousUpdateVectorWithCustomState !== null && previousUpdateVectorWithCustomState !== void 0 ? previousUpdateVectorWithCustomState : {
150
- position: null
151
- },
152
- lastPosition = _ref5.position;
153
-
137
+ position: null
138
+ },
139
+ lastPosition = _ref5.position;
154
140
  if (positionDifference < 0 || positionDifference > mediaElementDelay) {
155
141
  if (lastPosition === currentTime) {
156
142
  mediaElementDelay += absolutePositionDifference;
157
143
  }
158
-
159
144
  return updateVectorWithNewPosition(mediaElementDelay, position, function (nextPosition) {
160
145
  return computeVelocity(nextPosition - position, minValue, maxValue, velocity);
161
146
  });
162
147
  }
163
-
164
148
  if (lastPosition !== currentTime) {
165
149
  return updateVectorWithNewPosition(mediaElementDelay - absolutePositionDifference, position, function (nextPosition) {
166
150
  return computeVelocity(nextPosition - position, minValue, maxValue, velocity);
167
151
  });
168
152
  }
169
153
  }
170
-
171
154
  if (absolutePositionDifference > tolerance) {
172
155
  return {
173
156
  mediaElementDelay: mediaElementDelay,
@@ -175,7 +158,6 @@
175
158
  velocity: computeVelocity(positionDifference, minValue, maxValue, velocity)
176
159
  };
177
160
  }
178
-
179
161
  return {
180
162
  mediaElementDelay: mediaElementDelay,
181
163
  position: currentTime,
@@ -190,22 +172,18 @@
190
172
  if (currentTime > 0) {
191
173
  setCurrentTime(mediaElement, currentTime, 0);
192
174
  }
193
-
194
175
  pause(mediaElement);
195
176
  } else if (position >= duration) {
196
177
  if (currentTime !== duration) {
197
178
  setCurrentTime(mediaElement, currentTime, duration);
198
179
  }
199
-
200
180
  pause(mediaElement);
201
181
  } else if (currentTime !== position) {
202
182
  setCurrentTime(mediaElement, currentTime, position);
203
-
204
183
  if (velocity !== 0) {
205
184
  if (playbackRate !== velocity) {
206
185
  setPlaybackRate(mediaElement, playbackRate, velocity);
207
186
  }
208
-
209
187
  play(mediaElement);
210
188
  } else {
211
189
  pause(mediaElement);
@@ -226,22 +204,21 @@
226
204
  return function (tolerance) {
227
205
  return function (timingStateVector, currentTime, previousUpdateVectorWithCustomState) {
228
206
  var _ref = previousUpdateVectorWithCustomState !== null && previousUpdateVectorWithCustomState !== void 0 ? previousUpdateVectorWithCustomState : {
229
- lastAppliedPostion: 0,
230
- lastAppliedTimestamp: 0,
231
- lastAppliedVelocity: 0,
232
- lastPlayheadDifference: 0,
233
- mediaElementDelay: 0,
234
- numberOfDetectedResets: 0,
235
- numberOfExpectedResets: 1
236
- },
237
- lastAppliedPostion = _ref.lastAppliedPostion,
238
- lastAppliedTimestamp = _ref.lastAppliedTimestamp,
239
- lastAppliedVelocity = _ref.lastAppliedVelocity,
240
- lastPlayheadDifference = _ref.lastPlayheadDifference,
241
- mediaElementDelay = _ref.mediaElementDelay,
242
- numberOfDetectedResets = _ref.numberOfDetectedResets,
243
- numberOfExpectedResets = _ref.numberOfExpectedResets;
244
-
207
+ lastAppliedPostion: 0,
208
+ lastAppliedTimestamp: 0,
209
+ lastAppliedVelocity: 0,
210
+ lastPlayheadDifference: 0,
211
+ mediaElementDelay: 0,
212
+ numberOfDetectedResets: 0,
213
+ numberOfExpectedResets: 1
214
+ },
215
+ lastAppliedPostion = _ref.lastAppliedPostion,
216
+ lastAppliedTimestamp = _ref.lastAppliedTimestamp,
217
+ lastAppliedVelocity = _ref.lastAppliedVelocity,
218
+ lastPlayheadDifference = _ref.lastPlayheadDifference,
219
+ mediaElementDelay = _ref.mediaElementDelay,
220
+ numberOfDetectedResets = _ref.numberOfDetectedResets,
221
+ numberOfExpectedResets = _ref.numberOfExpectedResets;
245
222
  if (timingStateVector.position < 0 || timingStateVector.velocity === 0) {
246
223
  lastAppliedPostion = timingStateVector.position;
247
224
  lastAppliedVelocity = timingStateVector.velocity;
@@ -256,16 +233,13 @@
256
233
  position: lastAppliedPostion,
257
234
  velocity: lastAppliedVelocity
258
235
  };
259
- } // Bug #4: Safari decreases currentTime after playing for about 200 milliseconds.
260
-
261
-
236
+ }
237
+ // Bug #4: Safari decreases currentTime after playing for about 200 milliseconds.
262
238
  if (lastAppliedVelocity === timingStateVector.velocity && lastPlayheadDifference < MAXIMUM_PLAYHEAD_DIFFERENCE) {
263
239
  var playheadDifference = Math.abs(currentTime - lastAppliedPostion) * lastAppliedVelocity;
264
-
265
240
  if (playheadDifference < MAXIMUM_PLAYHEAD_DIFFERENCE) {
266
241
  if (playheadDifference + 0.001 > lastPlayheadDifference) {
267
242
  lastPlayheadDifference = playheadDifference;
268
-
269
243
  if (numberOfDetectedResets < numberOfExpectedResets) {
270
244
  return {
271
245
  lastAppliedPostion: lastAppliedPostion,
@@ -282,7 +256,6 @@
282
256
  } else {
283
257
  lastPlayheadDifference = playheadDifference;
284
258
  numberOfDetectedResets += 1;
285
-
286
259
  if (numberOfDetectedResets <= numberOfExpectedResets) {
287
260
  return {
288
261
  lastAppliedPostion: lastAppliedPostion,
@@ -296,7 +269,6 @@
296
269
  velocity: lastAppliedVelocity
297
270
  };
298
271
  }
299
-
300
272
  numberOfExpectedResets += 1;
301
273
  }
302
274
  } else {
@@ -306,25 +278,20 @@
306
278
  } else {
307
279
  lastAppliedTimestamp = 0;
308
280
  }
309
-
310
281
  var positionDifference = Math.abs(currentTime - timingStateVector.position);
311
282
  var velocityHasChanged = lastAppliedVelocity === 0 || lastAppliedVelocity < 0 && timingStateVector.velocity > 0 || lastAppliedVelocity > 0 && timingStateVector.velocity < 0;
312
-
313
283
  if (positionDifference > tolerance || velocityHasChanged) {
314
284
  if (lastAppliedTimestamp > 0) {
315
285
  var elapsedTime = timingStateVector.timestamp - lastAppliedTimestamp;
316
-
317
286
  var _translateTimingState = translateTimingStateVector({
318
- acceleration: 0,
319
- position: lastAppliedPostion,
320
- timestamp: lastAppliedTimestamp,
321
- velocity: lastAppliedVelocity
322
- }, elapsedTime),
323
- position = _translateTimingState.position;
324
-
287
+ acceleration: 0,
288
+ position: lastAppliedPostion,
289
+ timestamp: lastAppliedTimestamp,
290
+ velocity: lastAppliedVelocity
291
+ }, elapsedTime),
292
+ position = _translateTimingState.position;
325
293
  mediaElementDelay = position - currentTime;
326
294
  }
327
-
328
295
  lastAppliedPostion = timingStateVector.position + mediaElementDelay;
329
296
  lastAppliedVelocity = timingStateVector.velocity;
330
297
  return {
@@ -339,7 +306,6 @@
339
306
  velocity: lastAppliedVelocity
340
307
  };
341
308
  }
342
-
343
309
  return {
344
310
  lastAppliedPostion: lastAppliedPostion,
345
311
  lastAppliedTimestamp: lastAppliedTimestamp,
@@ -364,9 +330,7 @@
364
330
  if (window === null) {
365
331
  return DEFAULT_VALUES;
366
332
  }
367
-
368
333
  var audio = new window.Audio();
369
-
370
334
  try {
371
335
  // Bug #2: Chrome does not support values above 16.
372
336
  audio.playbackRate = 17;
@@ -374,14 +338,12 @@
374
338
  // Bug #1: Chrome does not support values below 0.625.
375
339
  return [0.625, 16];
376
340
  }
377
-
378
341
  try {
379
342
  // Bug #3: Firefox does not support negative values.
380
343
  audio.playbackRate = -1;
381
344
  } catch (_unused2) {
382
345
  return [0, DEFAULT_VALUES[1]];
383
346
  }
384
-
385
347
  return DEFAULT_VALUES;
386
348
  };
387
349
 
package/package.json CHANGED
@@ -9,24 +9,24 @@
9
9
  }
10
10
  },
11
11
  "dependencies": {
12
- "@babel/runtime": "^7.19.0",
13
- "subscribable-things": "^2.1.7",
14
- "timing-object": "^3.1.48",
12
+ "@babel/runtime": "^7.19.4",
13
+ "subscribable-things": "^2.1.8",
14
+ "timing-object": "^3.1.49",
15
15
  "tslib": "^2.4.0"
16
16
  },
17
17
  "description": "A library to synchronize a MediaElement with a TimingObject.",
18
18
  "devDependencies": {
19
- "@babel/core": "^7.19.1",
19
+ "@babel/core": "^7.19.6",
20
20
  "@babel/plugin-external-helpers": "^7.18.6",
21
- "@babel/plugin-transform-runtime": "^7.19.1",
22
- "@babel/preset-env": "^7.19.1",
21
+ "@babel/plugin-transform-runtime": "^7.19.6",
22
+ "@babel/preset-env": "^7.19.4",
23
23
  "@commitlint/cli": "^17.1.2",
24
24
  "@commitlint/config-angular": "^17.1.0",
25
25
  "@rollup/plugin-babel": "^5.3.1",
26
26
  "chai": "^4.3.6",
27
27
  "commitizen": "^4.2.5",
28
28
  "cz-conventional-changelog": "^3.3.0",
29
- "eslint": "^8.23.1",
29
+ "eslint": "^8.26.0",
30
30
  "eslint-config-holy-grail": "^52.0.33",
31
31
  "grunt": "^1.5.3",
32
32
  "grunt-cli": "^1.4.3",
@@ -41,18 +41,18 @@
41
41
  "karma-sinon-chai": "^2.0.2",
42
42
  "karma-webpack": "^5.0.0",
43
43
  "load-grunt-config": "^4.0.1",
44
- "mocha": "^10.0.0",
44
+ "mocha": "^10.1.0",
45
45
  "prettier": "^2.7.1",
46
46
  "pretty-quick": "^3.1.3",
47
47
  "rimraf": "^3.0.2",
48
48
  "rollup": "^2.79.1",
49
- "sinon": "^14.0.0",
49
+ "sinon": "^14.0.1",
50
50
  "sinon-chai": "^3.7.0",
51
51
  "ts-loader": "^9.4.1",
52
52
  "tsconfig-holy-grail": "^11.1.36",
53
53
  "tslint": "^6.1.3",
54
54
  "tslint-config-holy-grail": "^53.2.33",
55
- "typescript": "^4.8.3",
55
+ "typescript": "^4.8.4",
56
56
  "webpack": "^5.74.0"
57
57
  },
58
58
  "files": [
@@ -75,5 +75,5 @@
75
75
  "test": "grunt lint && grunt test"
76
76
  },
77
77
  "types": "build/es2019/module.d.ts",
78
- "version": "1.2.8"
78
+ "version": "1.2.9"
79
79
  }