MM5 API with WebSockets in NodeJS

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: MM5 API with WebSockets in NodeJS

Re: MM5 API with WebSockets in NodeJS

by ushmaelen » Fri Apr 08, 2022 11:07 am

Ludek wrote: Mon Sep 20, 2021 8:07 am Is your script/addon already available for testing?

As for adding another output device/list, see e.g. 'choosePlayer' in actions.js and related generateChoosePlayerSubmenu
and related code like

Code: Select all

var apl = app.sharing.getActivePlayer();
var lst = app.sharing.getAvailablePlayers();
....
app.sharing.setActivePlayerUUID( ... )
Great to see remote control support in the Android app @Ludek. Pretty please

Re: MM5 API with WebSockets in NodeJS

by Ludek » Mon Sep 20, 2021 8:07 am

I've completed my MM5 javascript Addin leveraging the POST request Ludek added..

So this doesn't use WebSockets as that was a dead end. My client is a an Android app but I'd done a React POC so anything that serves up a nothing more than a SPA app would work.

My next task it to add controls to the app/javascript Addin to redirect the output to available Chromecast device but if I understand what you're doing with a DAC bridge that would not be necessary.
Is your script/addon already available for testing?

As for adding another output device/list, see e.g. 'choosePlayer' in actions.js and related generateChoosePlayerSubmenu
and related code like

Code: Select all

var apl = app.sharing.getActivePlayer();
var lst = app.sharing.getAvailablePlayers();
....
app.sharing.setActivePlayerUUID( ... )

Re: MM5 API with WebSockets in NodeJS

by Peke » Sun Aug 01, 2021 9:51 am

Hi,
He ants that on Pi that is used as DAC bridge (MM play to multiple devices) on its 7" Display he have Remote MM5 Player controls and Metadata info. An access to Now Playing in MM5 would be a bonus.

I also upgraded his request to feature that one Device can be Controller for MM5 (Play To), list and show all control points that access MM5 over DLNA, ... and fetch Metadata for playing files. Haven't deep dived in DLNA and control point to see if you can remotely control that control point player, something for future builds.

Re: MM5 API with WebSockets in NodeJS

by MyVikes » Sun Aug 01, 2021 5:04 am

I've completed my MM5 javascript Addin leveraging the POST request Ludek added, see post here by him on Mon Jun 14, 2021 11:08 am
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)
Ludek
So this doesn't use WebSockets as that was a dead end. My client is a an Android app but I'd done a React POC so anything that serves up a nothing more than a SPA app would work.

My next task it to add controls to the app/javascript Addin to redirect the output to available Chromecast device but if I understand what you're doing with a DAC bridge that would not be necessary.

Re: MM5 API with WebSockets in NodeJS

by zombiefly » Fri Jul 30, 2021 3:30 am

hello,
i posted another topic re: creating a monkeybridge appliance and was wondering if any of you talented people could assist? from what i can see, this websocket work covers most of the requirement. interested to hear your thoughts please! :D

viewtopic.php?f=27&t=99672&e=1&view=unread#unread

Re: MM5 API with WebSockets in NodeJS

by MyVikes » Wed Jul 07, 2021 5:49 pm

TBD....i've thought about it but not sure if i want to support an app outside of my own use. :-)

i've been using it for a 1+ year and love it. except for ripping and cataloging my music collection i no longer use the MM interface.

It currently requires a VB.Net proxy communicating with the MM4 COM objects.

Primarily it allows me to quickly randomly select an album, select from n random albums (both using filters on genre, artist, etc. if desired), skip forward/backward, pause, progress to a point in the playing song, view current playlist and select a song to advance to, control MM volume and browse my library among other things. Also, it provides simple links to artist and album wiki along with a lyrics search. The song progress is a simple estimation based on the length of the song and a background timer but works fine for my use. I've thought of using an occasional ping of the server but haven't found it necessary.

I'm about 70% done migrating the VB.Net app to javascript leveraging the "app.listen(app, 'remoteRequest', (r) => {" web server recently added. So it would require just the MM5 addin javascript and then my app (Android only although i might use this as an opportunity to learn Swift). I'd written a React front end as a learning opportunity but after having it ~80% functional compared to the Android app i lost interest (:-)) and have stopped working on that.

The current performance is excellent and the MM5 javascript version thus far is comparable.

Here is a screenshot: https://www.dropbox.com/s/tqu04ewq37gtx ... 6.png?dl=0

Re: MM5 API with WebSockets in NodeJS

by Reto S. » Wed Jul 07, 2021 6:51 am

MyVikes wrote: Thu Jun 24, 2021 4:26 am thumbs up and thanks!
HI @MyVikes

I see you are working on a Remote Control (for yourself!?!) or do you plan to release this publicly as an App or something?

Re: MM5 API with WebSockets in NodeJS

by MyVikes » Thu Jun 24, 2021 4:26 am

thumbs up and thanks!

Re: MM5 API with WebSockets in NodeJS

by Ludek » Tue Jun 22, 2021 12:10 pm

Hi, response headers settings isn't supported yet, just responseBody (as in the code example).
I'll add it to my TODO

Re: MM5 API with WebSockets in NodeJS

by MyVikes » Tue Jun 22, 2021 3:02 am

Thanks Ludek

Where can i get additional info/documentation regarding the remoteRequest such as how to properly set the responseType? I've tried "json" and "application/json; charset=utf-8" to have the Content-Type set in the returned Headers but no luck. It's returning json text but just not recognized as such by Postman.

Re: MM5 API with WebSockets in NodeJS

by Ludek » Fri Jun 18, 2021 3:35 pm

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.

Re: MM5 API with WebSockets in NodeJS

by MyVikes » Wed Jun 16, 2021 6:51 pm

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

by MyVikes » Wed Jun 16, 2021 3:45 am

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

by MyVikes » Tue Jun 15, 2021 6:59 am

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

by Ludek » Mon Jun 14, 2021 11:08 am

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)

Top