mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-20 01:56:00 +00:00
Update test
This commit is contained in:
parent
e7567c3fa3
commit
d7116f11cd
4 changed files with 23 additions and 12 deletions
|
|
@ -17,6 +17,7 @@ import (
|
|||
const (
|
||||
gameboyIndex = "./static/gameboy.html"
|
||||
debugIndex = "./static/index_ws.html"
|
||||
gamePath = "games"
|
||||
)
|
||||
|
||||
// Time allowed to write a message to the peer.
|
||||
|
|
@ -53,7 +54,7 @@ func initializeServer() {
|
|||
log.Println("Run as a single server")
|
||||
}
|
||||
|
||||
handler := handler.NewHandler(conn, *config.IsDebug)
|
||||
handler := handler.NewHandler(conn, *config.IsDebug, gamePath)
|
||||
|
||||
// ignore origin
|
||||
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ import (
|
|||
)
|
||||
|
||||
var host = "http://localhost:8000"
|
||||
|
||||
// Test is in cmd, so gamePath is in parent path
|
||||
var testGamePath = "../games"
|
||||
var webrtcconfig = webrtc.Configuration{ICEServers: []webrtc.ICEServer{{URLs: []string{"stun:stun.l.google.com:19302"}}}}
|
||||
|
||||
func initOverlord() *httptest.Server {
|
||||
|
|
@ -26,7 +29,8 @@ func initOverlord() *httptest.Server {
|
|||
}
|
||||
|
||||
func initServer(t *testing.T, oconn *websocket.Conn) *httptest.Server {
|
||||
handler := handler.NewHandler(oconn, true)
|
||||
fmt.Println("Spawn new server")
|
||||
handler := handler.NewHandler(oconn, true, testGamePath)
|
||||
server := httptest.NewServer(http.HandlerFunc(handler.WS))
|
||||
return server
|
||||
}
|
||||
|
|
@ -52,6 +56,7 @@ func initClient(t *testing.T, host string) {
|
|||
u := "ws" + strings.TrimPrefix(host, "http")
|
||||
|
||||
// Connect to the server
|
||||
fmt.Println("Connecting to server")
|
||||
ws, _, err := websocket.DefaultDialer.Dial(u, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
|
|
@ -60,6 +65,7 @@ func initClient(t *testing.T, host string) {
|
|||
|
||||
// Simulate peerconnection initialization from client
|
||||
|
||||
fmt.Println("Simulating PeerConnection")
|
||||
peerConnection, err := webrtc.NewPeerConnection(webrtcconfig)
|
||||
if err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@ package gamelist
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const gamePath = "games"
|
||||
|
||||
// getGameList returns list of games stored in games
|
||||
func GetGameList() []string {
|
||||
// TODO: change to class
|
||||
func GetGameList(gamePath string) []string {
|
||||
var games []string
|
||||
filepath.Walk(gamePath, func(path string, info os.FileInfo, err error) error {
|
||||
if !info.IsDir() {
|
||||
// remove prefix
|
||||
if info != nil && !info.IsDir() {
|
||||
// Remove prefix to obtain file names
|
||||
path = path[len(gamePath)+1:]
|
||||
// Add to games list
|
||||
games = append(games, path)
|
||||
|
|
@ -25,7 +25,8 @@ func GetGameList() []string {
|
|||
}
|
||||
|
||||
// GetEncodedGameList returns game list in encoded wspacket format
|
||||
func GetEncodedGameList() string {
|
||||
encodedList, _ := json.Marshal(GetGameList())
|
||||
func GetEncodedGameList(gamePath string) string {
|
||||
encodedList, _ := json.Marshal(GetGameList(gamePath))
|
||||
fmt.Println(encodedList)
|
||||
return string(encodedList)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ type Handler struct {
|
|||
// isDebug determines the mode handler is running
|
||||
isDebug bool
|
||||
isOverlord bool
|
||||
gamePath string
|
||||
|
||||
// ID to peerconnection
|
||||
peerconnections map[string]*webrtc.WebRTC
|
||||
|
|
@ -48,16 +49,18 @@ type Handler struct {
|
|||
}
|
||||
|
||||
// NewHandler returns a new server
|
||||
func NewHandler(overlordConn *websocket.Conn, isDebug bool) *Handler {
|
||||
func NewHandler(overlordConn *websocket.Conn, isDebug bool, gamePath string) *Handler {
|
||||
//conn, err := createOverlordConnection()
|
||||
//if err != nil {
|
||||
//return nil, err
|
||||
//}
|
||||
return &Handler{
|
||||
isDebug: isDebug,
|
||||
oClient: NewOverlordClient(overlordConn),
|
||||
rooms: map[string]*Room{},
|
||||
peerconnections: map[string]*webrtc.WebRTC{},
|
||||
|
||||
isDebug: isDebug,
|
||||
gamePath: gamePath,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +109,7 @@ func (h *Handler) WS(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
wssession.BrowserClient.Send(cws.WSPacket{
|
||||
ID: "gamelist",
|
||||
Data: gamelist.GetEncodedGameList(),
|
||||
Data: gamelist.GetEncodedGameList(h.gamePath),
|
||||
}, nil)
|
||||
|
||||
wssession.BrowserClient.Listen()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue