Liking cljdoc? Tell your friends :D

dk.simongray.play-nice.page.tabs

One player at a time across the tabs of an app, through Web Locks.

On a desktop, no engine stops the audio of one tab when another tab starts, so two tabs of a podcast app play at once and race to save the position. attach! holds a lock named for the app while the element plays, and takes it from any other tab that holds it, which then pauses its own element:

(def detach!
  (attach! audio "my-podcast-app"))

For an app that sends its playback to its other tabs itself, newest picks the newest of the playbacks that a tab received, and position moves one on to where it is by now.

The functions take these opts:

  • :window, the window whose navigator holds the locks, instead of the page's, e.g. a stand-in in a test
One player at a time across the tabs of an app, through Web Locks.

On a desktop, no engine stops the audio of one tab when another tab
starts, so two tabs of a podcast app play at once and race to save the
position. attach! holds a lock named for the app while the element
plays, and takes it from any other tab that holds it, which then pauses
its own element:

    (def detach!
      (attach! audio "my-podcast-app"))

For an app that sends its playback to its other tabs itself, newest
picks the newest of the playbacks that a tab received, and position
moves one on to where it is by now.

The functions take these opts:

- :window, the window whose navigator holds the locks, instead of the
  page's, e.g. a stand-in in a test
raw docstring

attach!cljs

(attach! element name)
(attach! element name opts)

Hold the Web Lock of name while the media element plays, with the opts above, and pause the element when another tab takes the lock. Return a function that detaches it.

The element takes the lock from any holder when it plays, and lets it go when it pauses and at pagehide, since a held lock keeps a page out of the back/forward cache. Where the browser has no Web Locks, the call does nothing. Where the window fires no events, e.g. Node's global object, which has Web Locks from Node 24.5, the element still takes the lock as it plays and lets go of it as it pauses.

Hold the Web Lock of `name` while the media `element` plays, with the
`opts` above, and pause the element when another tab takes the lock.
Return a function that detaches it.

The element takes the lock from any holder when it plays, and lets it
go when it pauses and at pagehide, since a held lock keeps a page out of
the back/forward cache. Where the browser has no Web Locks, the call
does nothing. Where the window fires no events, e.g. Node's global
object, which has Web Locks from Node 24.5, the element still takes the
lock as it plays and lets go of it as it pauses.
raw docstring

heartbeat-mscljs

How many milliseconds may pass between two playbacks that a tab sends while its element plays. newest counts the tab as gone after three.

How many milliseconds may pass between two playbacks that a tab sends
while its element plays. newest counts the tab as gone after three.
raw docstring

newestcljs

(newest states now)

The newest of the playback states of the tabs at now, in milliseconds since the epoch: one that plays, and else the one that changed last. A playing one that hasn't told where it is for three heartbeats counts as paused, and :gone.

Each state is a map of keys from media/state, with :at, the time in milliseconds at which its :current-time was taken, and :changed, when it last changed.

The newest of the playback `states` of the tabs at `now`, in
milliseconds since the epoch: one that plays, and else the one that
changed last. A playing one that hasn't told where it is for three
heartbeats counts as paused, and :gone.

Each state is a map of keys from media/state, with :at, the time in
milliseconds at which its :current-time was taken, and :changed, when
it last changed.
raw docstring

positioncljs

(position {:keys [current-time at paused status playback-rate duration]
           :as state}
          now)

Where the playback state is at now, in milliseconds since the epoch: its :current-time, moved on by the time since its :at at its rate while it plays, and no further than its duration.

Where the playback `state` is at `now`, in milliseconds since the epoch:
its :current-time, moved on by the time since its :at at its rate while
it plays, and no further than its duration.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close