Jump to content

Getting user login and device in use via websocket API


nahovevyse

Recommended Posts

nahovevyse

Checked the WebSocket wiki page. It shows to connect to a WebSocket you will require an API key and device ID
 

I'm trying to get the device ID as soon as any user logs in to the server. 
Till now I got no response after WebSocket connection.
here's my python code

    websocket.enableTrace(True)

    host = "xxx.xx.xx.xx"
    port = 8096
    api_key = "xxxxxx"
    device_id = "xxxx"

    ws = websocket.create_connection("ws://{}:{}/embywebsocket?api_key={}&deviceId={}".format(host, port, api_key, device_id))

    result = ws.recv()
    print('Result: {}'.format(result))

    result = ws.recv()
    print('Result: {}'.format(result))
    
    # Trying something from community... 
    ws.send(json.dumps([json.dumps({'msg': 'connect', 'version': '1', 'support': ['1', 'pre2', 'pre1']})]))
    result = ws.recv()
    print('Result: {}'.format(result))

Result:

 

--- request header ---
GET /embywebsocket?api_key=xxxxxxxx&deviceId=a7650139abe6b220 HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: xxx.xx.xx.xx:8096
Origin: http://xxx.xx.xx.xx:8096
Sec-WebSocket-Key: mHuOCG3yyL41uB7gk7fK8g==
Sec-WebSocket-Version: 13


-----------------------
--- response header ---
HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: Ta03Qfon0bEHLCQKG+0BtGNZXjQ=
-----------------------
send: b'\x8a\x80\x93\tf\xe1'
send: b'\x8a\x80\x13\xf8qB'
send: b'\x8a\x80\xa3\xf3\xa1b'
send: b'\x8a\x80\xa9\x87\xad\x9e'
send: b'\x8a\x80@\x19\xa7\xa7'

These send messages came after some time of no response. These are not proper Hex codes. IDK what they are.

Requesting EMBY gurus to help me on this.

I think I don't even know much about WebSockets :(

 

  • Like 1
Link to comment
Share on other sites

setavecata

+1
I don't also understood the working. I feel emby documentation is not proper, Lack examples.
I see anytime anyone asks something you guys point to your wiki page. Wiki pages is I feel don't help completely. They don't elaborate enough.
plex has much better support.

Edited by setavecata
Link to comment
Share on other sites

+1

I don't also understood the working. I feel emby documentation is not proper, Lack examples.

I see anytime anyone asks something you guys point to your wiki page. Wiki pages is I feel don't help completely. They don't elaborate enough.

plex has much better support.

 

Why would you say such a thing? Have you seen how active we are in the community?

Link to comment
Share on other sites

Yes the plugin/script is on the same server as emby

 

Ok, you can't use an apikey from another device to open a web socket connection. What is your end goal? What are you trying to do?

Link to comment
Share on other sites

setavecata

Why would you say such a thing? Have you seen how active we are in the community?

Sorry, didn't want to be mean. It's just what I felt. I've been reading your community forum since quite a while. I'm just trying to understand emby. I felt the documentation can bigger with rich examples code + use cases, everybody can relate. Maybe I'm wrong... maybe

Link to comment
Share on other sites

nahovevyse

I believe the end goal is to grab the device id and user id as soon as a user logs onto emby server. 

Yes the goal is to have the device id or Ip address related to a user Id.

Link to comment
Share on other sites

nahovevyse

Then I would use the /Sessions api. Please also make sure to explore our api documentation:

 

https://github.com/MediaBrowser/Emby/wiki

 

Thanks.

so with sessions

what will be the algorithm

 

session api will return all devices and the user logged in with those devices.

to limit a user X to few devices N I'll then have to

- loop through the objects (session api json output objects),

- Filter and get the devices for X count

- check 

     if  number_of_logged_in_devices_by_X >= N (permitted number of devices)

         Remove the allowed all devices check

         Use the /devices api and disable last used devices so that number_of_logged_in_devices_by_X becomes equal to N

 

There will be other scenarios like the user X wants to use the device we disabled etc

 

With this approach, the script will be running all the time and for ~1000-1500 user's I don't think it's a wise approach.

 

requesting EMBY gurus to share ideas/thoughts?

Link to comment
Share on other sites

nahovevyse

 - 

The Comment was originally posted on 29 March 2019- 07:18 AM 

 

] Why didn't anyone replied to the post?  -_-

If there's no better way or you're busy or don't wanna help or something else, whatever it is. Just say it.

 

At least reply.  :mellow: 

 

Edited by nahovevyse
Link to comment
Share on other sites

so with sessions

what will be the algorithm

 

session api will return all devices and the user logged in with those devices.

to limit a user X to few devices N I'll then have to

- loop through the objects (session api json output objects),

- Filter and get the devices for X count

- check 

     if  number_of_logged_in_devices_by_X >= N (permitted number of devices)

         Remove the allowed all devices check

         Use the /devices api and disable last used devices so that number_of_logged_in_devices_by_X becomes equal to N

 

There will be other scenarios like the user X wants to use the device we disabled etc

 

With this approach, the script will be running all the time and for ~1000-1500 user's I don't think it's a wise approach.

 

requesting EMBY gurus to share ideas/thoughts?

 

Yes, I guess you could do that, but we haven't tried that ourselves.

Link to comment
Share on other sites

nahovevyse

Yes, I guess you could do that, but we haven't tried that ourselves.

That's an idea. It's not feasible and will have loopholes for 100's of users's.

 

We just want to limit the user device usage via code, not manually.

Please help me with the process, I mean the things I should be using. 

 

First I tried websockets. Turned out they're not of use for this task.

Then sessions but the algo is not good.

 

What do you recommend??

How it should be done??

Edited by nahovevyse
Link to comment
Share on other sites

nahovevyse

Yes, I guess you could do that, but we haven't tried that ourselves.

I feel I'm not the only one trying to limit devices. Someone must have done this or anything related. This is nothing new but it's completely new for me tho lol

Edited by nahovevyse
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...