MM5 API with WebSockets in NodeJS

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

MyVikes
Posts: 89
Joined: Sun Jul 02, 2017 1:20 am

Re: MM5 API with WebSockets in NodeJS

Post by MyVikes »

I've tried using the non-localhost IP from the same PC and an intranet PC on same segment. Neither worked. :-(
MyVikes
Posts: 89
Joined: Sun Jul 02, 2017 1:20 am

Re: MM5 API with WebSockets in NodeJS

Post by MyVikes »

Question: in my MM5 Options / Media Sharing the port number is http://192.168.0.163:20834/

I can "access" MM5 using http://192.168.0.163:20834/ in that I see an empty shell of MM in the browser in which i can't do anything (like see albums, start/stop music, etc.) but for the web socket access i've using http://localhost:9222/json to get the:
"webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/8B7DB99C9EC77F1DCEBA8B879B5E0B4A"

what is the diff between the two port numbers (9222 and 20834)?
TIV73
Posts: 229
Joined: Sat Nov 12, 2011 1:31 pm

Re: MM5 API with WebSockets in NodeJS

Post by TIV73 »

Port 9222 is the remote debugging port for chrome. MediaMonkey uses chromium as frontend, which just happens to offer an API. You can use it to interface with the underlying host application, but that port is, technically speaking, not really related to mediamonkey itself.
MyVikes
Posts: 89
Joined: Sun Jul 02, 2017 1:20 am

Re: MM5 API with WebSockets in NodeJS

Post by MyVikes »

So if I'm to understand that following the approach here and/or here it only works from the machine that MM5 is running on. I'm able to interact with MM5 including addons I've written and installed but to do this from a remot e app I'll have to have a "small" proxy app running on the MM5 PC in order to interact with MM5 via this debug method.

Is that correct?
TIV73
Posts: 229
Joined: Sat Nov 12, 2011 1:31 pm

Re: MM5 API with WebSockets in NodeJS

Post by TIV73 »

iirc chrome only accepts remote debugging connections from localhost, probably for security reasons. There are a couple of settings that might help, but they are a bit situational and would need to be set from by the mediamonkey process that starts the chrome frontend.

Aside from creating a proxy application as you suggested, you could also have a look at port forwarding and see if it helps.
MyVikes
Posts: 89
Joined: Sun Jul 02, 2017 1:20 am

Re: MM5 API with WebSockets in NodeJS

Post by MyVikes »

Thank you all so much....I'll probably go the proxy route or since my OS is Windows I can update my RESTful interfaces for the changes necessary for the MM5 COM objects (as that's what got me started on this. see other thread here).

That being said, much like I did using the COM objects with MM4 where I created a RESTful interface to MM4, does anyone know if the good developers at MediaMonkey intend to create these for MM5 for general use? That would be way cool! :D
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: MM5 API with WebSockets in NodeJS

Post by drakinite »

Haven't talked to the other devs about it yet, but I'm beginning to think it'd be a very good idea to work on one. :slight_smile:
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
MyVikes
Posts: 89
Joined: Sun Jul 02, 2017 1:20 am

Re: MM5 API with WebSockets in NodeJS

Post by MyVikes »

Two thumbs up!
:D
Ludek
Posts: 4947
Joined: Fri Mar 09, 2007 9:00 am

Re: MM5 API with WebSockets in NodeJS

Post by Ludek »

FYI: I am preparing a sample addon that can receive and reply http requests (via our media server) and I'll add it to sampleAddons.

This will allow to remote control MM5 without a need for the "proxy" app being installed on the PC. The idea also is to put this sample addon on github to evolve to a RESTfull api.
Tracked in Mantis as issue #18000
MyVikes
Posts: 89
Joined: Sun Jul 02, 2017 1:20 am

Re: MM5 API with WebSockets in NodeJS

Post by MyVikes »

This is just what I was trying to do. I had written several Addons already.

"One thing" I would like to have is the ability to send custom queries and have results of course returned as json. A couple examples of what my app does is random start an album after clearing the playlist (or not, it's an option), randomly return a list of n albums from which I can select which to start and along with these restrict the album(s) to those that haven't been played in n number of days. Additionally, I can send a genre and/or partial album artist name to filter on. I also have a library browser where i can, for example, send a text string and it'll return matching albums, song, artists, etc. from which I can drill down. I have to admit it's amazing fast and allows me to interact very quickly with my rather large library in ways the MM4 client app can't (although this started as MM4 scripts it now goes way beyond what I did with those) .

https://www.dropbox.com/s/b7a2jkl1zoc9x ... 6.png?dl=0

Please let me know when I can start testing.

:D
Ludek
Posts: 4947
Joined: Fri Mar 09, 2007 9:00 am

Re: MM5 API with WebSockets in NodeJS

Post by Ludek »

OK, if you have already re-written the addons for MM5 then I guess that you have already own PC app for processing the remote requests.

If you are still interesed in processing requests via the MM5 server then install build 2415 and in the /sampleScripts/ folder there is 'remoteControl' sample script.

Currently it accepts only POST requests including MMCustomRequest in the request header and valid JSON as request body.
More in the code.

The test request available at: https://reqbin.com/uw0qc1ma (adjust port based on your settings in Options > Media Sharing)
MyVikes
Posts: 89
Joined: Sun Jul 02, 2017 1:20 am

Re: MM5 API with WebSockets in NodeJS

Post by MyVikes »

I've done the following:
1) updated MM4 to 2415
2) set the port number to 20834
3) installed the remoteControl Addon to MM5
4) tried using both REQBIN and Postman to post the following to http://localhost:20834:
{
"target": "remoteMMControlTestScript",
"clientID": "remoteTestClient",
"command": "play"
}


And i get the following:
HTTP/1.1 200 OK
connection: keep-alive
content-length: 0
server: Windows NT/5.0 UPnP/1.0, DLNADOC/1.50 Platinum/0.6.4.0


What i expected to happen was the current song in the play list to start playing and to get a response like: 'Playback of track ' + track.summary + ' started'

What am I missing or perhaps doing wrong?

Thanks!
MyVikes
Posts: 89
Joined: Sun Jul 02, 2017 1:20 am

Re: MM5 API with WebSockets in NodeJS

Post by MyVikes »

Never mind....i got it working as follows:

1) under MM5 Options / Media Sharing I created a new server and gave it a different port than the "MediaMonkey Library" default server.
2) this allowed the ReqBin request to work, then inspecting this further I found I needed to add the "MMCustomRequest: true" header in my Postman request as well

Thanks again!
MyVikes
Posts: 89
Joined: Sun Jul 02, 2017 1:20 am

Re: MM5 API with WebSockets in NodeJS

Post by MyVikes »

I'm off and running with executing my own Addon methods and getting json back.

I will say understanding the purpose of

r.asyncResult = true;

in the remoteControl sample was instrumental to waiting for the the "then()" method to complete in order to return the responseBody with the result from the promise.

I'm documenting this for anyone else who wishes to try this as well.
Ludek
Posts: 4947
Joined: Fri Mar 09, 2007 9:00 am

Re: MM5 API with WebSockets in NodeJS

Post by Ludek »

Yes, exactly, you can use the r.asyncResult = true; whenever you need to set the responseBody later (asynchronously).
Just note that there is 10 seconds timeout in which you need to set the responseBody and also the client can have own read timeout -- so it should be used only for fast async operations (like simple SQL queries) otherwise it is preferred to fetch the data in more continual requests.
Post Reply