Jump to content


Photo

Getting user login and device in use via websocket API

websocket api login device

  • Please log in to reply
20 replies to this topic

#1 nahovevyse OFFLINE  

nahovevyse

    Member

  • Members
  • 16 posts
  • Local time: 07:43 PM

Posted 16 March 2019 - 03:06 AM

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 :(

 


  • setavecata likes this

#2 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 135803 posts
  • Local time: 09:43 PM

Posted 16 March 2019 - 12:16 PM

What do you mean after your user logs into the server?

#3 nils12 OFFLINE  

nils12

    Member

  • Members
  • 12 posts
  • Local time: 03:43 AM

Posted 16 March 2019 - 12:37 PM

when a user access emby server from his device, thats what he means. 



#4 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 135803 posts
  • Local time: 09:43 PM

Posted 16 March 2019 - 10:36 PM

Is this script being run from the same device?

#5 nils12 OFFLINE  

nils12

    Member

  • Members
  • 12 posts
  • Local time: 03:43 AM

Posted 17 March 2019 - 03:03 AM

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

#6 setavecata OFFLINE  

setavecata

    Newbie

  • Members
  • 2 posts
  • Local time: 07:13 AM

Posted 18 March 2019 - 05:17 AM

+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, 18 March 2019 - 08:29 AM.


#7 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 135803 posts
  • Local time: 09:43 PM

Posted 18 March 2019 - 01:53 PM

+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?



#8 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 135803 posts
  • Local time: 09:43 PM

Posted 18 March 2019 - 01:54 PM

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?



#9 nils12 OFFLINE  

nils12

    Member

  • Members
  • 12 posts
  • Local time: 03:43 AM

Posted 18 March 2019 - 02:12 PM

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



#10 setavecata OFFLINE  

setavecata

    Newbie

  • Members
  • 2 posts
  • Local time: 07:13 AM

Posted 19 March 2019 - 12:03 AM

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



#11 nahovevyse OFFLINE  

nahovevyse

    Member

  • Members
  • 16 posts
  • Local time: 07:43 PM

Posted 19 March 2019 - 12:52 AM

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.



#12 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 135803 posts
  • Local time: 09:43 PM

Posted 19 March 2019 - 11:02 AM

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

 

https://github.com/M...owser/Emby/wiki

 

Thanks.



#13 nahovevyse OFFLINE  

nahovevyse

    Member

  • Members
  • 16 posts
  • Local time: 07:43 PM

Posted 27 March 2019 - 08:22 AM

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

 

https://github.com/M...owser/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?



#14 nils12 OFFLINE  

nils12

    Member

  • Members
  • 12 posts
  • Local time: 03:43 AM

Posted 28 March 2019 - 09:57 AM

Hi Luke, 

 

Can you help on this please ? 



#15 nils12 OFFLINE  

nils12

    Member

  • Members
  • 12 posts
  • Local time: 03:43 AM

Posted 29 March 2019 - 09:18 AM

 - 


Edited by nils12, 29 March 2019 - 09:24 AM.


#16 nils12 OFFLINE  

nils12

    Member

  • Members
  • 12 posts
  • Local time: 03:43 AM

Posted 29 March 2019 - 09:24 AM

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

 

Luke? 



#17 nahovevyse OFFLINE  

nahovevyse

    Member

  • Members
  • 16 posts
  • Local time: 07:43 PM

Posted 30 March 2019 - 12:40 AM

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

 

https://github.com/M...owser/Emby/wiki

 

Thanks.

Everyone just vanished???
lol



#18 nahovevyse OFFLINE  

nahovevyse

    Member

  • Members
  • 16 posts
  • Local time: 07:43 PM

Posted 01 April 2019 - 05:12 AM

 - 

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, 03 April 2019 - 03:33 AM.


#19 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 135803 posts
  • Local time: 09:43 PM

Posted 01 April 2019 - 01:00 PM

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.



#20 nahovevyse OFFLINE  

nahovevyse

    Member

  • Members
  • 16 posts
  • Local time: 07:43 PM

Posted 03 April 2019 - 03:23 AM

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, 03 April 2019 - 03:33 AM.






Also tagged with one or more of these keywords: websocket, api, login, device

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users