@basmilius/apple-devices 0.9.6 → 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.
package/dist/index.d.mts CHANGED
@@ -21,6 +21,8 @@ declare class Client {
21
21
  get duration(): number;
22
22
  get playbackRate(): number;
23
23
  get isPlaying(): boolean;
24
+ get shuffleMode(): Proto.ShuffleMode_Enum;
25
+ get repeatMode(): Proto.RepeatMode_Enum;
24
26
  get elapsedTime(): number;
25
27
  get currentItem(): Proto.ContentItem | null;
26
28
  get currentItemMetadata(): Proto.ContentItemMetadata | null;
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;
@@ -1966,16 +1973,18 @@ var Client = class {
1966
1973
  get isPlaying() {
1967
1974
  return this.#playbackState === Proto.PlaybackState_Enum.Playing;
1968
1975
  }
1976
+ get shuffleMode() {
1977
+ return this.#supportedCommands.find((c) => c.command === Proto.Command.ChangeShuffleMode)?.shuffleMode ?? Proto.ShuffleMode_Enum.Unknown;
1978
+ }
1979
+ get repeatMode() {
1980
+ return this.#supportedCommands.find((c) => c.command === Proto.Command.ChangeRepeatMode)?.repeatMode ?? Proto.RepeatMode_Enum.Unknown;
1981
+ }
1969
1982
  get elapsedTime() {
1970
- const meta = this.currentItemMetadata;
1971
1983
  const npi = this.#nowPlayingInfo;
1972
- const elapsedTimestamp = meta?.elapsedTimeTimestamp || 0;
1973
- const elapsed = meta?.elapsedTime || npi?.elapsedTime || 0;
1974
- if (!elapsedTimestamp) return elapsed;
1975
- if ((meta?.playbackRate ?? npi?.playbackRate ?? 0) === 0 || !this.isPlaying) return elapsed;
1976
- const timestampUnix = elapsedTimestamp + 978307200;
1977
- const diff = Date.now() / 1e3 - timestampUnix;
1978
- 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;
1979
1988
  }
1980
1989
  get currentItem() {
1981
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.6",
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.6",
53
- "@basmilius/apple-common": "0.9.6",
54
- "@basmilius/apple-companion-link": "0.9.6",
55
- "@basmilius/apple-encoding": "0.9.6"
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",