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.
package/lib/cli.js CHANGED
@@ -2238,7 +2238,16 @@ class DeviceManager {
2238
2238
  this.off = __classPrivateFieldGet(this, _DeviceManager_emitter, "f").removeListener.bind(__classPrivateFieldGet(this, _DeviceManager_emitter, "f"));
2239
2239
  this.once = __classPrivateFieldGet(this, _DeviceManager_emitter, "f").once.bind(__classPrivateFieldGet(this, _DeviceManager_emitter, "f"));
2240
2240
  _DeviceManager_handleAnnounce.set(this, (message) => {
2241
- const device = (0, utils_1.deviceFromPacket)(message);
2241
+ // This runs on every UDP datagram the announce socket receives, so a parse
2242
+ // failure here would surface as an uncaught exception on the socket and
2243
+ // crash the process. Foreign or truncated packets are ignored instead.
2244
+ let device;
2245
+ try {
2246
+ device = (0, utils_1.deviceFromPacket)(message);
2247
+ }
2248
+ catch {
2249
+ return;
2250
+ }
2242
2251
  if (device === null) {
2243
2252
  return;
2244
2253
  }
@@ -2354,10 +2363,15 @@ const ip = __importStar(__webpack_require__(/*! ip-address */ "ip-address"));
2354
2363
  const constants_1 = __webpack_require__(/*! src/constants */ "./src/constants.ts");
2355
2364
  /**
2356
2365
  * Converts a announce packet to a device object.
2366
+ *
2367
+ * Returns null for any packet that is not a stage-3 Pro DJ Link announce. The
2368
+ * announce socket receives every UDP broadcast on its port, so foreign traffic
2369
+ * (other apps, other protocols) is normal and must be ignored, not treated as
2370
+ * an error.
2357
2371
  */
2358
2372
  function deviceFromPacket(packet) {
2359
2373
  if (packet.indexOf(constants_1.PROLINK_HEADER) !== 0) {
2360
- throw new Error('Announce packet does not start with expected header');
2374
+ return null;
2361
2375
  }
2362
2376
  if (packet[0x0a] !== 0x06) {
2363
2377
  return null;
@@ -9392,6 +9406,10 @@ var ItemType;
9392
9406
  ItemType[ItemType["MenuBit"] = 147] = "MenuBit";
9393
9407
  ItemType[ItemType["MenuFilename"] = 148] = "MenuFilename";
9394
9408
  ItemType[ItemType["MenuHistory"] = 149] = "MenuHistory";
9409
+ // Native streaming players return the track title and artist together in
9410
+ // this otherwise undocumented item instead of the normal 0x0004/0x0007
9411
+ // pair. Observed from direct Beatport streaming (NP3-591).
9412
+ ItemType[ItemType["StreamingTrackMetadata"] = 153] = "StreamingTrackMetadata";
9395
9413
  ItemType[ItemType["MenuAll"] = 160] = "MenuAll";
9396
9414
  ItemType[ItemType["TrackTitleAlbum"] = 516] = "TrackTitleAlbum";
9397
9415
  ItemType[ItemType["TrackTitleGenre"] = 1540] = "TrackTitleGenre";
@@ -9438,6 +9456,10 @@ const transformItem = {
9438
9456
  title: a.label1,
9439
9457
  artworkId: a.artworkId,
9440
9458
  }),
9459
+ [ItemType.StreamingTrackMetadata]: (a) => ({
9460
+ title: a.label1,
9461
+ artist: a.label2,
9462
+ }),
9441
9463
  [ItemType.AlbumTitle]: mapIdName,
9442
9464
  [ItemType.Artist]: mapIdName,
9443
9465
  [ItemType.Genre]: mapIdName,
@@ -9836,7 +9858,7 @@ const utils_1 = __webpack_require__(/*! ./utils */ "./src/remotedb/utils.ts");
9836
9858
  * Lookup track metadata from rekordbox and coerce it into a Track entity
9837
9859
  */
9838
9860
  async function getMetadata(opts) {
9839
- 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;
9861
+ 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;
9840
9862
  const { conn, lookupDescriptor, span, args } = opts;
9841
9863
  const { trackId, onResponse } = args;
9842
9864
  const request = new message_1.Message({
@@ -9857,24 +9879,25 @@ async function getMetadata(opts) {
9857
9879
  onResponse === null || onResponse === void 0 ? void 0 : onResponse({ itemsAvailable: resp.data.itemsAvailable, items: received });
9858
9880
  // Translate our trackItems into a (partial) Track entity.
9859
9881
  // Use optional chaining for all fields since streaming tracks may omit some.
9882
+ const streamingMetadata = trackItems[item_1.ItemType.StreamingTrackMetadata];
9860
9883
  const track = {
9861
9884
  id: (_b = (_a = trackItems[item_1.ItemType.TrackTitle]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0,
9862
- title: (_d = (_c = trackItems[item_1.ItemType.TrackTitle]) === null || _c === void 0 ? void 0 : _c.title) !== null && _d !== void 0 ? _d : '',
9863
- duration: (_f = (_e = trackItems[item_1.ItemType.Duration]) === null || _e === void 0 ? void 0 : _e.duration) !== null && _f !== void 0 ? _f : 0,
9864
- tempo: (_h = (_g = trackItems[item_1.ItemType.Tempo]) === null || _g === void 0 ? void 0 : _g.bpm) !== null && _h !== void 0 ? _h : 0,
9865
- comment: (_k = (_j = trackItems[item_1.ItemType.Comment]) === null || _j === void 0 ? void 0 : _j.comment) !== null && _k !== void 0 ? _k : '',
9866
- rating: (_m = (_l = trackItems[item_1.ItemType.Rating]) === null || _l === void 0 ? void 0 : _l.rating) !== null && _m !== void 0 ? _m : 0,
9867
- year: (_o = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.Year]) === null || _o === void 0 ? void 0 : _o.year,
9868
- bitrate: (_p = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.BitRate]) === null || _p === void 0 ? void 0 : _p.bitrate,
9869
- artwork: { id: (_r = (_q = trackItems[item_1.ItemType.TrackTitle]) === null || _q === void 0 ? void 0 : _q.artworkId) !== null && _r !== void 0 ? _r : 0 },
9870
- album: (_s = trackItems[item_1.ItemType.AlbumTitle]) !== null && _s !== void 0 ? _s : null,
9871
- artist: (_t = trackItems[item_1.ItemType.Artist]) !== null && _t !== void 0 ? _t : null,
9872
- genre: (_u = trackItems[item_1.ItemType.Genre]) !== null && _u !== void 0 ? _u : null,
9873
- key: (_v = trackItems[item_1.ItemType.Key]) !== null && _v !== void 0 ? _v : null,
9874
- color: (_w = (0, utils_1.findColor)(Object.values(trackItems))) !== null && _w !== void 0 ? _w : null,
9875
- label: (_x = trackItems[item_1.ItemType.Label]) !== null && _x !== void 0 ? _x : null,
9876
- remixer: (_y = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.Remixer]) !== null && _y !== void 0 ? _y : null,
9877
- originalArtist: (_z = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.OriginalArtist]) !== null && _z !== void 0 ? _z : null,
9885
+ 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 : '',
9886
+ duration: (_g = (_f = trackItems[item_1.ItemType.Duration]) === null || _f === void 0 ? void 0 : _f.duration) !== null && _g !== void 0 ? _g : 0,
9887
+ tempo: (_j = (_h = trackItems[item_1.ItemType.Tempo]) === null || _h === void 0 ? void 0 : _h.bpm) !== null && _j !== void 0 ? _j : 0,
9888
+ comment: (_l = (_k = trackItems[item_1.ItemType.Comment]) === null || _k === void 0 ? void 0 : _k.comment) !== null && _l !== void 0 ? _l : '',
9889
+ rating: (_o = (_m = trackItems[item_1.ItemType.Rating]) === null || _m === void 0 ? void 0 : _m.rating) !== null && _o !== void 0 ? _o : 0,
9890
+ year: (_p = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.Year]) === null || _p === void 0 ? void 0 : _p.year,
9891
+ bitrate: (_q = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.BitRate]) === null || _q === void 0 ? void 0 : _q.bitrate,
9892
+ artwork: { id: (_s = (_r = trackItems[item_1.ItemType.TrackTitle]) === null || _r === void 0 ? void 0 : _r.artworkId) !== null && _s !== void 0 ? _s : 0 },
9893
+ album: (_t = trackItems[item_1.ItemType.AlbumTitle]) !== null && _t !== void 0 ? _t : null,
9894
+ 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),
9895
+ genre: (_v = trackItems[item_1.ItemType.Genre]) !== null && _v !== void 0 ? _v : null,
9896
+ key: (_w = trackItems[item_1.ItemType.Key]) !== null && _w !== void 0 ? _w : null,
9897
+ color: (_x = (0, utils_1.findColor)(Object.values(trackItems))) !== null && _x !== void 0 ? _x : null,
9898
+ label: (_y = trackItems[item_1.ItemType.Label]) !== null && _y !== void 0 ? _y : null,
9899
+ remixer: (_z = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.Remixer]) !== null && _z !== void 0 ? _z : null,
9900
+ originalArtist: (_0 = trackItems === null || trackItems === void 0 ? void 0 : trackItems[item_1.ItemType.OriginalArtist]) !== null && _0 !== void 0 ? _0 : null,
9878
9901
  composer: null,
9879
9902
  fileName: '',
9880
9903
  filePath: '',