Multiple instances ws socket

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: Multiple instances ws socket

Re: Multiple instances ws socket

by Ludek » Fri Aug 23, 2024 4:35 pm

Hi,
see [MM install folder]/sampleScripts/remoteControl

Code: Select all

/*

This demonstrates how POST request to our media server (see IP:Port in Options > Media Sharing)
catched bellow to start playing

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

The test request available at: https://reqbin.com/uw0qc1ma

POST / HTTP/1.1
Host: 127.0.0.1
MMCustomRequest: true
Content-Type: application/json
Content-Length: 92

{
 "target":"remoteMMControlTestScript",
 "clientID":"remoteTestClient",
 "command":"play"
}


*/
app.listen(app, 'remoteRequest', (r) => {
    var content = JSON.parse(r.requestBody);
    if (content.target == 'remoteMMControlTestScript' && content.clientID == 'remoteTestClient') {
        if (content.command == 'play') {
            if (app.player.entriesCount > 0) {
                r.asyncResult = true;
                app.player.playAsync().then(() => {
                    var track = app.player.getCurrentTrack();
                    if (track)
                        r.responseBody = 'Playback of track ' + track.summary + ' started';
                    else
                        r.responseBody = 'Playback started';
                });
            } else {
                r.responseBody = 'No track in \'Playing\' list';
            }
        }
    }
});

This way you can communicate with different servers [different ip port] from an external application.

Re: Multiple instances ws socket

by eshaacacia » Fri Aug 23, 2024 3:10 am

Ill try it out but a bit unsure how that helps for example, this is my JS script to connect to the MM:

Code: Select all

async function getWebSocketDebuggerUrl() {
    try {
        // Fetch the list of open pages from the browser
        const response = await axios.get('http://localhost:9222/json');
        const pages = response.data;

        // Find the page with the URL 'file:///mainwindow.html'
        const mainPage = pages.find(page => page.url === 'file:///mainwindow.html');

        if (mainPage) {
            // Return the WebSocket debugger URL
            return mainPage.webSocketDebuggerUrl;
        } else {
            throw new Error("Main window page not found.");
        }
    } catch (error) {
        console.error('Error fetching WebSocket debugger URL:', error);
    }
}

var wsUrl = await getWebSocketDebuggerUrl();
console.log(wsUrl);
var ws = new WebSocket(wsUrl);
 
 //Further script to send commands on open close error etc
similarly here's the python script to achieve the same:

Code: Select all

import win32com.client

# Create a COM object for MediaMonkey
SDB = win32com.client.Dispatch("SongsDB5.SDBApplication")
In both these scripts there is no field to connect to a particular MM server via IP/Port or server name. So even if I have multiple servers with different names and IPs in unable to connect to that server specifically. Hence I wanted to know if theres any way to communicate and send commands to a MM server specifically.

Also to clarify, the problem is not setting up multiple servers/access points in MM but to communicate with them from an external application.

Re: Multiple instances ws socket

by Peke » Thu Aug 22, 2024 5:38 pm

Hi,
Have you tried to rename MM Server names?

I've tried in MMA and even they have same name I can manually add multiple servers adn access them at same time.

Re: Multiple instances ws socket

by eshaacacia » Thu Aug 22, 2024 5:14 am

No issues, my current workaround for this is that I use multiple instances of MM at the same time with each instance acting as a different access point. This works I can confirm. The issue is I want to communicate to these multiple instances but from all documentation I have inferred that you cannot communicate with a specific instance of MM. The ws socket and other methods simply communicate with the first instance of MM launched. Hence I wanted to ask is there maybe anything I have missed that will allow me to communicate with specific instances given that each instance is sharing media at a different port address.

Re: Multiple instances ws socket

by Peke » Tue Aug 20, 2024 1:46 pm

Hi,
unfortunately that is not possible from MM side you can cast single track to multiple devices at same time, but not mutiple files to mutiple devices. You can use devices to access MM DLNA/UPnP server to play different music.

Re: Multiple instances ws socket

by eshaacacia » Tue Aug 20, 2024 3:37 am

Hi,
The WMP capability from what I am aware can only play the same thing on multiple cast devices. What I want to achieve is to play different files/playlists on different devices so yes I want each device as a different control point essentially.

Re: Multiple instances ws socket

by Peke » Sat Aug 17, 2024 9:13 am

Hi,
Are you referring to WMP capabilities to Cast Library on multiple devices and have them listed as different control points?

Multiple instances ws socket

by eshaacacia » Fri Aug 16, 2024 9:49 am

Hi,
I am working on a system where I need multiple uPnP servers to connect and play music on different devices simultaneously. It is not multi stream as I need different playlists playing on different devices. I wanted to create a simple desktop app that allows me to communicate with these servers and send the basic media player commands. I can do this easily with WebSocket for one instance but I cannot figure out how to do this for multiple instances since there is no information on how to connect to a particular instance of Monkey Media via server Ip and port. As such I am a bit lost and would appreciate any info that would clear things out for me.

Top