Live video on the AT Protocol

model: just use sql for recent livestreams

+5 -31
+2 -9
js/app/features/bluesky/blueskySlice.tsx
··· 293 const { bluesky } = thunkAPI.getState() as { 294 bluesky: BlueskyState; 295 }; 296 - let bskyAgent: Agent; 297 - if (!bluesky.pdsAgent) { 298 - // unauthed request to Bluesky Appview 299 - bskyAgent = new Agent("https://public.api.bsky.app"); 300 - } else { 301 - bskyAgent = bluesky.pdsAgent; 302 - } 303 - 304 - if (!bskyAgent) throw new Error("No Agent!"); 305 306 return await bskyAgent.getProfiles({ 307 actors: actors,
··· 293 const { bluesky } = thunkAPI.getState() as { 294 bluesky: BlueskyState; 295 }; 296 + // unauthed request to Bluesky Appview 297 + const bskyAgent = new Agent("https://public.api.bsky.app"); 298 299 return await bskyAgent.getProfiles({ 300 actors: actors,
+3 -22
pkg/model/livestream.go
··· 76 return &livestream, nil 77 } 78 79 - // type for livestream with seg start time 80 - type LivestreamWithSegmentStartTime struct { 81 - Livestream 82 - // should be latest_segments.latest_segment_start_time in the query 83 - LatestSegmentStartTime string 84 - } 85 - 86 // GetLatestLivestreams returns the most recent livestreams, given a limit and a cursor 87 // Only gets livestreams with a valid segment no less than 30 seconds old 88 func (m *DBModel) GetLatestLivestreams(limit int, before *time.Time) ([]Livestream, error) { 89 - var recentLivestreams []LivestreamWithSegmentStartTime 90 thirtySecondsAgo := time.Now().Add(-30 * time.Second) 91 92 // get latest segment for the repo DID ··· 96 m.DB.Table("segments"). 97 Select("repo_did, MAX(start_time)"). 98 Group("repo_did")). 99 - Where("start_time > ?", thirtySecondsAgo). 100 Group("repo_did") 101 102 rankedLivestreamsSubQuery := m.DB.Table("livestreams"). ··· 130 return nil, nil 131 } 132 133 - var finalStreams []Livestream 134 - 135 - // for each seg, put results in map if seg start time is after 30 seconds ago 136 - for _, seg := range recentLivestreams { 137 - layout := "2006-01-02 15:04:05.000+00:00" 138 - segStartTime, _ := time.Parse(layout, seg.LatestSegmentStartTime) 139 - if segStartTime.After(thirtySecondsAgo) { 140 - finalStreams = append(finalStreams, seg.Livestream) 141 - //fmt.Printf("seg start time: %s vs 30 seconds ago: %s\n", segStartTime, thirtySecondsAgo.UTC()) 142 - } 143 - } 144 - 145 - return finalStreams, nil 146 }
··· 76 return &livestream, nil 77 } 78 79 // GetLatestLivestreams returns the most recent livestreams, given a limit and a cursor 80 // Only gets livestreams with a valid segment no less than 30 seconds old 81 func (m *DBModel) GetLatestLivestreams(limit int, before *time.Time) ([]Livestream, error) { 82 + var recentLivestreams []Livestream 83 thirtySecondsAgo := time.Now().Add(-30 * time.Second) 84 85 // get latest segment for the repo DID ··· 89 m.DB.Table("segments"). 90 Select("repo_did, MAX(start_time)"). 91 Group("repo_did")). 92 + Where("start_time > ?", thirtySecondsAgo.UTC()). 93 Group("repo_did") 94 95 rankedLivestreamsSubQuery := m.DB.Table("livestreams"). ··· 123 return nil, nil 124 } 125 126 + return recentLivestreams, nil 127 }