Page 2 of 3

Re: MM5 API with WebSockets in NodeJS

Posted: Tue Jun 01, 2021 5:34 am
by MyVikes
I've tried using the non-localhost IP from the same PC and an intranet PC on same segment. Neither worked. :-(

Re: MM5 API with WebSockets in NodeJS

Posted: Tue Jun 01, 2021 8:38 am
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)?

Re: MM5 API with WebSockets in NodeJS

Posted: Tue Jun 01, 2021 2:41 pm
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.

Re: MM5 API with WebSockets in NodeJS

Posted: Tue Jun 01, 2021 6:55 pm
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?

Re: MM5 API with WebSockets in NodeJS

Posted: Wed Jun 02, 2021 8:14 am
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.

Re: MM5 API with WebSockets in NodeJS

Posted: Thu Jun 03, 2021 2:46 am
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

Re: MM5 API with WebSockets in NodeJS

Posted: Fri Jun 04, 2021 10:24 am
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:

Re: MM5 API with WebSockets in NodeJS

Posted: Sat Jun 05, 2021 5:59 am
by MyVikes
Two thumbs up!
:D

Re: MM5 API with WebSockets in NodeJS

Posted: Tue Jun 08, 2021 4:50 pm
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

Re: MM5 API with WebSockets in NodeJS

Posted: Fri Jun 11, 2021 1:37 am
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

Re: MM5 API with WebSockets in NodeJS

Posted: Mon Jun 14, 2021 11:08 am
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)

Re: MM5 API with WebSockets in NodeJS

Posted: Tue Jun 15, 2021 6:59 am
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!

Re: MM5 API with WebSockets in NodeJS

Posted: Wed Jun 16, 2021 3:45 am
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!

Re: MM5 API with WebSockets in NodeJS

Posted: Wed Jun 16, 2021 6:51 pm
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.

Re: MM5 API with WebSockets in NodeJS

Posted: Fri Jun 18, 2021 3:35 pm
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.