Jump to content

Websocket


tomtomgooo

Recommended Posts

tomtomgooo

Hi,

I try to use websocket with node-red and emby but I never receive nothing from connection.

I am connected to ws://192.168.1.71:8096?api_key=xxx&deviceId=xxx.

I expect to receive message system from emby passively but it never comes nothing.

Do I need to do something else ?

I am in docker swarm with emby 4.6.4.0.

Thanks for your help

 

Link to comment
Share on other sites

In the JavaScript API you have to request "Sessions" inorder to get session data through the webSocket. (Play, Pause, stopped)

When I get home from work,  I'll look to see what the actual url is when that request is made.

It is most likely a POST method, with how many milliseconds should pass before getting more data from "Sessions".

 

Link to comment
Share on other sites

3 hours ago, tomtomgooo said:

Ok thanks .

Is it the same url as HTTP rest API?

Yeah, I think so. You would just use 'ws' instead of 'http'.

 

I meant to check this last night, I will look at it this morning. Apologies.

 

Link to comment
Share on other sites

Okay here is the Websocket code from the API. Lets see if we can figure out what the websocket message is gonna be for Session data.

sendWebSocketMessage(name, data) {

        console.log(`Sending web socket message: ${name}`);

        let msg = { MessageType: name };

        if (data) {
            msg.Data = data;
        }

        msg = JSON.stringify(msg);

        this._webSocket.send(msg);
    }

    startMessageListener(name, options) {

        this.sendMessage(`${name}Start`, options);

        let list = this.messageListeners;

        if (!list) {
            this.messageListeners = list = [];
        }

        if (!list.includes(name)) {
            list.push(name);
        }
    }

    stopMessageListener(name) {

        this.sendMessage(`${name}Stop`);

        let list = this.messageListeners;

        if (list && list.includes(name)) {
            this.messageListeners = list = list.filter(n => n !== name);
        }
    }

    sendMessage(name, data) {

        if (this.isWebSocketOpen()) {
            this.sendWebSocketMessage(name, data);
        }
    }

 

I might be wrong here, but it's a place to start.

 

First the Websocket URL you have seems to be correct:

ws://{url}:{port}/embywebsocket?api_key={apiKey}&deviceId={deviceName}

 

It then looks like we need to send a POST request along to the URL, with a specific body data.

 

The body data object is JSON, and seems to be an object something like:

{ MessageType: "", Data: ""} 

 

 

It also looks like they append "Start" to the param name here:

 this.sendMessage(`${name}Start`, options);

 

So....Maybe... try sending this in POST body to your websocket URL:

{MessageType: "SessionsStart", Data: "0,5000"}

I believe this says: Open a websocket connection to "Sessions", and get data every 5 seconds.

 

I'm interested in how you fair, so please do let me know.

 

 

 

 

Link to comment
Share on other sites

tomtomgooo

Oh nice it is ok now.

My address was wrong, I forgot /embywebsocket.

I have send :

{MessageType: "SessionsStart", Data: "0,5000"}

All is ok, receive all sessions informations from all user in an array of json.

Thanks for your help

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...