Commit 558c6513 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Redesign GeoDrops into live location sharing (was: one-off song pins)

Replaces the "drop a specific song at this exact point, once" model
with a live broadcast: share your position and whatever you're
currently playing, updated automatically as you move or switch songs,
visible to anyone nearby while you're sharing. Matches the backend's
GeoDrop -> LiveLocation redesign.

- "Share my live location" toggle: starts watchPosition, pushes an
  update on every meaningful location/song change, plus a periodic
  heartbeat (keeps the row from expiring server-side while nothing's
  changed) - matching the backend's staleness-expiry approach, since a
  closing tab can't reliably notify the server with an authenticated
  request on unload.
- Nearby list now live-updates on a short poll, not just on demand.
- New: "Play my geo playlist" - shuffles everyone nearby's current song
  into the shared player's queue (Fisher-Yates, not the common biased
  Array.sort(() => Math.random() - 0.5) shuffle) and starts playing.
- Only broadcasts a song when it's a real LibrarySong reference
  (Soundmarks/Rooms/Posts-sourced playback uses synthetic negative ids
  for player identity, not something safe to send as song_id).
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent dd72364f
Pipeline #1078 failed with stage
......@@ -57,35 +57,48 @@ export async function fetchPostStreamUrl(postId: number): Promise<string> {
return URL.createObjectURL(blob)
}
export interface GeoDrop {
id: number
export interface LiveListener {
user_id: number
username: string | null
/** Null if they're sharing their location but not currently playing anything. */
song: SocialSong | null
latitude: number
longitude: number
dropped_at: string
updated_at: string
}
export function createGeoDrop(songId: number, latitude: number, longitude: number) {
return apiFetch<GeoDrop>('/social/geo-drop', {
method: 'POST',
json: { song_id: songId, latitude, longitude },
/** Upserts the caller's live position and what they're currently playing - call this on every
* meaningful location/song change, plus periodically as a heartbeat, while sharing is on.
* songId is only meaningful when it's a real LibrarySong id (playback sourced from Soundmarks/
* Rooms/Posts/other live locations uses synthetic negative ids for player identity, not a real
* library reference - pass null for those instead of a bogus id). */
export function shareLiveLocation(latitude: number, longitude: number, songId: number | null) {
return apiFetch<LiveListener>('/social/live-location', {
method: 'PUT',
json: { latitude, longitude, song_id: songId },
})
}
export function getNearbyDrops(lat: number, lon: number, radiusKm = 5) {
return apiFetch<{ drop: GeoDrop; distance_km: number }[]>(
`/social/geo-drop/nearby?lat=${lat}&lon=${lon}&radius_km=${radiusKm}`,
export function stopSharingLiveLocation() {
return apiFetch<{ status: string }>('/social/live-location', { method: 'DELETE' })
}
/** Other nearby users currently sharing their location, self-excluded, sorted by distance.
* Anyone who's gone quiet for a while (closed the tab, lost connection) drops out on their
* own server-side - see LIVE_LOCATION_STALE_AFTER in the backend. */
export function getNearbyLiveListeners(lat: number, lon: number, radiusKm = 5) {
return apiFetch<{ listener: LiveListener; distance_km: number }[]>(
`/social/live-location/nearby?lat=${lat}&lon=${lon}&radius_km=${radiusKm}`,
)
}
/** For PlayerContext's `streamUrl` override - fetches a dropped song as an authenticated blob,
* regardless of who uploaded it (mirrors fetchRoomStreamUrl/fetchSoundmarkStreamUrl against the
* analogous drop-scoped endpoint). Caller is responsible for calling URL.revokeObjectURL(). */
export async function fetchGeoDropStreamUrl(dropId: number): Promise<string> {
/** For PlayerContext's `streamUrl` override - fetches whatever a nearby user is currently
* playing as an authenticated blob, regardless of who uploaded it (mirrors
* fetchRoomStreamUrl/fetchSoundmarkStreamUrl against the analogous endpoint). Caller is
* responsible for calling URL.revokeObjectURL(). */
export async function fetchLiveLocationStreamUrl(userId: number): Promise<string> {
const token = getAccessToken()
const res = await fetch(`${API_BASE_URL}/social/geo-drop/${dropId}/stream`, {
const res = await fetch(`${API_BASE_URL}/social/live-location/${userId}/stream`, {
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
})
if (!res.ok) {
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment