package main import ( "log" "net/http" "sync" "dev.hexasoftware.com/stdio/wsrpc" _ "dev.hexasoftware.com/stdio/prettylog" "dev.hexasoftware.com/stdio/wsrpc/sample/canvas/canvas" ) var objlock sync.Mutex type Point struct { x, y int } func ClientHandler(ctx *wsrpc.ClientCtx) { log.Println("Client connected", ctx.WS.RemoteAddr()) c := canvas.New(ctx) points := []Point{} c.OnMouseMove = func(x, y int) { objlock.Lock() defer objlock.Unlock() c.Clear() points = append(points, Point{x, y}) lenPoints := len(points) // Test this if lenPoints > 2 { for i := 1; i < lenPoints; i++ { c.Line(points[i-1].x, points[i-1].y, points[i].x, points[i].y) } } if lenPoints > 15 { // try 100 drawCalls points = points[1:] // remove first } } } func main() { var mux = http.NewServeMux() wsrpc.RegisterTo(mux, ClientHandler) mux.Handle("/", http.FileServer(http.Dir("web"))) log.Println("Listening :8080") http.ListenAndServe(":8080", mux) }