webamp 0.0.0-next-c1d68b5 → 0.0.0-next-a618b04

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.
@@ -4,9 +4,11 @@ import { IMedia } from "../media";
4
4
  interface Props {
5
5
  filePickers: FilePicker[];
6
6
  media: IMedia;
7
+ parentDomNode: HTMLElement;
8
+ onMount?: () => void;
7
9
  }
8
10
  /**
9
11
  * Constructs the windows to render
10
12
  */
11
- export default function App({ media, filePickers }: Props): import("react").ReactPortal | null;
13
+ export default function App({ media, filePickers, onMount, parentDomNode, }: Props): import("react").ReactPortal | null;
12
14
  export {};
@@ -30,35 +30,35 @@ declare class Webamp {
30
30
  static browserIsSupported(): boolean;
31
31
  constructor(options: Options & PrivateOptions & InjectableDependencies);
32
32
  /**
33
- * Play the current tack
33
+ * Play the current track.
34
34
  */
35
35
  play(): void;
36
36
  /**
37
- * Pause the current tack
37
+ * Pause the current track.
38
38
  */
39
39
  pause(): void;
40
40
  /**
41
- * Stop the currently playing audio. Equivalent to pressing the "stop" button
41
+ * Stop the currently playing audio. Equivalent to pressing the "stop" button.
42
42
  */
43
43
  stop(): void;
44
44
  /**
45
- * Set volume from 0 - 100
45
+ * Set volume from 0 - 100.
46
46
  */
47
47
  setVolume(volume: number): void;
48
48
  /**
49
- * Seek backward n seconds in the current track
49
+ * Seek backward n seconds in the current track.
50
50
  */
51
51
  seekBackward(seconds: number): void;
52
52
  /**
53
- * Seek forward n seconds in the current track
53
+ * Seek forward n seconds in the current track.
54
54
  */
55
55
  seekForward(seconds: number): void;
56
56
  /**
57
- * Seek to a given time within the current track
57
+ * Seek to a given time within the current track.
58
58
  */
59
59
  seekToTime(seconds: number): void;
60
60
  /**
61
- * Check if shuffle is enabled
61
+ * Check if shuffle is enabled.
62
62
  */
63
63
  isShuffleEnabled(): boolean;
64
64
  /**
@@ -66,7 +66,7 @@ declare class Webamp {
66
66
  */
67
67
  toggleShuffle(): void;
68
68
  /**
69
- * Check if repeat is enabled
69
+ * Check if repeat is enabled.
70
70
  */
71
71
  isRepeatEnabled(): boolean;
72
72
  /**
@@ -74,15 +74,15 @@ declare class Webamp {
74
74
  */
75
75
  toggleRepeat(): void;
76
76
  /**
77
- * Play the next track
77
+ * Play the next track.
78
78
  */
79
79
  nextTrack(): void;
80
80
  /**
81
- * Play the previous track
81
+ * Play the previous track.
82
82
  */
83
83
  previousTrack(): void;
84
84
  /**
85
- * Set the current track a specific track in the playlist by zero-based index.
85
+ * Set the current track to a specific track in the playlist by zero-based index.
86
86
  *
87
87
  * Note: If Webamp is currently playing, the track will begin playing. If
88
88
  * Webamp is not playing, the track will not start playing. You can use
@@ -121,7 +121,7 @@ declare class Webamp {
121
121
  */
122
122
  onClose(cb: () => void): () => void;
123
123
  /**
124
- * Equivalent to selection "Close" from Webamp's options menu. Once closed,
124
+ * Equivalent to selecting "Close" from Webamp's options menu. Once closed,
125
125
  * you can open it again with `.reopen()`.
126
126
  */
127
127
  close(): void;
@@ -43304,7 +43304,7 @@
43304
43304
  /**
43305
43305
  * Constructs the windows to render
43306
43306
  */
43307
- function App({ media, filePickers }) {
43307
+ function App({ media, filePickers, onMount, parentDomNode, }) {
43308
43308
  const closed = useTypedSelector(getClosed);
43309
43309
  const genWindowsInfo = useTypedSelector(getGenWindows);
43310
43310
  const zIndex = useTypedSelector(getZIndex);
@@ -43321,11 +43321,11 @@
43321
43321
  webampNode.style.zIndex = String(zIndex);
43322
43322
  }, [webampNode, zIndex]);
43323
43323
  reactExports.useLayoutEffect(() => {
43324
- document.body.appendChild(webampNode);
43324
+ parentDomNode.appendChild(webampNode);
43325
43325
  return () => {
43326
- document.body.removeChild(webampNode);
43326
+ parentDomNode.removeChild(webampNode);
43327
43327
  };
43328
- }, [webampNode]);
43328
+ }, [webampNode, parentDomNode]);
43329
43329
  reactExports.useEffect(() => {
43330
43330
  const handleWindowResize = () => {
43331
43331
  if (webampNode == null) {
@@ -43353,6 +43353,11 @@
43353
43353
  window.removeEventListener("resize", handleWindowResize);
43354
43354
  };
43355
43355
  }, [browserWindowSizeChanged$1, webampNode]);
43356
+ reactExports.useEffect(() => {
43357
+ if (onMount != null) {
43358
+ onMount();
43359
+ }
43360
+ }, [onMount]);
43356
43361
  const renderWindows = reactExports.useCallback(() => {
43357
43362
  return objectMap(genWindowsInfo, (w, id) => {
43358
43363
  if (!w.open) {
@@ -44069,10 +44074,7 @@
44069
44074
  this._actionEmitter = new Emitter();
44070
44075
  this.options = options;
44071
44076
  const { initialTracks, initialSkin, availableSkins, enableHotkeys = false, zIndex, requireJSZip, requireMusicMetadata, handleTrackDropEvent, handleAddUrlEvent, handleLoadListEvent, handleSaveListEvent, enableDoubleSizeMode, __butterchurnOptions, __customMediaClass, } = this.options;
44072
- if (options.enableMediaSession) {
44073
- enableMediaSession(this);
44074
- }
44075
- // TODO: Make this much cleaner
44077
+ // TODO: Make this much cleaner.
44076
44078
  let convertPreset = null;
44077
44079
  if (__butterchurnOptions != null) {
44078
44080
  const { importConvertPreset, presetConverterEndpoint } = __butterchurnOptions;
@@ -44083,18 +44085,21 @@
44083
44085
  };
44084
44086
  }
44085
44087
  }
44086
- // TODO: Validate required options
44088
+ // TODO: Validate required options.
44087
44089
  this.media = new (__customMediaClass || Media)();
44088
44090
  this.store = createWebampStore(this.media, this._actionEmitter, this.options.__customMiddlewares, this.options.__initialState, {
44089
44091
  requireJSZip,
44090
44092
  requireMusicMetadata,
44091
44093
  convertPreset,
44092
- // @ts-ignore Typescript is drunk
44094
+ // @ts-ignore Typescript is drunk.
44093
44095
  handleTrackDropEvent,
44094
44096
  handleAddUrlEvent,
44095
44097
  handleLoadListEvent,
44096
44098
  handleSaveListEvent,
44097
44099
  });
44100
+ if (options.enableMediaSession) {
44101
+ enableMediaSession(this);
44102
+ }
44098
44103
  if (enableDoubleSizeMode) {
44099
44104
  this.store.dispatch(toggleDoubleSizeMode());
44100
44105
  }
@@ -44147,49 +44152,49 @@
44147
44152
  }
44148
44153
  }
44149
44154
  /**
44150
- * Play the current tack
44155
+ * Play the current track.
44151
44156
  */
44152
44157
  play() {
44153
44158
  this.store.dispatch(play());
44154
44159
  }
44155
44160
  /**
44156
- * Pause the current tack
44161
+ * Pause the current track.
44157
44162
  */
44158
44163
  pause() {
44159
44164
  this.store.dispatch(pause());
44160
44165
  }
44161
44166
  /**
44162
- * Stop the currently playing audio. Equivalent to pressing the "stop" button
44167
+ * Stop the currently playing audio. Equivalent to pressing the "stop" button.
44163
44168
  */
44164
44169
  stop() {
44165
44170
  this.store.dispatch(stop());
44166
44171
  }
44167
44172
  /**
44168
- * Set volume from 0 - 100
44173
+ * Set volume from 0 - 100.
44169
44174
  */
44170
44175
  setVolume(volume) {
44171
44176
  this.store.dispatch(setVolume(volume));
44172
44177
  }
44173
44178
  /**
44174
- * Seek backward n seconds in the current track
44179
+ * Seek backward n seconds in the current track.
44175
44180
  */
44176
44181
  seekBackward(seconds) {
44177
44182
  this.store.dispatch(seekBackward(seconds));
44178
44183
  }
44179
44184
  /**
44180
- * Seek forward n seconds in the current track
44185
+ * Seek forward n seconds in the current track.
44181
44186
  */
44182
44187
  seekForward(seconds) {
44183
44188
  this.store.dispatch(seekForward(seconds));
44184
44189
  }
44185
44190
  /**
44186
- * Seek to a given time within the current track
44191
+ * Seek to a given time within the current track.
44187
44192
  */
44188
44193
  seekToTime(seconds) {
44189
44194
  this.store.dispatch(seekToTime(seconds));
44190
44195
  }
44191
44196
  /**
44192
- * Check if shuffle is enabled
44197
+ * Check if shuffle is enabled.
44193
44198
  */
44194
44199
  isShuffleEnabled() {
44195
44200
  return getShuffle(this.store.getState());
@@ -44201,7 +44206,7 @@
44201
44206
  this.store.dispatch(toggleShuffle());
44202
44207
  }
44203
44208
  /**
44204
- * Check if repeat is enabled
44209
+ * Check if repeat is enabled.
44205
44210
  */
44206
44211
  isRepeatEnabled() {
44207
44212
  return getRepeat(this.store.getState());
@@ -44213,19 +44218,19 @@
44213
44218
  this.store.dispatch(toggleRepeat());
44214
44219
  }
44215
44220
  /**
44216
- * Play the next track
44221
+ * Play the next track.
44217
44222
  */
44218
44223
  nextTrack() {
44219
44224
  this.store.dispatch(next());
44220
44225
  }
44221
44226
  /**
44222
- * Play the previous track
44227
+ * Play the previous track.
44223
44228
  */
44224
44229
  previousTrack() {
44225
44230
  this.store.dispatch(previous());
44226
44231
  }
44227
44232
  /**
44228
- * Set the current track a specific track in the playlist by zero-based index.
44233
+ * Set the current track to a specific track in the playlist by zero-based index.
44229
44234
  *
44230
44235
  * Note: If Webamp is currently playing, the track will begin playing. If
44231
44236
  * Webamp is not playing, the track will not start playing. You can use
@@ -44281,7 +44286,7 @@
44281
44286
  return this._actionEmitter.on(CLOSE_WINAMP, cb);
44282
44287
  }
44283
44288
  /**
44284
- * Equivalent to selection "Close" from Webamp's options menu. Once closed,
44289
+ * Equivalent to selecting "Close" from Webamp's options menu. Once closed,
44285
44290
  * you can open it again with `.reopen()`.
44286
44291
  */
44287
44292
  close() {
@@ -44308,7 +44313,7 @@
44308
44313
  */
44309
44314
  onTrackDidChange(cb) {
44310
44315
  let previousTrackId = null;
44311
- // TODO #leak
44316
+ // TODO #leak.
44312
44317
  return this.store.subscribe(() => {
44313
44318
  const state = this.store.getState();
44314
44319
  const trackId = getCurrentlyPlayingTrackIdIfLoaded(state);
@@ -44344,7 +44349,7 @@
44344
44349
  */
44345
44350
  async skinIsLoaded() {
44346
44351
  // Wait for the skin to load.
44347
- // TODO #leak
44352
+ // TODO #leak.
44348
44353
  await storeHas(this.store, (state) => !state.display.loading);
44349
44354
  // We attempt to pre-resolve these promises before we declare the skin
44350
44355
  // loaded. That's because `<EqGraph>` needs these in order to render fully.
@@ -44383,7 +44388,12 @@
44383
44388
  this._root = null;
44384
44389
  }
44385
44390
  });
44386
- this._root.render(jsxRuntimeExports.jsx(Provider, { store: this.store, children: jsxRuntimeExports.jsx(App, { media: this.media, filePickers: this.options.filePickers || [] }) }));
44391
+ let onMount;
44392
+ const mountPromise = new Promise((resolve) => {
44393
+ onMount = resolve;
44394
+ });
44395
+ this._root.render(jsxRuntimeExports.jsx(Provider, { store: this.store, children: jsxRuntimeExports.jsx(App, { media: this.media, filePickers: this.options.filePickers || [], onMount: onMount, parentDomNode: document.body }) }));
44396
+ await mountPromise;
44387
44397
  }
44388
44398
  /**
44389
44399
  * **Note:** _This method is not fully functional. It is currently impossible to
@@ -44395,8 +44405,8 @@
44395
44405
  * attempt to clean itself up to avoid memory leaks.
44396
44406
  */
44397
44407
  dispose() {
44398
- // TODO: Clean up store subscription in onTrackDidChange
44399
- // TODO: Every storeHas call represents a potential race condition
44408
+ // TODO: Clean up store subscription in onTrackDidChange.
44409
+ // TODO: Every storeHas call represents a potential race condition.
44400
44410
  this.media.dispose();
44401
44411
  this._actionEmitter.dispose();
44402
44412
  this._disposable.dispose();
@@ -44408,7 +44418,7 @@
44408
44418
  return getSerlializedState(this.store.getState());
44409
44419
  }
44410
44420
  __onStateChange(cb) {
44411
- // TODO #leak
44421
+ // TODO #leak.
44412
44422
  return this.store.subscribe(cb);
44413
44423
  }
44414
44424
  _bufferTracks(tracks) {
@@ -44417,7 +44427,7 @@
44417
44427
  }
44418
44428
  };
44419
44429
  // Return a promise that resolves when the store matches a predicate.
44420
- // TODO #leak
44430
+ // TODO #leak.
44421
44431
  const storeHas = (store, predicate) => new Promise((resolve) => {
44422
44432
  if (predicate(store.getState())) {
44423
44433
  resolve();