mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-18 00:55:40 +00:00
Users, workers, and the coordinator will now send WebRTC signaling
information through a single API endpoint with a unified structure. The
payload should contain either an sdp or ice field for further processing
by the designated handlers.
Replaced API endpoints:
- (101) WebrtcOffer -> WebrtcSignal
Removed API endpoints:
- WebrtcAnswer (102)
- WebrtcIce (103)
64 lines
2.2 KiB
Go
64 lines
2.2 KiB
Go
package coordinator
|
|
|
|
import "github.com/giongto35/cloud-game/v3/pkg/api"
|
|
|
|
func (w *Worker) InitWebrtcStream(id string, initiator bool, sdp string) (*api.InitWebrtcStreamResponse, error) {
|
|
return api.UnwrapChecked[api.InitWebrtcStreamResponse](
|
|
w.Send(api.InitWebrtcStream, api.InitWebrtcStreamRequest{Id: id, Initiator: initiator, Sdp: sdp}))
|
|
}
|
|
|
|
func (w *Worker) WebrtcSignal(id string, sdp, ice *string) {
|
|
w.Notify(api.WebrtcSignal, api.WebrtcSignalRequest{
|
|
Stateful: api.Stateful{Id: id}, Ice: ice, Sdp: sdp,
|
|
})
|
|
}
|
|
|
|
func (w *Worker) StartGame(id string, req api.GameStartUserRequest) (*api.StartGameResponse, error) {
|
|
return api.UnwrapChecked[api.StartGameResponse](
|
|
w.Send(api.StartGame, api.StartGameRequest{
|
|
StatefulRoom: api.StatefulRoom{Id: id, Rid: req.RoomId},
|
|
Game: req.GameName,
|
|
PlayerIndex: req.PlayerIndex,
|
|
Record: req.Record,
|
|
RecordUser: req.RecordUser,
|
|
}))
|
|
}
|
|
|
|
func (w *Worker) QuitGame(id string) {
|
|
w.Notify(api.QuitGame, api.GameQuitRequest{Id: id, Rid: w.RoomId})
|
|
}
|
|
|
|
func (w *Worker) SaveGame(id string) (*api.SaveGameResponse, error) {
|
|
return api.UnwrapChecked[api.SaveGameResponse](
|
|
w.Send(api.SaveGame, api.SaveGameRequest{Id: id, Rid: w.RoomId}))
|
|
}
|
|
|
|
func (w *Worker) LoadGame(id string) (*api.LoadGameResponse, error) {
|
|
return api.UnwrapChecked[api.LoadGameResponse](
|
|
w.Send(api.LoadGame, api.LoadGameRequest{Id: id, Rid: w.RoomId}))
|
|
}
|
|
|
|
func (w *Worker) ChangePlayer(id string, index int) (*api.ChangePlayerResponse, error) {
|
|
return api.UnwrapChecked[api.ChangePlayerResponse](
|
|
w.Send(api.ChangePlayer, api.ChangePlayerRequest{
|
|
StatefulRoom: api.StatefulRoom{Id: id, Rid: w.RoomId},
|
|
Index: index,
|
|
}))
|
|
}
|
|
|
|
func (w *Worker) ResetGame(id string) {
|
|
w.Notify(api.ResetGame, api.ResetGameRequest{Id: id, Rid: w.RoomId})
|
|
}
|
|
|
|
func (w *Worker) RecordGame(id string, rec bool, recUser string) (*api.RecordGameResponse, error) {
|
|
return api.UnwrapChecked[api.RecordGameResponse](
|
|
w.Send(api.RecordGame, api.RecordGameRequest{
|
|
StatefulRoom: api.StatefulRoom{Id: id, Rid: w.RoomId},
|
|
Active: rec,
|
|
User: recUser,
|
|
}))
|
|
}
|
|
|
|
func (w *Worker) TerminateSession(id string) {
|
|
_, _ = w.Send(api.TerminateSession, api.TerminateSessionRequest{Id: id})
|
|
}
|