@basmilius/apple-devices 0.9.12 → 0.9.13

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
@@ -140,6 +140,7 @@ type EventMap$4 = {
140
140
  readonly clients: [Record<string, Client>];
141
141
  readonly deviceInfo: [Proto.DeviceInfoMessage];
142
142
  readonly deviceInfoUpdate: [Proto.DeviceInfoMessage];
143
+ readonly nowPlayingChanged: [client: Client | null, player: Player | null];
143
144
  readonly originClientProperties: [Proto.OriginClientPropertiesMessage];
144
145
  readonly playerClientProperties: [Proto.PlayerClientPropertiesMessage];
145
146
  readonly removeClient: [Proto.RemoveClientMessage];
package/dist/index.mjs CHANGED
@@ -482,6 +482,7 @@ var state_default = class extends EventEmitter {
482
482
  #device;
483
483
  #clients;
484
484
  #nowPlayingClientBundleIdentifier;
485
+ #nowPlayingSnapshot;
485
486
  #outputDeviceUID;
486
487
  #outputDevices = [];
487
488
  #volume;
@@ -561,6 +562,7 @@ var state_default = class extends EventEmitter {
561
562
  clear() {
562
563
  this.#clients = {};
563
564
  this.#nowPlayingClientBundleIdentifier = null;
565
+ this.#nowPlayingSnapshot = null;
564
566
  this.#outputDeviceUID = null;
565
567
  this.#outputDevices = [];
566
568
  this.#volume = 0;
@@ -587,10 +589,12 @@ var state_default = class extends EventEmitter {
587
589
  }
588
590
  onRemoveClient(message) {
589
591
  if (!(message.client.bundleIdentifier in this.#clients)) return;
592
+ const wasActive = this.#nowPlayingClientBundleIdentifier === message.client.bundleIdentifier;
590
593
  delete this.#clients[message.client.bundleIdentifier];
591
- if (this.#nowPlayingClientBundleIdentifier === message.client.bundleIdentifier) this.#nowPlayingClientBundleIdentifier = null;
594
+ if (wasActive) this.#nowPlayingClientBundleIdentifier = null;
592
595
  this.emit("removeClient", message);
593
596
  this.emit("clients", this.#clients);
597
+ if (wasActive) this.#emitNowPlayingChangedIfNeeded();
594
598
  }
595
599
  onSendCommandResult(message) {
596
600
  this.emit("sendCommandResult", message);
@@ -605,6 +609,7 @@ var state_default = class extends EventEmitter {
605
609
  onSetNowPlayingClient(message) {
606
610
  this.#nowPlayingClientBundleIdentifier = message.client?.bundleIdentifier ?? null;
607
611
  this.emit("setNowPlayingClient", message);
612
+ this.#emitNowPlayingChangedIfNeeded();
608
613
  }
609
614
  onSetNowPlayingPlayer(message) {
610
615
  if (message.playerPath?.client?.bundleIdentifier && message.playerPath?.player?.identifier) {
@@ -613,9 +618,11 @@ var state_default = class extends EventEmitter {
613
618
  client.setActivePlayer(message.playerPath.player.identifier);
614
619
  }
615
620
  this.emit("setNowPlayingPlayer", message);
621
+ this.#emitNowPlayingChangedIfNeeded();
616
622
  }
617
623
  onSetState(message) {
618
- const client = this.#client(message.playerPath.client.bundleIdentifier, message.displayName);
624
+ const bundleIdentifier = message.playerPath.client.bundleIdentifier;
625
+ const client = this.#client(bundleIdentifier, message.displayName);
619
626
  const playerIdentifier = message.playerPath?.player?.identifier || "MediaRemote-DefaultPlayer";
620
627
  const player = client.getOrCreatePlayer(playerIdentifier, message.playerPath?.player?.displayName);
621
628
  if (message.nowPlayingInfo) player.setNowPlayingInfo(message.nowPlayingInfo);
@@ -623,13 +630,16 @@ var state_default = class extends EventEmitter {
623
630
  if (message.supportedCommands) player.setSupportedCommands(message.supportedCommands.supportedCommands);
624
631
  if (message.playbackQueue) player.setPlaybackQueue(message.playbackQueue);
625
632
  this.emit("setState", message);
633
+ if (bundleIdentifier === this.#nowPlayingClientBundleIdentifier) this.#emitNowPlayingChangedIfNeeded();
626
634
  }
627
635
  onUpdateContentItem(message) {
628
- const client = this.#client(message.playerPath.client.bundleIdentifier, message.playerPath.client.displayName);
636
+ const bundleIdentifier = message.playerPath.client.bundleIdentifier;
637
+ const client = this.#client(bundleIdentifier, message.playerPath.client.displayName);
629
638
  const playerIdentifier = message.playerPath?.player?.identifier || "MediaRemote-DefaultPlayer";
630
639
  const player = client.getOrCreatePlayer(playerIdentifier, message.playerPath?.player?.displayName);
631
640
  for (const item of message.contentItems) player.updateContentItem(item);
632
641
  this.emit("updateContentItem", message);
642
+ if (bundleIdentifier === this.#nowPlayingClientBundleIdentifier) this.#emitNowPlayingChangedIfNeeded();
633
643
  }
634
644
  onUpdateContentItemArtwork(message) {
635
645
  this.emit("updateContentItemArtwork", message);
@@ -644,6 +654,7 @@ var state_default = class extends EventEmitter {
644
654
  if (client) client.removePlayer(message.playerPath.player.identifier);
645
655
  }
646
656
  this.emit("removePlayer", message);
657
+ if (message.playerPath?.client?.bundleIdentifier === this.#nowPlayingClientBundleIdentifier) this.#emitNowPlayingChangedIfNeeded();
647
658
  }
648
659
  onUpdateClient(message) {
649
660
  this.#client(message.client.bundleIdentifier, message.client.displayName);
@@ -676,6 +687,38 @@ var state_default = class extends EventEmitter {
676
687
  return client;
677
688
  }
678
689
  }
690
+ #createNowPlayingSnapshot() {
691
+ const client = this.nowPlayingClient;
692
+ const player = client?.activePlayer ?? null;
693
+ return {
694
+ bundleIdentifier: client?.bundleIdentifier ?? null,
695
+ playerIdentifier: player?.identifier ?? null,
696
+ playbackState: player?.playbackState ?? Proto.PlaybackState_Enum.Unknown,
697
+ title: player?.title ?? "",
698
+ artist: player?.artist ?? "",
699
+ album: player?.album ?? "",
700
+ genre: player?.genre ?? "",
701
+ duration: player?.duration ?? 0,
702
+ shuffleMode: player?.shuffleMode ?? Proto.ShuffleMode_Enum.Unknown,
703
+ repeatMode: player?.repeatMode ?? Proto.RepeatMode_Enum.Unknown,
704
+ mediaType: player?.mediaType ?? Proto.ContentItemMetadata_MediaType.UnknownMediaType,
705
+ seriesName: player?.seriesName ?? "",
706
+ seasonNumber: player?.seasonNumber ?? 0,
707
+ episodeNumber: player?.episodeNumber ?? 0,
708
+ contentIdentifier: player?.contentIdentifier ?? ""
709
+ };
710
+ }
711
+ #emitNowPlayingChangedIfNeeded() {
712
+ const snapshot = this.#createNowPlayingSnapshot();
713
+ const previous = this.#nowPlayingSnapshot;
714
+ if (previous && this.#snapshotsEqual(previous, snapshot)) return;
715
+ this.#nowPlayingSnapshot = snapshot;
716
+ const client = this.nowPlayingClient;
717
+ this.emit("nowPlayingChanged", client, client?.activePlayer ?? null);
718
+ }
719
+ #snapshotsEqual(a, b) {
720
+ return a.bundleIdentifier === b.bundleIdentifier && a.playerIdentifier === b.playerIdentifier && a.playbackState === b.playbackState && a.title === b.title && a.artist === b.artist && a.album === b.album && a.genre === b.genre && a.duration === b.duration && a.shuffleMode === b.shuffleMode && a.repeatMode === b.repeatMode && a.mediaType === b.mediaType && a.seriesName === b.seriesName && a.seasonNumber === b.seasonNumber && a.episodeNumber === b.episodeNumber && a.contentIdentifier === b.contentIdentifier;
721
+ }
679
722
  };
680
723
 
681
724
  //#endregion
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.12",
4
+ "version": "0.9.13",
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.12",
53
- "@basmilius/apple-common": "0.9.12",
54
- "@basmilius/apple-companion-link": "0.9.12",
55
- "@basmilius/apple-encoding": "0.9.12"
52
+ "@basmilius/apple-airplay": "0.9.13",
53
+ "@basmilius/apple-common": "0.9.13",
54
+ "@basmilius/apple-companion-link": "0.9.13",
55
+ "@basmilius/apple-encoding": "0.9.13"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/bun": "^1.3.9",