alphatheta-connect 0.28.2 → 0.28.5

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.
@@ -1,5 +1,10 @@
1
1
  import { Device } from "../types";
2
2
  /**
3
3
  * Converts a announce packet to a device object.
4
+ *
5
+ * Returns null for any packet that is not a stage-3 Pro DJ Link announce. The
6
+ * announce socket receives every UDP broadcast on its port, so foreign traffic
7
+ * (other apps, other protocols) is normal and must be ignored, not treated as
8
+ * an error.
4
9
  */
5
10
  export declare function deviceFromPacket(packet: Buffer): Device | null;
package/lib/index.js CHANGED
@@ -2127,7 +2127,16 @@ class DeviceManager {
2127
2127
  this.off = __classPrivateFieldGet(this, _DeviceManager_emitter, "f").removeListener.bind(__classPrivateFieldGet(this, _DeviceManager_emitter, "f"));
2128
2128
  this.once = __classPrivateFieldGet(this, _DeviceManager_emitter, "f").once.bind(__classPrivateFieldGet(this, _DeviceManager_emitter, "f"));
2129
2129
  _DeviceManager_handleAnnounce.set(this, (message) => {
2130
- const device = (0, utils_1.deviceFromPacket)(message);
2130
+ // This runs on every UDP datagram the announce socket receives, so a parse
2131
+ // failure here would surface as an uncaught exception on the socket and
2132
+ // crash the process. Foreign or truncated packets are ignored instead.
2133
+ let device;
2134
+ try {
2135
+ device = (0, utils_1.deviceFromPacket)(message);
2136
+ }
2137
+ catch {
2138
+ return;
2139
+ }
2131
2140
  if (device === null) {
2132
2141
  return;
2133
2142
  }
@@ -2243,10 +2252,15 @@ const ip = __importStar(__webpack_require__(/*! ip-address */ "ip-address"));
2243
2252
  const constants_1 = __webpack_require__(/*! src/constants */ "./src/constants.ts");
2244
2253
  /**
2245
2254
  * Converts a announce packet to a device object.
2255
+ *
2256
+ * Returns null for any packet that is not a stage-3 Pro DJ Link announce. The
2257
+ * announce socket receives every UDP broadcast on its port, so foreign traffic
2258
+ * (other apps, other protocols) is normal and must be ignored, not treated as
2259
+ * an error.
2246
2260
  */
2247
2261
  function deviceFromPacket(packet) {
2248
2262
  if (packet.indexOf(constants_1.PROLINK_HEADER) !== 0) {
2249
- throw new Error('Announce packet does not start with expected header');
2263
+ return null;
2250
2264
  }
2251
2265
  if (packet[0x0a] !== 0x06) {
2252
2266
  return null;
@@ -12311,6 +12325,10 @@ var ItemType;
12311
12325
  ItemType[ItemType["MenuBit"] = 147] = "MenuBit";
12312
12326
  ItemType[ItemType["MenuFilename"] = 148] = "MenuFilename";
12313
12327
  ItemType[ItemType["MenuHistory"] = 149] = "MenuHistory";
12328
+ // Native streaming players return the track title and artist together in
12329
+ // this otherwise undocumented item instead of the normal 0x0004/0x0007
12330
+ // pair. Observed from direct Beatport streaming (NP3-591).
12331
+ ItemType[ItemType["StreamingTrackMetadata"] = 153] = "StreamingTrackMetadata";
12314
12332
  ItemType[ItemType["MenuAll"] = 160] = "MenuAll";
12315
12333
  ItemType[ItemType["TrackTitleAlbum"] = 516] = "TrackTitleAlbum";
12316
12334
  ItemType[ItemType["TrackTitleGenre"] = 1540] = "TrackTitleGenre";
@@ -12357,6 +12375,10 @@ const transformItem = {
12357
12375
  title: a.label1,
12358
12376
  artworkId: a.artworkId,
12359
12377
  }),
12378
+ [ItemType.StreamingTrackMetadata]: (a) => ({
12379
+ title: a.label1,
12380
+ artist: a.label2,
12381
+ }),
12360
12382
  [ItemType.AlbumTitle]: mapIdName,
12361
12383
  [ItemType.Artist]: mapIdName,
12362
12384
  [ItemType.Genre]: mapIdName,
@@ -12755,7 +12777,7 @@ const utils_1 = __webpack_require__(/*! ./utils */ "./src/remotedb/utils.ts");
12755
12777
  * Lookup track metadata from rekordbox and coerce it into a Track entity
12756
12778
  */
12757
12779
  async function getMetadata(opts) {
12758
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
12780
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
12759
12781
  const { conn, lookupDescriptor, span, args } = opts;
12760
12782
  const { trackId, onResponse } = args;
12761
12783
  const request = new message_1.Message({
@@ -12776,24 +12798,25 @@ async function getMetadata(opts) {
12776
12798
  onResponse === null || onResponse === void 0 ? void 0 : onResponse({ itemsAvailable: resp.data.itemsAvailable, items: received });
12777
12799
  // Translate our trackItems into a (partial) Track entity.
12778
12800
  // Use optional chaining for all fields since streaming tracks may omit some.
12801
+ const streamingMetadata = trackItems[item_1.ItemType.StreamingTrackMetadata];
12779
12802
  const track = {
12780
12803
  id: (_b = (_a = trackItems[item_1.ItemType.TrackTitle]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0,
12781
- title: (_d = (_c = trackItems[item_1.ItemType.TrackTitle]) === null || _c === void 0 ? void 0 : _c.title) !== null && _d !== void 0 ? _d : '',
12782
- duration: (_f = (_e = trackItems[item_1.ItemType.Duration]) === null || _e === void 0 ? void 0 : _e.duration) !== null && _f !== void 0 ? _f : 0,
12783
- tempo: (_h = (_g = trackItems[item_1.ItemType.Tempo]) === null || _g === void 0 ? void 0 : _g.bpm) !== null && _h !== void 0 ? _h : 0,
12784
- comment: (_k = (_j = trackItems[item_1.ItemType.Comment]) === null || _j === void 0 ? void 0 : _j.comment) !== null && _k !== void 0 ? _k : '',
12785
- rating: (_m = (_l = trackItems[item_1.ItemType.Rating]) === null || _l === void 0 ? void 0 : _l.rating) !== null && _m !== void 0 ? _m : 0,
12786
- year: (_o = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.Year]) === null || _o === void 0 ? void 0 : _o.year,
12787
- bitrate: (_p = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.BitRate]) === null || _p === void 0 ? void 0 : _p.bitrate,
12788
- artwork: { id: (_r = (_q = trackItems[item_1.ItemType.TrackTitle]) === null || _q === void 0 ? void 0 : _q.artworkId) !== null && _r !== void 0 ? _r : 0 },
12789
- album: (_s = trackItems[item_1.ItemType.AlbumTitle]) !== null && _s !== void 0 ? _s : null,
12790
- artist: (_t = trackItems[item_1.ItemType.Artist]) !== null && _t !== void 0 ? _t : null,
12791
- genre: (_u = trackItems[item_1.ItemType.Genre]) !== null && _u !== void 0 ? _u : null,
12792
- key: (_v = trackItems[item_1.ItemType.Key]) !== null && _v !== void 0 ? _v : null,
12793
- color: (_w = (0, utils_1.findColor)(Object.values(trackItems))) !== null && _w !== void 0 ? _w : null,
12794
- label: (_x = trackItems[item_1.ItemType.Label]) !== null && _x !== void 0 ? _x : null,
12795
- remixer: (_y = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.Remixer]) !== null && _y !== void 0 ? _y : null,
12796
- originalArtist: (_z = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.OriginalArtist]) !== null && _z !== void 0 ? _z : null,
12804
+ title: (_e = (_d = (_c = trackItems[item_1.ItemType.TrackTitle]) === null || _c === void 0 ? void 0 : _c.title) !== null && _d !== void 0 ? _d : streamingMetadata === null || streamingMetadata === void 0 ? void 0 : streamingMetadata.title) !== null && _e !== void 0 ? _e : '',
12805
+ duration: (_g = (_f = trackItems[item_1.ItemType.Duration]) === null || _f === void 0 ? void 0 : _f.duration) !== null && _g !== void 0 ? _g : 0,
12806
+ tempo: (_j = (_h = trackItems[item_1.ItemType.Tempo]) === null || _h === void 0 ? void 0 : _h.bpm) !== null && _j !== void 0 ? _j : 0,
12807
+ comment: (_l = (_k = trackItems[item_1.ItemType.Comment]) === null || _k === void 0 ? void 0 : _k.comment) !== null && _l !== void 0 ? _l : '',
12808
+ rating: (_o = (_m = trackItems[item_1.ItemType.Rating]) === null || _m === void 0 ? void 0 : _m.rating) !== null && _o !== void 0 ? _o : 0,
12809
+ year: (_p = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.Year]) === null || _p === void 0 ? void 0 : _p.year,
12810
+ bitrate: (_q = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.BitRate]) === null || _q === void 0 ? void 0 : _q.bitrate,
12811
+ artwork: { id: (_s = (_r = trackItems[item_1.ItemType.TrackTitle]) === null || _r === void 0 ? void 0 : _r.artworkId) !== null && _s !== void 0 ? _s : 0 },
12812
+ album: (_t = trackItems[item_1.ItemType.AlbumTitle]) !== null && _t !== void 0 ? _t : null,
12813
+ artist: (_u = trackItems[item_1.ItemType.Artist]) !== null && _u !== void 0 ? _u : ((streamingMetadata === null || streamingMetadata === void 0 ? void 0 : streamingMetadata.artist) ? { id: 0, name: streamingMetadata.artist } : null),
12814
+ genre: (_v = trackItems[item_1.ItemType.Genre]) !== null && _v !== void 0 ? _v : null,
12815
+ key: (_w = trackItems[item_1.ItemType.Key]) !== null && _w !== void 0 ? _w : null,
12816
+ color: (_x = (0, utils_1.findColor)(Object.values(trackItems))) !== null && _x !== void 0 ? _x : null,
12817
+ label: (_y = trackItems[item_1.ItemType.Label]) !== null && _y !== void 0 ? _y : null,
12818
+ remixer: (_z = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.Remixer]) !== null && _z !== void 0 ? _z : null,
12819
+ originalArtist: (_0 = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.OriginalArtist]) !== null && _0 !== void 0 ? _0 : null,
12797
12820
  composer: null,
12798
12821
  fileName: '',
12799
12822
  filePath: '',