Jump to content


Photo

Handling real-time library updates to the client

websocket api real-time client

  • Please log in to reply
3 replies to this topic

#1 roblav96 OFFLINE  

roblav96

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:32 AM

Posted 13 October 2019 - 01:28 AM

TLDR

How does the server tell a client to re-render library content?

 

A few example use-cases are:

  • client searches for library media, server dynamically adds media to library, client never receives library updates until they type the next word
  • client views a library item, server dynamically downloads subtitles for library item, client never receives subtitle updates until they press back and view the library item again

Things I've tried:

  • POST /Library/Media/Updated only downloads metadata for parameters in the request body
  • POST /Sessions/{Id}/Message/LibraryChanged command but the clients never receive a websocket message, the only time I've witnesses the client receive a LibraryChanged message is a full minute after a library scan is completed, would be nice to manually send this command immediately after the library scan

Issues I've come across:

  • Roku clients never receive updates of any kind from the server, most likely related to using roku's native remote control api which is restricted to same subnet ip addresses


#2 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 157224 posts
  • Local time: 02:32 AM

Posted 23 October 2019 - 03:19 AM

The server tells the clients via the websocket LibraryChanged messages, and yes, that can take a minute or so after the change actually happens.

 

 

 

POST /Library/Media/Updated only downloads metadata for parameters in the request body

This tells the server that a file changed, which then feeds that notification into the same place that the realtime monitor notifies. And then eventually later this will send LibraryChanged if something in the database was updated as a result of the file changes.

 

 

 

client searches for library media, server dynamically adds media to library, client never receives library updates until they type the next word

When does the server dynamically add media?



#3 roblav96 OFFLINE  

roblav96

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:32 AM

Posted 25 October 2019 - 01:41 AM

Is there anyway I can manually send the LibraryChanged event to clients via websocket on the server?

 

I've tried something like:

await Session.command('LibraryChanged', {
	CollectionFolders: [],
	FoldersAddedTo: ['4'],
	FoldersRemovedFrom: [],
	IsEmpty: false,
	ItemsAdded: [],
	ItemsRemoved: [],
	ItemsUpdated: Items.map(v => v.Id),
})

but the clients never received.

 

The server dynamically adds media from my search plugin:

https://github.com/r...y/search.ts#L98



#4 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 157224 posts
  • Local time: 02:32 AM

Posted 25 October 2019 - 02:07 AM

No, you can't force that to be sent out. You should use /Library/Media/Updated. This will tell the server that files were changed, and eventually this will lead to LibraryChanged messages getting sent out.

 

Having said that, I'm not sure what your code is doing, but if it's creating or editing strm files then you might just be able to enable the realtime monitor and let that do the work for you of notifying the apps.







Also tagged with one or more of these keywords: websocket, api, real-time, client

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users