@basmilius/apple-devices 0.9.7 → 0.9.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.
Files changed (2) hide show
  1. package/dist/index.mjs +11 -8
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -1926,6 +1926,13 @@ var merge = createAssigner(function(object, source, srcIndex) {
1926
1926
 
1927
1927
  //#endregion
1928
1928
  //#region src/airplay/client.ts
1929
+ const COCOA_EPOCH_OFFSET = 978307200;
1930
+ const extrapolateElapsed = (elapsed, cocoaTimestamp, rate, isPlaying) => {
1931
+ if (!rate || !isPlaying) return elapsed;
1932
+ const timestampUnix = cocoaTimestamp + COCOA_EPOCH_OFFSET;
1933
+ const delta = (Date.now() / 1e3 - timestampUnix) * rate;
1934
+ return Math.max(0, elapsed + delta);
1935
+ };
1929
1936
  var Client = class {
1930
1937
  get bundleIdentifier() {
1931
1938
  return this.#bundleIdentifier;
@@ -1973,15 +1980,11 @@ var Client = class {
1973
1980
  return this.#supportedCommands.find((c) => c.command === Proto.Command.ChangeRepeatMode)?.repeatMode ?? Proto.RepeatMode_Enum.Unknown;
1974
1981
  }
1975
1982
  get elapsedTime() {
1976
- const meta = this.currentItemMetadata;
1977
1983
  const npi = this.#nowPlayingInfo;
1978
- const elapsedTimestamp = meta?.elapsedTimeTimestamp || 0;
1979
- const elapsed = meta?.elapsedTime || npi?.elapsedTime || 0;
1980
- if (!elapsedTimestamp) return elapsed;
1981
- if ((meta?.playbackRate ?? npi?.playbackRate ?? 0) === 0 || !this.isPlaying) return elapsed;
1982
- const timestampUnix = elapsedTimestamp + 978307200;
1983
- const diff = Date.now() / 1e3 - timestampUnix;
1984
- return Math.max(0, elapsed + diff);
1984
+ const meta = this.currentItemMetadata;
1985
+ if (npi?.elapsedTime != null && npi.timestamp) return extrapolateElapsed(npi.elapsedTime, npi.timestamp, npi.playbackRate, this.isPlaying);
1986
+ if (meta?.elapsedTime != null && meta.elapsedTimeTimestamp) return extrapolateElapsed(meta.elapsedTime, meta.elapsedTimeTimestamp, meta.playbackRate, this.isPlaying);
1987
+ return npi?.elapsedTime || meta?.elapsedTime || 0;
1985
1988
  }
1986
1989
  get currentItem() {
1987
1990
  if (!this.#playbackQueue || this.#playbackQueue.contentItems.length === 0) return null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basmilius/apple-devices",
3
3
  "description": "Exposes various Apple devices to connect with either AirPlay or Companion Link.",
4
- "version": "0.9.7",
4
+ "version": "0.9.8",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -49,10 +49,10 @@
49
49
  }
50
50
  },
51
51
  "dependencies": {
52
- "@basmilius/apple-airplay": "0.9.7",
53
- "@basmilius/apple-common": "0.9.7",
54
- "@basmilius/apple-companion-link": "0.9.7",
55
- "@basmilius/apple-encoding": "0.9.7"
52
+ "@basmilius/apple-airplay": "0.9.8",
53
+ "@basmilius/apple-common": "0.9.8",
54
+ "@basmilius/apple-companion-link": "0.9.8",
55
+ "@basmilius/apple-encoding": "0.9.8"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/bun": "^1.3.9",