Change done chan to 1

This commit is contained in:
giongto35 2019-05-20 15:16:56 +08:00
parent b8b950fa2a
commit 0c4e851c0c
5 changed files with 11 additions and 10 deletions

View file

@ -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() {

View file

@ -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

View file

@ -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 {

View file

@ -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()

View file

@ -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()