mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-28 12:36:30 +00:00
* WIP * Add libretro * Update input retro * Update cloud retro input: * Integrate libretro remove GL * Launch emulator by game type * Save and load * Update deeplink to game directly * Done channel for naemulator * each server handle only one session * Only provide available clients * Emulator based on game * Remove all OpenGL related * Retroarch audio * Audio encoding mono * Experiment with libretro audio * Audio without datachannel * Audio opus internal * Remove unnecessary code * Resampled * Limit time frame * Start Room and Audio by game * Dynamic video image allocation * Dynamic Video buffer allocation based on video resolution * Move encoder to room * width and height from emulator * Padding images to fix multipler of 64 * Remove OpenGL * Remove Open AL * Remove OpenGL from Go mod * Move away nanoarch logic in naemulator * Remove unecessary savefiles.go * Optimize Docker for caching * Update ReadME * Update README to introduce Retro * Update README * Update README.md
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package overlord
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/giongto35/cloud-game/cws"
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
type WorkerClient struct {
|
|
*cws.Client
|
|
ServerID string
|
|
Address string
|
|
IsAvailable bool
|
|
}
|
|
|
|
// RouteWorker are all routes server received from worker
|
|
func (o *Server) RouteWorker(workerClient *WorkerClient) {
|
|
// registerRoom event from a server, when server created a new room.
|
|
// RoomID is global so it is managed by overlord.
|
|
workerClient.Receive("registerRoom", func(resp cws.WSPacket) cws.WSPacket {
|
|
log.Println("Overlord: Received registerRoom ", resp.Data, workerClient.ServerID)
|
|
o.roomToServer[resp.Data] = workerClient.ServerID
|
|
return cws.WSPacket{
|
|
ID: "registerRoom",
|
|
}
|
|
})
|
|
|
|
// getRoom returns the server ID based on requested roomID.
|
|
workerClient.Receive("getRoom", func(resp cws.WSPacket) cws.WSPacket {
|
|
log.Println("Overlord: Received a getroom request")
|
|
log.Println("Result: ", o.roomToServer[resp.Data])
|
|
return cws.WSPacket{
|
|
ID: "getRoom",
|
|
Data: o.roomToServer[resp.Data],
|
|
}
|
|
})
|
|
|
|
workerClient.Receive("heartbeat", func(resp cws.WSPacket) cws.WSPacket {
|
|
return resp
|
|
})
|
|
}
|
|
|
|
// NewWorkerClient returns a client connecting to worker. This connection exchanges information between workers and server
|
|
func NewWorkerClient(c *websocket.Conn, serverID string, address string) *WorkerClient {
|
|
return &WorkerClient{
|
|
Client: cws.NewClient(c),
|
|
ServerID: serverID,
|
|
Address: address,
|
|
IsAvailable: true,
|
|
}
|
|
}
|