Documentation ¶
Index ¶
- Constants
- type Chunk
- type ChunkID
- type ChunkInfo
- type ChunkList
- type DurationMs
- type ExpandedReplayFormatter
- func (l *ExpandedReplayFormatter) Create() (io.WriteCloser, error)
- func (l *ExpandedReplayFormatter) CreateChunk(id ChunkID) (io.WriteCloser, error)
- func (l *ExpandedReplayFormatter) CreateEndOfGameStats() (io.WriteCloser, error)
- func (l *ExpandedReplayFormatter) CreateKeyFrame(id KeyFrameID) (io.WriteCloser, error)
- func (l *ExpandedReplayFormatter) HasChunk(id ChunkID) bool
- func (l *ExpandedReplayFormatter) HasEndOfGameStats() bool
- func (l *ExpandedReplayFormatter) HasKeyFrame(id KeyFrameID) bool
- func (l *ExpandedReplayFormatter) Open() (io.ReadCloser, error)
- func (l *ExpandedReplayFormatter) OpenChunk(id ChunkID) (io.ReadCloser, error)
- func (l *ExpandedReplayFormatter) OpenEndOfGameStats() (io.ReadCloser, error)
- func (l *ExpandedReplayFormatter) OpenKeyFrame(id KeyFrameID) (io.ReadCloser, error)
- type GameMetadata
- type KeyFrame
- type KeyFrameID
- type KeyFrameInfo
- type KeyFrameList
- type LastChunkInfo
- type LolTime
- type Replay
- func (r *Replay) AddGameInfo(info lol.CurrentGameInfo)
- func (r *Replay) ChunkByID(id ChunkID) (*Chunk, bool)
- func (r *Replay) Consolidate()
- func (r *Replay) HighlightSummoner(id lol.SummonerID) error
- func (r *Replay) KeyFrameByID(id KeyFrameID) (*KeyFrame, bool)
- func (r *Replay) LoadData(loader ReplayDataLoader) error
- func (r *Replay) MergeFromLastChunkInfo(ci LastChunkInfo)
- func (r *Replay) MergeFromMetaData(gm GameMetadata)
- func (r *Replay) Save(writer ReplayDataWriter) error
- func (r *Replay) SaveData(writer ReplayDataWriter) error
- func (r *Replay) SaveWithData(writer ReplayDataWriter) error
- type ReplayDataFormatter
- type ReplayDataLoader
- type ReplayDataWriter
- type ReplayManager
- type ReplayPrinter
- type ReplayServer
- type SpectateAPI
- func (a *SpectateAPI) Format(function SpectateFunction, param int) string
- func (a *SpectateAPI) Get(function SpectateFunction, param int, v interface{}) error
- func (a *SpectateAPI) ReadAll(function SpectateFunction, param int, w io.Writer) error
- func (a *SpectateAPI) SpectateGame(encryptionKey string, w ReplayDataWriter) (*Replay, error)
- func (a *SpectateAPI) Version() (string, error)
- func (a *SpectateAPI) VersionURL() string
- type SpectateFunction
- type XdgReplayManager
- func (m *XdgReplayManager) CleanUp() error
- func (m *XdgReplayManager) Create(region *lol.Region, id lol.GameID) (ReplayDataWriter, error)
- func (m *XdgReplayManager) Delete(region *lol.Region, id lol.GameID) error
- func (m *XdgReplayManager) Get(region *lol.Region, id lol.GameID) (ReplayDataLoader, error)
- func (m *XdgReplayManager) Replays() map[string][]*Replay
- func (m *XdgReplayManager) Store(r *Replay) error
Constants ¶
const ( // GetGameMetaData is a function to fetch game metadata GetGameMetaData SpectateFunction = "getGameMetaData" // GetLastChunkInfo is a function that returns the LastChunkInfo GetLastChunkInfo SpectateFunction = "getLastChunkInfo" // GetGameDataChunk returns the binary compressed and encoded data for a Chunk GetGameDataChunk SpectateFunction = "getGameDataChunk" // GetKeyFrame returns the binary compressed and encoded data for a Keyframe GetKeyFrame SpectateFunction = "getKeyFrame" //EndOfGameStats returns a json data about game stats EndOfGameStats SpectateFunction = "endOfGameStats" //Version returns current version Version SpectateFunction = "version" // Prefix is the prefix of the spectate API Prefix string = "/observer-mode/rest/consumer/" )
const ( //NullParam should be passed for function without a parameter NullParam int = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chunk ¶
type Chunk struct { ChunkInfo KeyFrame KeyFrameID // contains filtered or unexported fields }
A Chunk represent data modification of a Replay between frames
type ChunkInfo ¶
type ChunkInfo struct { ID ChunkID `json:"id"` Duration DurationMs `json:"duration"` ReceivedTime LolTime `json:"receivedTime"` }
ChunkInfo are information about chunk
type ChunkList ¶
type ChunkList []Chunk
A ChunkList is slice of Chunk that implements sort.Interface
type DurationMs ¶
type DurationMs int64
DurationMs represent the number of milliseconds between two point in time
func (DurationMs) Duration ¶
func (d DurationMs) Duration() time.Duration
Duration casts a DurationMs to time.Duration
type ExpandedReplayFormatter ¶
type ExpandedReplayFormatter struct {
// contains filtered or unexported fields
}
ExpandedReplayFormatter is a ReplayDataLoader that expand all its data to several file on the hardrive. It is meant to
func NewExpandedReplayFormatter ¶
func NewExpandedReplayFormatter(basedir string) (*ExpandedReplayFormatter, error)
NewExpandedReplayFormatter returns a ReplayDataLoader that will save and load data from directory basedir
func (*ExpandedReplayFormatter) Create ¶
func (l *ExpandedReplayFormatter) Create() (io.WriteCloser, error)
Create returns a truncatde io.WriteCloser to write replay data
func (*ExpandedReplayFormatter) CreateChunk ¶
func (l *ExpandedReplayFormatter) CreateChunk(id ChunkID) (io.WriteCloser, error)
CreateChunk returns a truncated io.WriteCloser to write data for a given Chunk
func (*ExpandedReplayFormatter) CreateEndOfGameStats ¶
func (l *ExpandedReplayFormatter) CreateEndOfGameStats() (io.WriteCloser, error)
CreateEndOfGameStats returns a truncated io.WriteCloser to write data for the end of game statistics
func (*ExpandedReplayFormatter) CreateKeyFrame ¶
func (l *ExpandedReplayFormatter) CreateKeyFrame(id KeyFrameID) (io.WriteCloser, error)
CreateKeyFrame returns a truncated io.WriteCloser to write data for a given KeyFrame
func (*ExpandedReplayFormatter) HasChunk ¶
func (l *ExpandedReplayFormatter) HasChunk(id ChunkID) bool
HasChunk returns true if data is available for a given Chunk
func (*ExpandedReplayFormatter) HasEndOfGameStats ¶
func (l *ExpandedReplayFormatter) HasEndOfGameStats() bool
HasEndOfGameStats returns true if data is available for End of Game statistics
func (*ExpandedReplayFormatter) HasKeyFrame ¶
func (l *ExpandedReplayFormatter) HasKeyFrame(id KeyFrameID) bool
HasKeyFrame returns true if data is available for a given KeyFrame
func (*ExpandedReplayFormatter) Open ¶
func (l *ExpandedReplayFormatter) Open() (io.ReadCloser, error)
Open returns a io.ReadCloser for reading replay data
func (*ExpandedReplayFormatter) OpenChunk ¶
func (l *ExpandedReplayFormatter) OpenChunk(id ChunkID) (io.ReadCloser, error)
OpenChunk returns a io.ReadCloser for reading data for a given Chunk
func (*ExpandedReplayFormatter) OpenEndOfGameStats ¶
func (l *ExpandedReplayFormatter) OpenEndOfGameStats() (io.ReadCloser, error)
OpenEndOfGameStats returns a io.ReadCloser for reading data for the end of game statistics
func (*ExpandedReplayFormatter) OpenKeyFrame ¶
func (l *ExpandedReplayFormatter) OpenKeyFrame(id KeyFrameID) (io.ReadCloser, error)
OpenKeyFrame returns a io.ReadCloser for reading data for a given KeyFrame
type GameMetadata ¶
type GameMetadata struct { GameKey struct { ID lol.GameID `json:"gameId"` PlatformID string `json:"platformId"` } `json:"gameKey"` GameServerAddress string `json:"gameServerAddress"` Port int `json:"port"` EncryptionKey string `json:"encryptionKey"` ChunkTimeInterval DurationMs `json:"chunkTimeInterval"` StartTime LolTime `json:"startTime"` LastChunkID int `json:"lastChunkId"` LastKeyFrameID int `json:"lastKeyFrameId"` EndStartupChunkID int `json:"endStartupChunkId"` DelayTime DurationMs `json:"delayTime"` PendingAvailableChunkInfo []ChunkInfo `json:"pendingAvailableChunkInfo"` PendingAvailableKeyFrameInfo []KeyFrameInfo `json:"pendingAvailableKeyFrameInfo"` KeyFrameInterval DurationMs DecodedEncryptionKey string `json:"decodedEncryptionKey"` StartGameChunkID int `json:"startGameChunkId"` ClientAddedLag DurationMs `json:"clientAddedLag"` ClientBackFetchingEnabled bool `json:"clientBackFetchingEnabled"` ClientBackFetchingFreq int `json:"clientBackFetchingFreq"` InterestScore int `json:"interestScore"` FeaturedGame bool `json:"featuredGame"` CreateTime LolTime `json:"createTime"` EndGameChunkID int `json:"endGameChunkId"` EndGameKeyFrameID int `json:"endGameKeyFrameId"` }
GameMetadata represents a game metadata for downloading / replaying it. This is the data send and receive by the unofficial LoL spectator API
type KeyFrame ¶
type KeyFrame struct { KeyFrameInfo Chunks []ChunkID // contains filtered or unexported fields }
A KeyFrame Represent a Replay state at a given point in time.
type KeyFrameInfo ¶
type KeyFrameInfo struct { ID KeyFrameID `json:"id"` ReceivedTime LolTime `json:"receivedTime"` NextChunkID ChunkID `json:"nextChunkId"` }
KeyFrameInfo are information about KeyFrame
type KeyFrameList ¶
type KeyFrameList []KeyFrame
A KeyFrameList is slice of KeyFrame that implements sort.Interface
func (KeyFrameList) Len ¶
func (l KeyFrameList) Len() int
Len returns the length of the KeyFrameList
func (KeyFrameList) Less ¶
func (l KeyFrameList) Less(i, j int) bool
Less returns true if element in i should be sorted before element in j in the KeyFrameList
func (KeyFrameList) Swap ¶
func (l KeyFrameList) Swap(i, j int)
Swap swaps the element placed in i and j in the KeyFrameList
type LastChunkInfo ¶
type LastChunkInfo struct { ID ChunkID `json:"chunkId"` AvailableSince DurationMs `json:"availableSince"` NextAvailableChunk DurationMs `json:"nextAvailableChunk"` AssociatedKeyFrameID KeyFrameID `json:"keyFrameId"` NextChunkID ChunkID `json:"nextChunkId"` EndStartupChunkID ChunkID `json:"endStartupChunkId"` StartGameChunkID ChunkID `json:"startGameChunkId"` EndGameChunkID ChunkID `json:"endGameChunkId"` Duration DurationMs `json:"duration"` }
LastChunkInfo represents latest available Chunk informations
type LolTime ¶
LolTime is a time.Time that (Un)Marshal -izes itself according to Lol date format
func (LolTime) MarshalJSON ¶
MarshalJSON marshalize the time to the lol format
func (LolTime) MarshalText ¶
MarshalText marshalize the time to the lol format
func (*LolTime) UnmarshalJSON ¶
UnmarshalJSON unmarshalize the time according to the lol format
func (*LolTime) UnmarshalText ¶
UnmarshalText unmarshalize the time according to the lol format
type Replay ¶
type Replay struct { Chunks []Chunk KeyFrames []KeyFrame MetaData GameMetadata //Version of the spectator API Version string //Encryption Key used by the data EncryptionKey string //GameInfo contains the GameInformation GameInfo lol.CurrentGameInfo // PlayerOfInterest PlayerOfInterest lol.SummonerID // contains filtered or unexported fields }
A Replay is a in memory structure that represent all data that is needed to spectate a LoL game.
func LoadReplay ¶
func LoadReplay(loader ReplayDataLoader) (*Replay, error)
LoadReplay is loading the Replay data (without loading binary data like KeyFrame, Chunk and EndOfGameStats) from a ReplayDataLoader
func LoadReplayWithData ¶
func LoadReplayWithData(loader ReplayDataLoader) (*Replay, error)
LoadReplayWithData is loading all of a Replay data from a ReplayDataLoader
func (*Replay) AddGameInfo ¶
func (r *Replay) AddGameInfo(info lol.CurrentGameInfo)
AddGameInfo adds game information for a
func (*Replay) Consolidate ¶
func (r *Replay) Consolidate()
Consolidate is reconstructing missing internal data (KeyFrame and Chunk association) from the internal data we haev so far.
func (*Replay) HighlightSummoner ¶
HighlightSummoner highlights a summonner name
func (*Replay) KeyFrameByID ¶
func (r *Replay) KeyFrameByID(id KeyFrameID) (*KeyFrame, bool)
KeyFrameByID returns a KeyFrame from its ChunkID
func (*Replay) LoadData ¶
func (r *Replay) LoadData(loader ReplayDataLoader) error
LoadData is loading in memory all binary data of Replay (KeyFrame, Chunk and EndOfGameStats) through a ReplayDataLoader
func (*Replay) MergeFromLastChunkInfo ¶
func (r *Replay) MergeFromLastChunkInfo(ci LastChunkInfo)
MergeFromLastChunkInfo merges Replay internal data with the one that could be fetch with a LastChunkInfo structure, obtained through the SpectateAPI
func (*Replay) MergeFromMetaData ¶
func (r *Replay) MergeFromMetaData(gm GameMetadata)
MergeFromMetaData merge the internal Replay data from GameMetadata that can be fetch through the SpectateAPI
func (*Replay) Save ¶
func (r *Replay) Save(writer ReplayDataWriter) error
Save is writing all Replay data (without binary data like KeyFrame, Chunk and EndOfGameStats) through a ReplayDataWriter
func (*Replay) SaveData ¶
func (r *Replay) SaveData(writer ReplayDataWriter) error
SaveData is saving all binary data of a Replay through a ReplayDataWriter
func (*Replay) SaveWithData ¶
func (r *Replay) SaveWithData(writer ReplayDataWriter) error
SaveWithData is writing all of Replay data through a ReplayDataWriter
type ReplayDataFormatter ¶
type ReplayDataFormatter interface { ReplayDataLoader ReplayDataWriter }
A ReplayDataFormatter is both a ReplayDataWriter and ReplayDataLoader
type ReplayDataLoader ¶
type ReplayDataLoader interface { HasChunk(ChunkID) bool HasKeyFrame(KeyFrameID) bool HasEndOfGameStats() bool Open() (io.ReadCloser, error) OpenChunk(ChunkID) (io.ReadCloser, error) OpenKeyFrame(KeyFrameID) (io.ReadCloser, error) OpenEndOfGameStats() (io.ReadCloser, error) }
A ReplayDataLoader can load all data of a Replay
type ReplayDataWriter ¶
type ReplayDataWriter interface { Create() (io.WriteCloser, error) CreateChunk(ChunkID) (io.WriteCloser, error) CreateKeyFrame(KeyFrameID) (io.WriteCloser, error) CreateEndOfGameStats() (io.WriteCloser, error) }
A ReplayDataWriter can be used to write data of a replay
type ReplayManager ¶
type ReplayManager interface { Store(*Replay) error Get(*lol.Region, lol.GameID) (ReplayDataLoader, error) Create(*lol.Region, lol.GameID) (ReplayDataWriter, error) Replays() map[string]*Replay Delete(*lol.Region, lol.GameID) error }
A ReplayManager stores and retrieve replays
type ReplayPrinter ¶
type ReplayPrinter struct {
// contains filtered or unexported fields
}
ReplayPrinter can be used to display Replay info on command line / text output
func NewReplayPrinter ¶
func NewReplayPrinter(region *lol.Region, key lol.APIKey) (*ReplayPrinter, error)
NewReplayPrinter creates a new replay printer for a region
func (*ReplayPrinter) Display ¶
func (p *ReplayPrinter) Display(r *Replay)
Display nicely display on stdout the replay information
type ReplayServer ¶
type ReplayServer struct { TimeDivisor DurationMs // contains filtered or unexported fields }
A ReplayServer can serve over http a replay.
func NewReplayServer ¶
func NewReplayServer(loader ReplayDataLoader) (*ReplayServer, error)
NewReplayServer initializes a ReplayServer from data located somewhere
func (*ReplayServer) Close ¶
func (h *ReplayServer) Close() error
Close stops a running ReplayServer
func (*ReplayServer) EncryptionKey ¶
func (h *ReplayServer) EncryptionKey() string
EncryptionKey returns the encryption key used to encrypt the game data.
func (*ReplayServer) ListenAndServe ¶
func (h *ReplayServer) ListenAndServe(addr string) error
ListenAndServe starts an http Server on the given address to show the replay
type SpectateAPI ¶
type SpectateAPI struct {
// contains filtered or unexported fields
}
SpectateAPI is an helper to use the REST api for spectate mode
func NewSpectateAPI ¶
func NewSpectateAPI(region *lol.Region, id lol.GameID) (*SpectateAPI, error)
NewSpectateAPI creates a new API endpoint dedicated to get data for the specified game (from lol.Region and lol.GameID)
func (*SpectateAPI) Format ¶
func (a *SpectateAPI) Format(function SpectateFunction, param int) string
Format formats an URL appropriately for the API
func (*SpectateAPI) Get ¶
func (a *SpectateAPI) Get(function SpectateFunction, param int, v interface{}) error
Get parses JSON data into the v param. Only GetGameMetaData, GetLastChunkInfo and EndOfGameStats should use it
func (*SpectateAPI) ReadAll ¶
func (a *SpectateAPI) ReadAll(function SpectateFunction, param int, w io.Writer) error
ReadAll reads the entire response from the REST Api and copy it to w io.Writer
func (*SpectateAPI) SpectateGame ¶
func (a *SpectateAPI) SpectateGame(encryptionKey string, w ReplayDataWriter) (*Replay, error)
SpectateGame is spectating a Game from the SpectateAPI endpoint. It is fetching all data needed to spectate the Replay again and checks for its integrity.
func (*SpectateAPI) Version ¶
func (a *SpectateAPI) Version() (string, error)
Version is getting from the Server the version currently used.
func (*SpectateAPI) VersionURL ¶
func (a *SpectateAPI) VersionURL() string
VersionURL is returning the URL for getting the SpectateAPI version used on the distant server.
type SpectateFunction ¶
type SpectateFunction string
SpectateFunction is a function of the SpectateAPI
type XdgReplayManager ¶
type XdgReplayManager struct {
// contains filtered or unexported fields
}
A XdgReplayManager is a ReplayManager that stores its data within the XDG_CACHE_HOME directory
func NewXdgReplayManager ¶
func NewXdgReplayManager() (*XdgReplayManager, error)
NewXdgReplayManager creates a ReplayManager that stores its data in XDG_CACHE_HOME
func (*XdgReplayManager) CleanUp ¶
func (m *XdgReplayManager) CleanUp() error
CleanUp is locating for all invalid files / replay in the XdgReplayManager and removes them.
func (*XdgReplayManager) Create ¶
func (m *XdgReplayManager) Create(region *lol.Region, id lol.GameID) (ReplayDataWriter, error)
Create returns a ReplayDataWriter for a replay identifieud by its lol.Region and lol.GameID. It will fails if a replay already exists for that Game.
func (*XdgReplayManager) Delete ¶
func (m *XdgReplayManager) Delete(region *lol.Region, id lol.GameID) error
Delete ensure that the replay is deleted from the manager. It only returns an error if it cannot delete it. If the replay does not exist it will silently ignores the error.
func (*XdgReplayManager) Get ¶
func (m *XdgReplayManager) Get(region *lol.Region, id lol.GameID) (ReplayDataLoader, error)
Get returns a ReplayDataLoader for a given lol.Region and lol.GameID that is fully stored in the Manager. It will return an error if the replay data is missing or incomplete for LoL client to spectate.
func (*XdgReplayManager) Replays ¶
func (m *XdgReplayManager) Replays() map[string][]*Replay
Replays return all Replay stored in the XdgReplayManager
func (*XdgReplayManager) Store ¶
func (m *XdgReplayManager) Store(r *Replay) error
Store saves in the cache directory all the Replay data.