visualfries 0.1.6 → 0.1.8

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.
@@ -50,6 +50,9 @@ export class MediaHook {
50
50
  }
51
51
  }
52
52
  async #autoSeek() {
53
+ if (!this.#mediaElement) {
54
+ return;
55
+ }
53
56
  const target = this.#context.currentComponentTime;
54
57
  const frameDuration = 1 / (this.state.data.settings.fps || 30);
55
58
  if (this.#lastTargetTime !== null &&
@@ -60,6 +63,9 @@ export class MediaHook {
60
63
  await this.#seek(target);
61
64
  }
62
65
  async #seek(time) {
66
+ if (!this.#mediaElement) {
67
+ return;
68
+ }
63
69
  const element = this.#mediaElement;
64
70
  const frameDuration = 1 / (this.state.data.settings.fps || 30);
65
71
  // Use fastSeek for larger jumps when supported
@@ -96,6 +102,9 @@ export class MediaHook {
96
102
  });
97
103
  }
98
104
  #isOutOfSync() {
105
+ if (!this.#mediaElement) {
106
+ return false;
107
+ }
99
108
  // run only once per MAX_LAG_TIME
100
109
  const now = performance.now() / 1000; // convert to seconds
101
110
  if (now - this.#lastSyncCheck < this.#MAX_LAG_TIME) {
@@ -106,11 +115,17 @@ export class MediaHook {
106
115
  return lagTime >= this.#MAX_LAG_TIME;
107
116
  }
108
117
  async #pause(reason) {
118
+ if (!this.#mediaElement) {
119
+ return;
120
+ }
109
121
  if (!this.#mediaElement.paused && !this.#playRequested) {
110
122
  this.#mediaElement.pause();
111
123
  }
112
124
  }
113
125
  async #play() {
126
+ if (!this.#mediaElement) {
127
+ return;
128
+ }
114
129
  if (this.#mediaElement.paused) {
115
130
  this.#playRequested = true;
116
131
  try {
@@ -167,6 +182,9 @@ export class MediaHook {
167
182
  }
168
183
  return;
169
184
  }
185
+ if (!this.#mediaElement) {
186
+ await this.#handleRefresh();
187
+ }
170
188
  // Make sure we're still marked as the controller (debounced)
171
189
  if (!isController && shouldCheckController) {
172
190
  // Only set controller if no other component is currently controlling this media
@@ -184,7 +202,7 @@ export class MediaHook {
184
202
  }
185
203
  // Check if component is loading using the StateManager
186
204
  if (this.state.isLoadingComponent(this.#context.contextData.id)) {
187
- if (this.#mediaElement.readyState < 2) {
205
+ if (this.#mediaElement && this.#mediaElement.readyState < 2) {
188
206
  await this.#pause('readyState < 2');
189
207
  return;
190
208
  }
@@ -193,10 +211,10 @@ export class MediaHook {
193
211
  }
194
212
  }
195
213
  // Ensure the media element matches the component's mute and volume state
196
- if (this.#mediaElement.muted != isMuted) {
214
+ if (this.#mediaElement && this.#mediaElement.muted != isMuted) {
197
215
  this.#mediaElement.muted = isMuted;
198
216
  }
199
- if (this.#mediaElement.volume != componentVolume) {
217
+ if (this.#mediaElement && this.#mediaElement.volume != componentVolume) {
200
218
  this.#mediaElement.volume = componentVolume;
201
219
  }
202
220
  const isScenePlaying = this.#context.sceneState.state === 'playing' || this.#context.sceneState.state === 'loading';
@@ -208,7 +226,7 @@ export class MediaHook {
208
226
  }
209
227
  else {
210
228
  // When scene is playing and media is paused, play media
211
- if (this.#mediaElement.paused) {
229
+ if (this.#mediaElement && this.#mediaElement.paused) {
212
230
  await this.#play();
213
231
  }
214
232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "visualfries",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "license": "MIT",
5
5
  "author": "ContentFries",
6
6
  "repository": {