mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 08:45:38 +02:00
⭐ feat(maitred): Update maitred - hookup to the API (#198)
## Description We are attempting to hookup maitred to the API Maitred duties will be: - [ ] Hookup to the API - [ ] Wait for signal (from the API) to start Steam - [ ] Stop signal to stop the gaming session, clean up Steam... and maybe do the backup ## Summary by CodeRabbit - **New Features** - Introduced Docker-based deployment configurations for both the main and relay applications. - Added new API endpoints enabling real-time machine messaging and enhanced IoT operations. - Expanded database schema and actor types to support improved machine tracking. - **Improvements** - Enhanced real-time communication and relay management with streamlined room handling. - Upgraded dependencies, logging, and error handling for greater stability and performance. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: DatCaptainHorse <DatCaptainHorse@users.noreply.github.com> Co-authored-by: Kristian Ollikainen <14197772+DatCaptainHorse@users.noreply.github.com>
This commit is contained in:
52
packages/maitred/internal/realtime/messages.go
Normal file
52
packages/maitred/internal/realtime/messages.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package realtime
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// BaseMessage is the generic top-level message structure
|
||||
type BaseMessage struct {
|
||||
Type string `json:"type"`
|
||||
Payload json.RawMessage `json:"payload"`
|
||||
}
|
||||
|
||||
type CreatePayload struct{}
|
||||
|
||||
type StartPayload struct {
|
||||
ContainerID string `json:"container_id"`
|
||||
}
|
||||
|
||||
type StopPayload struct {
|
||||
ContainerID string `json:"container_id"`
|
||||
}
|
||||
|
||||
// ParseMessage parses a BaseMessage and returns the specific payload
|
||||
func ParseMessage(data []byte) (BaseMessage, interface{}, error) {
|
||||
var base BaseMessage
|
||||
if err := json.Unmarshal(data, &base); err != nil {
|
||||
return base, nil, err
|
||||
}
|
||||
|
||||
switch base.Type {
|
||||
case "create":
|
||||
var payload CreatePayload
|
||||
if err := json.Unmarshal(base.Payload, &payload); err != nil {
|
||||
return base, nil, err
|
||||
}
|
||||
return base, payload, nil
|
||||
case "start":
|
||||
var payload StartPayload
|
||||
if err := json.Unmarshal(base.Payload, &payload); err != nil {
|
||||
return base, nil, err
|
||||
}
|
||||
return base, payload, nil
|
||||
case "stop":
|
||||
var payload StopPayload
|
||||
if err := json.Unmarshal(base.Payload, &payload); err != nil {
|
||||
return base, nil, err
|
||||
}
|
||||
return base, payload, nil
|
||||
default:
|
||||
return base, base.Payload, nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user