harrisi / bookplayerweb

web frontend for BookPlayer
MIT License
0 stars 0 forks source link

More robust syncing #9

Closed harrisi closed 11 months ago

harrisi commented 1 year ago

Currently, there are three events that cause a sync attempt:

  1. Player is paused (I don't particularly like this one)
  2. Current file is ends
  3. The player component is destroyed.

(2) seems quite reasonable. (3) happens when you change which file is being played. I would like for it to also occur when the page is closed. It may be as simple as syncing on beforeunload or visibilitychange.

All updates should be queued in a persistent cache before sending the request, and removed on success.

If the request fails, start exponentially backing off requests. During this, more events may be pushed to the queue, so all events need to be consolidated. The number of events possible grows exponentially as well, so this algorithm would ideally be logarithmic in time. I don't think this is possible in general.

harrisi commented 1 year ago

(3) is partially solved by a3a28c8c6121bd2146d044b1f70816dfc15d0c5d. It works for page closes but doesn't seem to work on browser quit (in some browsers), and firefox doesn't support keepalive. I may try using navigator.sendBeacon.

harrisi commented 11 months ago

I'm going to close this since the sync procedure has changed.