New music service - starting plugin development

I didn’t see this post until last night. I thought I was following this thread.

Anyway, take a look at what I changed below. I have not tested this but this might help if you haven’t gotten past this point by now.

I am a little fuzzy about how JavaScript handles copying and aliasing objects. You might be able to just copy the items part of the response object, act on it, and then the result is reflected in the parent response object. I would consult documentation to confirm this.

I’d rather just drill down on the response object and push your objects into that array.

Oh yeah, in case it’s not clear from my comment in your code, you can just call self.logger.info() and self.logger.error() if you haven’t removed that reference from your code created by the plugin code generator.

iheartrad.prototype.handleBrowseUri = function (curUri) {
	var self = this;

    self.logger.info('iheartrad.handleBrowseUri: ' + curUri);
	//self.commandRouter.logger.info('iheartrad.handleBrowseUri: ' + curUri);

	//var response = [];
	var defer = libQ.defer();

	var response = {
        navigation: {
            prev: {
                uri: "/iheartrad"
            }, //prev
            lists: [{
                "availableListViews": ["list","grid"],
                "items": []
            }] //lists
        } //navigation
    }; //var response

    //var list = response.navigation.lists[0].items;

    if (curUri.startsWith('/iheartrad')) {
		self.commandRouter.logger.info('iheartrad: found an iheart url: ' + curUri);
		if (curUri === '/iheartrad') {
			self.commandRouter.logger.info('iheartrad: Default url: ' + curUri);
			
			//list.push({
            response.navigation.lists.items.push({
				service: 'iheartrad',
				type: 'folder',
				title: 'Saved',
				artist: '',
				album: '',
				icon: 'fa fa-folder-open-o',
				url: '/iheartrad/saved'
			});

            //list.push({
            response.navigation.lists.items.push({
				service: 'iheartrad',
				type: 'folder',
				title: 'Browse',
				artist: '',
				album: '',
				icon: 'fa fa-folder-open-o',
				url: '/iheartrad/browse'
			});

			self.commandRouter.logger.info('iheartrad: Default url: after getRootContent');
			self.commandRouter.logger.info('iheartrad: list:' + JSON.stringify(list));
		} //if (curUri === 'iheartrad')
		else if (curUri.startsWith('iheartrad/saved')) {
			self.commandRouter.logger.info('iheartrad: Try and search for ZM station id');
			var matches = iHeart.getById('zm-6190');
			if (matches.length > 0) {
				self.commandRouter.logger.info(`iheartrad: matches: ${JSON.stringify(matches)}`);
				const station = matches.stations[0];
				const surl = iHeart.streamURL(station);

				//list.push({
                response.navigation.lists.items.push({
					service: 'webradio',
					type: 'station',
					title: 'ZM',
					artist: '',
					album: '',
					icon: 'fa fa-microphone',
					url: 'https://i.mjh.nz/nz/radio.ih.6190'
				});
			} else
				self.commandRouter.logger.info('iheartrad: matches: found nothing');

		} //else if (curUri === 'iheartrad/zm') 
		else {
			self.commandRouter.logger.info('iheartrad: reject');
			response = libQ.reject();
		}
		defer.resolve(response);
    } //if (curUri.startsWith('iheartrad'))
    else
		self.commandRouter.logger.info('iheartrad.handleBrowseUri: No uri specififed: ' + curUri);

    return defer.promise;
};

I’ll put together something on debugging with VS Code, but for now you should look at the example for Webstorm here:

Watch the whole thing. You won’t need the ssh forwarding if you use the method I did, but you can try the way he does it also. Zoom in on his command lines to see what he does. Look up VS Code remote debugging for Javascript and there is a lot of information provide by Microsoft.

You need to have Node 8 installed on your machine. That’s pretty old these days; I believe the current version is 14.x? Anyway, at first I installed Debian 8 in a VM with Virtualbox. This was kind of a pain. Then I found that you can install an old Node version locally for your user. I’m sure this can be done in Windows and on a Mac as well.

After that, you just have to get the ports right and attach to the process. When you get that working, crack a few beers or catch a buzz in some fashion. Take a break!

Now you’ll have to learn how to use the debugger. It really helps. The debugger in VS Code is extremely powerful.

Here is the launch.json file for Volumio. Bear in mind that you need to copy the /data and the /volumio directories to the root of your directory here, so I have:

/home/trucker/src/volumio/data
and
/home/trucker/src/volumio/volumio

My plugin is installed at /home/trucker/src/volumio/data/plugins/music_service/pandora

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Attach remote node: Nodemon",
            "address": "volumio.local",
            "port": 9229,
            // "restart": true,
            "protocol": "inspector",
            "localRoot": "/home/trucker/src/volumio/",
            "remoteRoot": "/"
        }
    ]
}

Okay, I have to take off for now. I hope that helps some!