init
This commit is contained in:
80
server/internal/room/model.go
Normal file
80
server/internal/room/model.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package room
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
PlaybackIdle = "idle"
|
||||
PlaybackPlaying = "playing"
|
||||
PlaybackPaused = "paused"
|
||||
|
||||
SourceModeDirect = "direct"
|
||||
SourceModeProxy = "proxy"
|
||||
)
|
||||
|
||||
type Room struct {
|
||||
Code string `json:"code"`
|
||||
OwnerDeviceID string `json:"ownerDeviceId,omitempty"`
|
||||
OwnerLastSeenAt int64 `json:"ownerLastSeenAt,omitempty"`
|
||||
OnlineCount int `json:"onlineCount"`
|
||||
Source *Source `json:"source,omitempty"`
|
||||
Playback Playback `json:"playback"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
ExpiresAt int64 `json:"expiresAt"`
|
||||
}
|
||||
|
||||
type Source struct {
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
URL string `json:"url"`
|
||||
IsLive bool `json:"isLive"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
ProxyPath string `json:"proxyPath,omitempty"`
|
||||
}
|
||||
|
||||
type Playback struct {
|
||||
State string `json:"state"`
|
||||
PositionMS int64 `json:"positionMs"`
|
||||
ServerUpdatedAt int64 `json:"serverUpdatedAt"`
|
||||
TargetLatencyMS int64 `json:"targetLatencyMs,omitempty"`
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
Room Room `json:"room"`
|
||||
IsOwner bool `json:"isOwner"`
|
||||
DeviceID string `json:"deviceId"`
|
||||
ServerNow int64 `json:"serverNow"`
|
||||
}
|
||||
|
||||
func New(code string, ttl time.Duration) Room {
|
||||
now := time.Now()
|
||||
return Room{
|
||||
Code: code,
|
||||
Playback: Playback{State: PlaybackIdle, ServerUpdatedAt: now.UnixMilli()},
|
||||
CreatedAt: now.UnixMilli(),
|
||||
UpdatedAt: now.UnixMilli(),
|
||||
ExpiresAt: now.Add(ttl).UnixMilli(),
|
||||
OnlineCount: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Room) PublicFor(deviceID string) Room {
|
||||
out := r
|
||||
if out.Source != nil {
|
||||
src := *out.Source
|
||||
if src.Mode == SourceModeProxy {
|
||||
src.URL = src.ProxyPath
|
||||
src.Headers = nil
|
||||
src.Username = ""
|
||||
src.Password = ""
|
||||
}
|
||||
out.Source = &src
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func NowMS() int64 {
|
||||
return time.Now().UnixMilli()
|
||||
}
|
||||
Reference in New Issue
Block a user