I’m working on a Spotify app and need to create direct communication between users who have my app installed. My goal is to establish peer-to-peer connections using JavaScript within the Spotify client environment.
I initially tried using PeerJS for its simplicity, but I’m open to other solutions. When attempting to connect to the PeerJS server, I get an error saying WebRTC isn’t supported by the browser. This is strange since Spotify uses Chrome as its base.
Are there other ways to create direct client-to-client connections in this environment? Or am I stuck with server-based communication? Any suggestions for libraries or approaches that work well with Spotify’s JavaScript environment would be helpful.
spotify’s chromium build blocks webrtc apis for security reasons in their app sandbox. i tried the simple-peer library - same problem. ended up going with firebase realtime database instead. works perfectly for user messaging and updates instantly. not technically p2p, but it feels like it.
When I started working with Spotify’s platform, I encountered similar limitations regarding WebRTC. I found that leveraging Socket.IO for real-time communication pair with Spotify’s Web API is a more effective approach. While direct peer connections aren’t feasible, you can achieve a responsive messaging experience. I set up an Express server using Socket.IO rooms associated with Spotify user IDs, which manages message routing effectively. The latency is quite acceptable, and the error handling is actually superior to what WebRTC offers. Remember to implement Spotify’s OAuth tokens for authentication to ensure secure connections.
I ran into the same problems building for Spotify’s app framework. It’s not that WebRTC isn’t supported - Spotify’s sandbox just blocks the browser APIs that WebRTC needs. Libraries like PeerJS can’t access the media and networking APIs properly. I got it working with WebSockets for signaling and a lightweight Node.js server to handle connections. You get near real-time communication, but it’s not true peer-to-peer. Also worth checking out Spotify’s Connect API for basic user interactions, though the sandbox limits what you can do.