racehub

package
v0.0.0-...-9bee2a0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskTypeManageRaceStatus = "manage_race_start"
	TaskTypeManageNextMark   = "manage_next_mark"
)
View Source
const (
	HandlerTypeAuth             = "auth"
	HandlerTypePostGeolocation  = "post_geolocation"
	HandlerTypePassedMark       = "passed_mark"
	HandlerTypeManageRaceStatus = "manage_race_status"
	HandlerTypeManageNextMark   = "manage_next_mark"
)
View Source
const (
	ActionTypeConnectResult    = "connect_result"
	ActionTypeAuthResult       = "auth_result"
	ActionTypeMarkGeolocations = "mark_geolocations"
	ActionTypeParticipantsInfo = "participants_info"
	ActionTypeManageRaceStatus = "manage_race_status"
	ActionTypeManageNextMark   = "manage_next_mark"

	AuthResultOK                    = "OK"
	AuthResultFailedAuthToken       = "failed_auth_token"
	AuthResultOutsideAssociation    = "outside_association"
	AuthResultInvalidDeviceID       = "invalid_device_id"
	AuthResultInvalidWantMarkCounts = "invalid_want_mark_counts"
)

Variables

View Source
var Upgrader = websocket.Upgrader{

	ReadBufferSize: 4096,

	WriteBufferSize: 4096,

	EnableCompression: true,

	CheckOrigin: func(r *http.Request) bool {
		return true
	},
}

WebSocketアップグレーダー: HTTP接続をWebSocket接続にアップグレードする設定

Functions

This section is empty.

Types

type Action

type Action interface {
	ConnectResult(
		c *Client,
		ok bool,
		hubID string,
	) (*ConnectResultOutput, error)

	AuthResult(
		c *Client,
		ok bool,
		message string,
	) (*AuthResultOutput, error)

	MarkGeolocations(
		c *Client,
	) (*MarkGeolocationsOutput, error)

	ParticipantsInfo(
		c *Client,
	) (*ParticipantsInfoOutput, error)

	ManageRaceStatus(
		c *Client,
		started bool,
		startedAt time.Time,
		finishedAt time.Time,
	) (*ManageRaceStatusOutput, error)

	ManageNextMark(
		c *Client,
		nextMarkNo int,
	) (*ManageNextMarkOutput, error)
}

type AuthInput

type AuthInput struct {
	MessageType    string `json:"type"`
	Token          string `json:"token"`
	DeviceID       string `json:"device_id"`
	WantMarkCounts int    `json:"want_mark_counts"`
}

type AuthResultOutput

type AuthResultOutput struct {
	MessageType string `json:"type"`
	OK          bool   `json:"ok"`
	DeviceID    string `json:"device_id"`
	Role        string `json:"role"`
	MarkNo      int    `json:"mark_no"`
	Authed      bool   `json:"authed"`
	Message     string `json:"message"`
}

type Client

type Client struct {
	ID                  string
	Hub                 *Hub
	Conn                *websocket.Conn
	SendCh              chan any
	StoppingWritePumpCh chan bool

	DeviceID       string
	Role           string
	MarkNo         int
	WantMarkCounts int
	Authed         bool
}

func (*Client) LogValue

func (c *Client) LogValue() slog.Value

func (*Client) SetPingPongHandler

func (c *Client) SetPingPongHandler()

func (*Client) WriteAuthResult

func (c *Client) WriteAuthResult(
	ok bool,
	message string,
) error

func (*Client) WriteConnectResult

func (c *Client) WriteConnectResult(ok bool, hubID string) error

func (*Client) WriteManageNextMark

func (c *Client) WriteManageNextMark(nextMarkNo int) error

func (*Client) WriteManageRaceStatus

func (c *Client) WriteManageRaceStatus(started bool, startedAt time.Time, finishedAt time.Time) error

func (*Client) WriteMarkGeolocations

func (c *Client) WriteMarkGeolocations() error

func (*Client) WriteParticipantsInfo

func (c *Client) WriteParticipantsInfo() error

type ClientEvent

type ClientEvent interface {
	Register(*Client)
	Unregister(*Client)
}

type ConnectResultOutput

type ConnectResultOutput struct {
	MessageType string `json:"type"`
	OK          bool   `json:"ok"`
	HubID       string `json:"hub_id"`
}

type Handler

type Handler interface {
	Auth(*Client, *AuthInput)
	PostGeolocation(*Client, *PostGeolocationInput)
	PassedMark(*Client, *PassedMarkInput)
	ManageRaceStatus(*Client, *ManageRaceStatusInput)
	ManageNextMark(*Client, *ManageNextMarkInput)
}

type Hub

type Hub struct {
	ID            string
	AssociationID string
	Clients       map[string]*Client

	Mu sync.RWMutex
	// contains filtered or unexported fields
}

func NewHub

func NewHub(
	associationID string,
	tm *taskmanager.Manager,
	clientEvent ClientEvent,
	serverEvent ServerEvent,
	handler Handler,
	action Action,
) *Hub

func (*Hub) LogValue

func (h *Hub) LogValue() slog.Value

func (*Hub) PublishManageNextMarkTask

func (h *Hub) PublishManageNextMarkTask(ctx context.Context, targetTaskManagerID string, targetDeviceID string, nextMarkNo int) error

func (*Hub) PublishManageRaceStatusTask

func (h *Hub) PublishManageRaceStatusTask(ctx context.Context, started bool, startedAt time.Time, finishedAt time.Time) error

func (*Hub) Register

func (h *Hub) Register(conn *websocket.Conn) *Client

func (*Hub) Unregister

func (h *Hub) Unregister(c *Client)

type ManageNextMarkInput

type ManageNextMarkInput struct {
	MessageType    string `json:"type"`
	TargetDeviceID string `json:"target_device_id"`
	NextMarkNo     int    `json:"next_mark_no"`
}

type ManageNextMarkOutput

type ManageNextMarkOutput struct {
	MessageType string `json:"type"`
	NextMarkNo  int    `json:"next_mark_no"`
}

type ManageNextMarkTaskMessage

type ManageNextMarkTaskMessage struct {
	TargetDeviceID string `json:"target_device_id"`
	NextMarkNo     int    `json:"next_mark_no"`
}

type ManageRaceStatusInput

type ManageRaceStatusInput struct {
	MessageType string    `json:"type"`
	Started     bool      `json:"started"`
	StartedAt   time.Time `json:"started_at"`
	FinishedAt  time.Time `json:"finished_at"`
}

type ManageRaceStatusOutput

type ManageRaceStatusOutput struct {
	MessageType string    `json:"type"`
	Started     bool      `json:"started"`
	StartedAt   time.Time `json:"started_at"`
	FinishedAt  time.Time `json:"finished_at"`
}

type ManageRaceStatusTaskMessage

type ManageRaceStatusTaskMessage struct {
	Started    bool      `json:"started"`
	StartedAt  time.Time `json:"started_at"`
	FinishedAt time.Time `json:"finished_at"`
}

type MarkGeolocationsOutput

type MarkGeolocationsOutput struct {
	MessageType string                       `json:"type"`
	MarkCounts  int                          `json:"mark_counts"`
	Marks       []MarkGeolocationsOutputMark `json:"marks"`
}

type MarkGeolocationsOutputMark

type MarkGeolocationsOutputMark struct {
	MarkNo        int       `json:"mark_no"`
	Stored        bool      `json:"stored"`
	Latitude      float64   `json:"latitude"`
	Longitude     float64   `json:"longitude"`
	AccuracyMeter float64   `json:"accuracy_meter"`
	Heading       float64   `json:"heading"`
	RecordedAt    time.Time `json:"recorded_at"`
}

type ParticipantsInfoOutput

type ParticipantsInfoOutput struct {
	MessageType string                          `json:"type"`
	MarkCounts  int                             `json:"mark_counts"`
	Marks       []MarkGeolocationsOutputMark    `json:"marks"`
	Athletes    []ParticipantsInfoOutputAthlete `json:"athletes"`
}

type ParticipantsInfoOutputAthlete

type ParticipantsInfoOutputAthlete struct {
	DeviceID      string    `json:"device_id"`
	NextMarkNo    int       `json:"next_mark_no"`
	Latitude      float64   `json:"latitude"`
	Longitude     float64   `json:"longitude"`
	AccuracyMeter float64   `json:"accuracy_meter"`
	Heading       float64   `json:"heading"`
	RecordedAt    time.Time `json:"recorded_at"`
}

type PassedMarkInput

type PassedMarkInput struct {
	MessageType  string    `json:"type"`
	PassedMarkNo int       `json:"passed_mark_no"`
	PassedAt     time.Time `json:"passed_at"`
}

type PostGeolocationInput

type PostGeolocationInput struct {
	MessageType           string    `json:"type"`
	Latitude              float64   `json:"latitude"`
	Longitude             float64   `json:"longitude"`
	AltitudeMeter         float64   `json:"altitude_meter"`
	AccuracyMeter         float64   `json:"accuracy_meter"`
	AltitudeAccuracyMeter float64   `json:"altitude_accuracy_meter"`
	Heading               float64   `json:"heading"`
	SpeedMeterPerSec      float64   `json:"speed_meter_per_sec"`
	RecordedAt            time.Time `json:"recorded_at"`
}

type ServerEvent

type ServerEvent interface {
	ManageRaceStatusTaskReceived(*Hub, *ManageRaceStatusTaskMessage)
	ManageNextMarkTaskReceived(*Hub, *ManageNextMarkTaskMessage)
}

type UnimplementedAction

type UnimplementedAction struct{}

type UnimplementedClientEvent

type UnimplementedClientEvent struct{}

type UnimplementedHandler

type UnimplementedHandler struct{}

type UnimplementedServerEvent

type UnimplementedServerEvent struct{}

Jump to

Keyboard shortcuts

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