File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
new/client/templates/wrappers Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,24 @@ func ReconnectGame(username string) (*Game, error) {
7575 }, nil
7676}
7777
78+ // Spectate joins a game as a spectator.
79+ func Spectate(gameId string) (*Game, error) {
80+ socket, err := cg.NewSocket("{{.URL}}")
81+ if err != nil {
82+ return nil, fmt.Errorf("failed to connect to server: %s", err)
83+ }
84+
85+ err = socket.Spectate(gameId)
86+ if err != nil {
87+ return nil, fmt.Errorf("failed to spectate game: %s", err)
88+ }
89+
90+ return &Game{
91+ Id: socket.Session().GameId,
92+ socket: socket,
93+ }, nil
94+ }
95+
7896// Run starts the event loop (blocking).
7997func (g *Game) Run() error {
8098 return g.socket.RunEventLoop()
@@ -89,6 +107,16 @@ func (g *Game) Update() error {
89107 return err
90108}
91109
110+ // ResolveUsername returns the username associated with playerId.
111+ func (g *Game) ResolveUsername(playerId string) string {
112+ return g.socket.ResolveUsername(playerId)
113+ }
114+
115+ // Session returns details of the current session.
116+ func (g *Game) Session() cg.Session {
117+ return g.socket.Session()
118+ }
119+
92120// Disconnect closes the underlying socket connection.
93121func (g *Game) Disconnect() error {
94122 return g.socket.Close()
Original file line number Diff line number Diff line change 11{
22 "server" : {
3- "0.7" : " 0.1 "
3+ "0.7" : " 0.2 "
44 },
55 "client" : {
6- "0.8" : " 0.1 "
6+ "0.8" : " 0.2 "
77 }
88}
You can’t perform that action at this time.
0 commit comments