Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

893 B
Raw Blame
package room

// ExpireEmptyRooms commits storage retirement before returning effect cleanup.
func (s *Store) ExpireEmptyRooms(beforeMs int64) ([]ClosedRoom, error) {
	return s.abandonRooms(s.EmptyRoomIDs(beforeMs))
}

// EmptyRoomIDs returns empty rooms in creation order, including never-joined
// rooms. A connected Host or Viewer protects an idle chat room just like a share.
// Callers retire candidates synchronously under the same signaling lock.
func (s *Store) EmptyRoomIDs(beforeMs int64) []string {
	var ids []string
	for id, room := range s.rooms.All() {
		if room.emptySinceMs <= beforeMs && !roomOccupied(room) {
			ids = append(ids, id)
		}
	}
	return ids
}

func roomOccupied(room *Room) bool {
	if room.host != nil && room.host.sessionID != "" {
		return true
	}
	for _, viewer := range room.viewers.All() {
		if viewer.sessionID != "" {
			return true
		}
	}
	return false
}