mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 08:40:18 +01:00
Fixed websocket sending once again.
This commit is contained in:
parent
c87ce03dbe
commit
0968c5c07c
@ -26,10 +26,10 @@ type connection struct {
|
||||
|
||||
type (
|
||||
tilesMsg struct {
|
||||
Tiles []xz `json:"tiles,omitempty"`
|
||||
Tiles []xz `json:"tiles"`
|
||||
}
|
||||
plsMsg struct {
|
||||
Pls []*player `json:"players,omitempty"`
|
||||
Pls []*player `json:"players"`
|
||||
}
|
||||
)
|
||||
|
||||
@ -83,8 +83,6 @@ func (wsf *websocketForwarder) send(m interface{}) {
|
||||
|
||||
data := buf.Bytes()
|
||||
|
||||
log.Printf("sending: %s\n", string(data))
|
||||
|
||||
for c := range wsf.connections {
|
||||
select {
|
||||
case c.send <- data:
|
||||
|
@ -133,9 +133,7 @@ func samePlayers(a, b []*player) bool {
|
||||
|
||||
func (ps *players) run() {
|
||||
for {
|
||||
ps.mu.Lock()
|
||||
empty := len(ps.pls) == 0
|
||||
ps.mu.Unlock()
|
||||
empty := len(ps.current()) == 0
|
||||
|
||||
pls, err := ps.readFromFIFO()
|
||||
if err != nil {
|
||||
@ -169,12 +167,15 @@ func (ps *players) run() {
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *players) current() []*player {
|
||||
ps.mu.RLock()
|
||||
defer ps.mu.RUnlock()
|
||||
return ps.pls
|
||||
}
|
||||
|
||||
func (ps *players) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.Header().Set("Content-Type", "application/json")
|
||||
var pls []*player
|
||||
ps.mu.RLock()
|
||||
pls = ps.pls
|
||||
ps.mu.RUnlock()
|
||||
pls := ps.current()
|
||||
encoder := json.NewEncoder(rw)
|
||||
if err := encoder.Encode(pls); err != nil {
|
||||
log.Printf("error: sending JSON failed: %s\n", err)
|
||||
|
Loading…
Reference in New Issue
Block a user