biz

package
v0.0.0-...-771d5d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgPlayerControlButtonPressed byte = iota
	MsgPlayerControlButtonReleased
	MsgChat
	MsgNewConn
	MsgCloseConn
	MsgSetController1
	MsgSetController2
	MsgResetController
	MsgPeerConnected
	MsgPauseEmulator
	MsgResumeEmulator
	MsgSaveGame
	MsgLoadSave
	MsgRestartEmulator
	MsgPing
	MsgSetGraphicOptions
	MsgSetEmulatorSpeed
)
View Source
const (
	InstanceStatusRunning int32 = iota
	InstanceStatusStopped
)
View Source
const (
	DefaultAudioSampleRate = 48000
)
View Source
const EnhanceFrameScale = 2
View Source
const (
	MessageTargetEmulator int64 = iota
)

Variables

ProviderSet is biz providers.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func (*Connection) Close

func (c *Connection) Close()

func (*Connection) OnDataChannelMessage

func (c *Connection) OnDataChannelMessage(instance *GameInstance, msg webrtc.DataChannelMessage)

func (*Connection) OnICEStateChange

func (c *Connection) OnICEStateChange(_ webrtc.ICEConnectionState)

func (*Connection) OnPeerConnectionState

func (c *Connection) OnPeerConnectionState(state webrtc.PeerConnectionState, instance *GameInstance)

type ConsumerResult

type ConsumerResult struct {
	Success bool
	Error   error
	Message string
	Data    any
}

type EndpointStats

type EndpointStats struct {
	EmulatorCount int32 `json:"emulatorCount"`
	CpuUsage      int32 `json:"cpuUsage"`
	MemoryUsed    int64 `json:"memoryUsed"`
	MemoryTotal   int64 `json:"memoryTotal"`
	Uptime        int64 `json:"uptime"`
}

type GameFileMetadata

type GameFileMetadata struct {
	Name       string `json:"name"`
	Mapper     string `json:"mapper"`
	Mirroring  string `json:"mirroring"`
	Size       int32  `json:"size"`
	UploadTime int64  `json:"uploadTime"`
}

type GameFileRepo

type GameFileRepo interface {
	GetGameData(ctx context.Context, game string) ([]byte, error)
	UploadGameData(ctx context.Context, game string, data []byte, metadata *GameFileMetadata) error
	ListGames(ctx context.Context, page, pageSize int) ([]*GameFileMetadata, int, error)
	DeleteGames(ctx context.Context, games []string) (int, error)
	GetSavedGame(ctx context.Context, id int64) (*GameSave, error)
	SaveGame(ctx context.Context, save *GameSave) error
	ListSaves(ctx context.Context, roomId int64, page, pageSize int32) ([]*GameSave, int32, error)
	DeleteSave(ctx context.Context, saveId int64) error
	GetExitSave(ctx context.Context, roomId int64) (*GameSave, error)
}

type GameFileUseCase

type GameFileUseCase struct {
	// contains filtered or unexported fields
}

func NewGameFileUseCase

func NewGameFileUseCase(repo GameFileRepo, logger log.Logger) *GameFileUseCase

func (*GameFileUseCase) DeleteGames

func (uc *GameFileUseCase) DeleteGames(ctx context.Context, games []string) (int, error)

func (*GameFileUseCase) DeleteSave

func (uc *GameFileUseCase) DeleteSave(ctx context.Context, saveId int64) error

func (*GameFileUseCase) ListGames

func (uc *GameFileUseCase) ListGames(ctx context.Context, page, pageSize int) ([]*GameFileMetadata, int, error)

func (*GameFileUseCase) ListSaves

func (uc *GameFileUseCase) ListSaves(ctx context.Context, roomId int64, page, pageSize int32) ([]*GameSave, int32, error)

func (*GameFileUseCase) UploadGameFile

func (uc *GameFileUseCase) UploadGameFile(ctx context.Context, game string, data []byte) error

type GameInstance

type GameInstance struct {
	RoomId       int64
	EmulatorType string // 模拟器类型名称,比如nes

	LeaseID int64

	InstanceId string // 实例ID
	// contains filtered or unexported fields
}

func (*GameInstance) DeleteConnection

func (g *GameInstance) DeleteConnection(userId int64)

func (*GameInstance) DumpStats

func (g *GameInstance) DumpStats() *GameInstanceStats

func (*GameInstance) LoadSave

func (g *GameInstance) LoadSave(data []byte, game string, gameFileRepo GameFileRepo) error

func (*GameInstance) NewConnection

func (g *GameInstance) NewConnection(userId int64, stunServer string) (*Connection, string, error)

func (*GameInstance) RenderCallback

func (g *GameInstance) RenderCallback(frame emulator.IFrame, logger *log.Helper)

func (*GameInstance) RestartEmulator

func (g *GameInstance) RestartEmulator(game string, gameData []byte) error

func (*GameInstance) SaveGame

func (g *GameInstance) SaveGame() (*GameSave, error)

func (*GameInstance) SetEmulatorSpeed

func (g *GameInstance) SetEmulatorSpeed(boostRate float64) float64

func (*GameInstance) SetGraphicOptions

func (g *GameInstance) SetGraphicOptions(options *GraphicOptions)

type GameInstanceRepo

type GameInstanceRepo interface {
	CreateGameInstance(ctx context.Context, game *GameInstance) (int64, error)
	DeleteGameInstance(ctx context.Context, roomId int64) error
	GetGameInstance(ctx context.Context, roomId int64) (*GameInstance, error)
	ListGameInstances(ctx context.Context) ([]*GameInstance, error)
}

type GameInstanceStats

type GameInstanceStats struct {
	RoomId            int64         `json:"roomId"`
	Connections       int           `json:"connections"`
	ActiveConnections int           `json:"activeConnections"`
	Game              string        `json:"game"`
	Uptime            time.Duration `json:"uptime"`
}

type GameInstanceUseCase

type GameInstanceUseCase struct {
	// contains filtered or unexported fields
}

func NewGameInstanceUseCase

func NewGameInstanceUseCase(repo GameInstanceRepo, gameFileRepo GameFileRepo, roomRepo RoomRepo, c *conf.IceServer, logger log.Logger) *GameInstanceUseCase

func (*GameInstanceUseCase) CreateGameInstance

func (uc *GameInstanceUseCase) CreateGameInstance(ctx context.Context, roomId int64, game string, emulatorType string) (*GameInstance, error)

CreateGameInstance 创建模拟器实例,第一个连接房间并创建会话的操作会创建模拟器实例 调用者必须持有房间会话的分布式锁,保证只创建一次

func (*GameInstanceUseCase) DeleteMemberConnection

func (uc *GameInstanceUseCase) DeleteMemberConnection(ctx context.Context, roomId, userId int64) error

func (*GameInstanceUseCase) GetController

func (uc *GameInstanceUseCase) GetController(ctx context.Context, roomId int64) (int64, int64, error)

func (*GameInstanceUseCase) GetEmulatorSpeed

func (uc *GameInstanceUseCase) GetEmulatorSpeed(ctx context.Context, roomId int64) (float64, error)

func (*GameInstanceUseCase) GetEndpointStats

func (uc *GameInstanceUseCase) GetEndpointStats(ctx context.Context) (*EndpointStats, error)

func (*GameInstanceUseCase) GetGameInstanceStats

func (uc *GameInstanceUseCase) GetGameInstanceStats(ctx context.Context, roomId int64) (*GameInstanceStats, error)

func (*GameInstanceUseCase) GetGraphicOptions

func (uc *GameInstanceUseCase) GetGraphicOptions(ctx context.Context, roomId int64) (*GraphicOptions, error)

func (*GameInstanceUseCase) GetICECandidates

func (uc *GameInstanceUseCase) GetICECandidates(ctx context.Context, roomId, userId int64) ([]string, error)

func (*GameInstanceUseCase) ICECandidate

func (uc *GameInstanceUseCase) ICECandidate(ctx context.Context, roomId, userId int64, candidate string) error

func (*GameInstanceUseCase) ListGameInstances

func (uc *GameInstanceUseCase) ListGameInstances(ctx context.Context) ([]*GameInstanceStats, error)

func (*GameInstanceUseCase) ListSupportedEmulators

func (uc *GameInstanceUseCase) ListSupportedEmulators(ctx context.Context) ([]*SupportedEmulator, error)

func (*GameInstanceUseCase) LoadSave

func (uc *GameInstanceUseCase) LoadSave(ctx context.Context, saveId int64) error

func (*GameInstanceUseCase) OnGameInstanceConnectionsAllClosed

func (uc *GameInstanceUseCase) OnGameInstanceConnectionsAllClosed(instance *GameInstance)

func (*GameInstanceUseCase) OpenGameConnection

func (uc *GameInstanceUseCase) OpenGameConnection(ctx context.Context, roomId, userId int64) (string, error)

func (*GameInstanceUseCase) ReleaseGameInstance

func (uc *GameInstanceUseCase) ReleaseGameInstance(ctx context.Context, roomId int64, force bool) error

ReleaseGameInstance 释放模拟器实例,所有连接断开后延迟释放 调用者必须持有房间会话的分布式锁,保证没有新连接建立

func (*GameInstanceUseCase) RestartEmulator

func (uc *GameInstanceUseCase) RestartEmulator(ctx context.Context, roomId int64, game string) error

func (*GameInstanceUseCase) SDPAnswer

func (uc *GameInstanceUseCase) SDPAnswer(ctx context.Context, roomId, userId int64, sdpAnswer string) error

func (*GameInstanceUseCase) SaveGame

func (uc *GameInstanceUseCase) SaveGame(ctx context.Context, roomId int64) error

func (*GameInstanceUseCase) SetController

func (uc *GameInstanceUseCase) SetController(ctx context.Context, roomId, playerId int64, controllerId int) error

func (*GameInstanceUseCase) SetEmulatorSpeed

func (uc *GameInstanceUseCase) SetEmulatorSpeed(ctx context.Context, roomId int64, rate float64) (float64, error)

func (*GameInstanceUseCase) SetGraphicOptions

func (uc *GameInstanceUseCase) SetGraphicOptions(ctx context.Context, roomId int64, options *GraphicOptions) error

type GameSave

type GameSave struct {
	Id         int64  `json:"id"`
	RoomId     int64  `json:"roomId"`
	Game       string `json:"game"`
	Data       []byte `json:"data"`
	CreateTime int64  `json:"createTime"`
	ExitSave   bool   `json:"exitSave"`
}

type GraphicOptions

type GraphicOptions struct {
	HighResOpen  bool `json:"highResOpen"`
	ReverseColor bool `json:"reverseColor"`
	Grayscale    bool `json:"grayscale"`
}

type Message

type Message struct {
	Type      byte  `json:"type"`
	From      int64 `json:"from"`
	To        int64 `json:"to"`
	Timestamp int64 `json:"timestamp"`
	Data      any   `json:"data"`
	// contains filtered or unexported fields
}

type RoomRepo

type RoomRepo interface {
	AddDeleteRoomSessionTask(ctx context.Context, roomId int64, instanceId string) error
}

type SupportedEmulator

type SupportedEmulator struct {
	Name                  string `json:"name"`
	SupportSaving         bool   `json:"saving"`
	SupportGraphicSetting bool   `json:"supportGraphicSetting"`
	Provider              string `json:"provider"`
	Games                 int32  `json:"games"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL