kopia lustrzana https://github.com/cyoung/stratux
Add SendJSON() to uibroadcaster.
rodzic
27206c0751
commit
504d97ec7a
|
@ -11,6 +11,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -36,6 +37,11 @@ func (u *uibroadcaster) Send(msg []byte) {
|
||||||
u.messages <- msg
|
u.messages <- msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *uibroadcaster) SendJSON(i interface{}) {
|
||||||
|
j, _ := json.Marshal(&i)
|
||||||
|
u.Send(j)
|
||||||
|
}
|
||||||
|
|
||||||
func (u *uibroadcaster) AddSocket(sock *websocket.Conn) {
|
func (u *uibroadcaster) AddSocket(sock *websocket.Conn) {
|
||||||
u.sockets_mu.Lock()
|
u.sockets_mu.Lock()
|
||||||
u.sockets = append(u.sockets, sock)
|
u.sockets = append(u.sockets, sock)
|
||||||
|
|
Ładowanie…
Reference in New Issue