new new
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
function on_update_operation(id, index) {
|
||||
if(sock) {
|
||||
console.log("sending")
|
||||
sock.send(JSON.stringify({"op": "update", "id": id, "index": index}));
|
||||
sock.send(JSON.stringify({"op": "move", "id": id, "index": index}));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
+15
-4
@@ -2,16 +2,17 @@ package www
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"html/template"
|
||||
"net/http"
|
||||
// "golang.org/x/net/websocket"
|
||||
"net/http"
|
||||
"github.com/gorilla/websocket"
|
||||
"../playlist"
|
||||
)
|
||||
|
||||
// todo: hub - https://stackoverflow.com/questions/31532652/go-websocket-send-all-clients-a-message
|
||||
|
||||
var pp *playlist.PrettyPlaylist
|
||||
var pp *playlist.PrettyPlaylist
|
||||
var p *playlist.Playlist
|
||||
|
||||
var pln = log.Println
|
||||
|
||||
@@ -26,7 +27,8 @@ var upgrader = websocket.Upgrader{
|
||||
WriteBufferSize: 512,
|
||||
}
|
||||
|
||||
func Init(p *playlist.Playlist) {
|
||||
func Init(playlist *playlist.Playlist) {
|
||||
p = playlist
|
||||
pp = p.Pretty()
|
||||
http.HandleFunc("/pp", pp_handler)
|
||||
http.HandleFunc("/ppop", pp_operations)
|
||||
@@ -59,6 +61,15 @@ func readop(c *websocket.Conn) {
|
||||
pln(err)
|
||||
return //connection lost?
|
||||
}
|
||||
|
||||
if opdata.OP == "move" {
|
||||
if id, err := strconv.ParseUint(opdata.ID, 10, 32); err == nil {
|
||||
p.Move(uint32(id), opdata.INDEX)
|
||||
pp = p.Pretty()
|
||||
pp.Print()
|
||||
}
|
||||
}
|
||||
|
||||
pln(opdata.OP)
|
||||
pln(opdata.ID)
|
||||
pln(opdata.INDEX)
|
||||
|
||||
Reference in New Issue
Block a user