0

I can go to the webpage https://open.spotify.com and select songs that are then immediately played on my desktop spotify application. How does this work? I could imagine a scenario where the webpage sends a request to a server which then tells my desktop application to play, but the website and my application seem too in sync. Sure the web is fast, but the song time counters are perfectly in sync and there is no lag when I click play.

I guess they could do something clever with syncing the song time counter, but I'm wondering if they're dong something even more clever: not using a server at all.

So the real question: Is there a way to have direct communication between a webpage and an application running on the client?

Andy Schmitt
  • 70
  • 1
  • 5
  • I'm not familiar with `spotify` technology stack but they could easily have a socket connection from your desktop application to their server, once you select a song a message is sent through the socket connection to your desktop app and the song starts playing. Since the socket is the fastest way to send small bits of data it wouldn't be surprising that they're in very good sync. – anteAdamovic Oct 21 '17 at 07:40

1 Answers1

1

The mechanism is described on How does the Spotify web browser button interact with the Spotify app?. When you install Spotify's desktop application, a process called SpotifyWebHelper runs in the background. This process acts as a local server and receives requests from open.spotify.com to interact with the current playback. As you see, there is a way to communicate a web site and a local application.

It's worth noting that there is an increase concern by browser vendors about this mechanism (see https://bugs.chromium.org/p/chromium/issues/detail?id=378566) and it will stop working at some point in the future. A more future-proof solution could be based on a proxy service that gets requests from the web page and updates your application, and viceversa. Web sockets are a good candidate for this. Although the proxy, acting as a state management service, introduces some delay, it also allows for some other use cases: eg you don't need to have the application installed on the same machine on which the web page is browsed, and one could for instance control a mobile client.

José M. Pérez
  • 3,199
  • 22
  • 37