diff --git a/cmd/main.go b/cmd/main.go index 17e6b94d..b34ee26e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -34,8 +34,6 @@ func createOverlordConnection() (*websocket.Conn, error) { func initilizeOverlord() { overlord := overlord.NewServer() - log.Println("http://localhost:8000") - http.HandleFunc("/", overlord.GetWeb) http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static")))) @@ -47,8 +45,6 @@ func initilizeOverlord() { // worker facing port http.HandleFunc("/wso", overlord.WSO) http.ListenAndServe(":8000", nil) - - log.Println("http://localhost:" + *config.Port) } // initializeWorker setup a worker @@ -65,7 +61,9 @@ func initializeWorker() { log.Println("Close worker") worker.Close() }() - worker.Run() + + go worker.Run() + http.ListenAndServe(":8001", nil) } func monitor() { diff --git a/emulator/director.go b/emulator/director.go index 9c911e54..70ed0535 100644 --- a/emulator/director.go +++ b/emulator/director.go @@ -28,7 +28,7 @@ const fps = 60 func NewDirector(roomID string, imageChannel chan<- *image.RGBA, audioChannel chan<- float32, inputChannel <-chan int) *Director { // TODO: return image channel from where it write director := Director{} - director.Done = make(chan struct{}) + director.Done = make(chan struct{}, 1) director.audioChannel = audioChannel director.imageChannel = imageChannel director.inputChannel = inputChannel diff --git a/webrtc/webrtc.go b/webrtc/webrtc.go index bb555781..d6dabc93 100644 --- a/webrtc/webrtc.go +++ b/webrtc/webrtc.go @@ -59,9 +59,9 @@ func NewWebRTC() *WebRTC { w := &WebRTC{ ID: uuid.Must(uuid.NewV4()).String(), - ImageChannel: make(chan []byte, 2), + ImageChannel: make(chan []byte, 100), AudioChannel: make(chan []byte, 1000), - InputChannel: make(chan int, 2), + InputChannel: make(chan int, 10), } return w } @@ -273,6 +273,7 @@ func (w *WebRTC) startStreaming(vp8Track *webrtc.Track, audioTrack *webrtc.DataC } }() + // TODO: Use same yuv for w.isConnected { yuv, ok := <-w.ImageChannel if !ok { diff --git a/worker/handlers.go b/worker/handlers.go index 7725b81d..423a437f 100644 --- a/worker/handlers.go +++ b/worker/handlers.go @@ -109,7 +109,9 @@ func (h *Handler) isRoomRunning(roomID string) bool { } func (h *Handler) Close() { - h.oClient.Close() + if h.oClient != nil { + h.oClient.Close() + } // Close all room for _, room := range h.rooms { room.Close() diff --git a/worker/room/room.go b/worker/room/room.go index 8e855a17..0aa40a32 100644 --- a/worker/room/room.go +++ b/worker/room/room.go @@ -65,7 +65,7 @@ func NewRoom(roomID, gamepath, gameName string, onlineStorage *storage.Client) * IsRunning: true, onlineStorage: onlineStorage, - Done: make(chan struct{}), + Done: make(chan struct{}, 1), } go room.startVideo()