mopidy / mopidy.js

JavaScript library for controlling a Mopidy music server over a WebSocket from browsers or Node.js. This is the foundation of Mopidy web clients.
https://mopidy.com
Apache License 2.0
75 stars 18 forks source link

Uncaught (in promise) TypeError: track.artists is undefined #37

Open bluepuma77 opened 3 years ago

bluepuma77 commented 3 years ago

For hours I have been trying to get mopidy.js to run, my major challenges:

  1. Does not build with node 15 (seems to work with 12 and 14)
  2. Parcel needs to be installed
  3. Changing the script to connect to remote mopidy
  4. Configure mopidy to enable remote hosts to access
  5. Finally "Uncaught (in promise) TypeError: track.artists is undefined"

It seems to work now, I play a radio stream on the Raspi3+ (latest Raspberry Pi OS Lite), can access remotely via Iris and mopidy.js seems to connect, I can see web socket messages. But the console shows the exception and it displays "Unknown - Unknown".

MopidyJS-track artists_is_undefined-2

bluepuma77 commented 3 years ago

I need to add that 4) is well documented: "Make sure the Mopidy config http/allowed_origins includes pi3.local:1234"

I just had the challenge that a basic sudo apt install mopidy installation would not read /etc/mopidy/mopidy.conf. It would tell me it reads the file, no error message, but then would not for example enable Iris.

Using a "professional" script does the trick of a working installation:

# install mopidy with Pimoroni script
curl https://raw.githubusercontent.com/pimoroni/pirate-audio/master/mopidy/install.sh | sudo bash

# roll back some changes :)
sudo sed -i '/hifiberry/d' /boot/config.txt
sudo sed -i '/\[pidi\]/,+3d' /etc/mopidy/mopidy.conf
bluepuma77 commented 3 years ago

MP3 stream does not work, MP3 local file does not work, but Spotify does work.

I started the MP3 stream with mpc clear && mpc add "https://starfm-2.explodio.com/berlin.mp3" && mpc play. The local MP3 I selected from within Iris file browser. Spotify I started with mpc clear && mpc add "spotify:playlist:37i9dQZF1DX0rCrO4CFRfM" && mpc play

kingosticks commented 3 years ago

Is there an actual problem/question regarding Mopidy.js here? If not, I'm going to close this.

If you are having problems with playing mp3 files or Mopidy in general then we can work on that at discuss.mopidy.com (you can also search for the similar issues on there already, it's likely a missing gstreamer plugin package).

bluepuma77 commented 3 years ago

Sorry, if I wasn't clear.

Mopidy.js throws an exception when playing MP3 streams or local MP3 files.

Uncaught (in promise) TypeError: track.artists is undefined

This prevents the Mopidy.js UI from updating the displayed information.

I would say it's a bug in Mopidy.js.

kingosticks commented 3 years ago

Track model attributes are optional. If there are no artist tags present, then, like any other attribute, track.artists is undefined. You need to handle this in your client code. Sometimes attributes are not set by a backend because they don't make any sense for that backend. Hence they are optional. If this was to be considered a bug it would be in mopidy-local (and it's not a bug, a track may not have any artists tags, or album tags, or whatever tags).

jodal commented 3 years ago

It seems that the code that triggered the bug was the example web app bundled with Mopidy.js, so I guess that could be made more robust.

zoechi commented 2 years ago

@kingosticks in https://github.com/mopidy/mopidy.js/blob/master/src/mopidy.d.ts#L227-L289 only track_no, disc_no, length, and last_modified are marked optional.

I just stumbled upon this because

{
  jsonrpc=2.0,
  id=0,
  method=core.tracklist.add,
  params={uris: [orfradio:oe3/live]},
}

returns

{"jsonrpc": "2.0", "id": 0, "result": [{"__model__": "TlTrack", "tlid": 12, "track": {"__model__": "Track", "uri": "orfradio:oe3/live", "name": "Live"}}]}

where most fields are actually missing.