From 83cf9dbaadc57cdab5e46dca2292b0a56cf2c2f1 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Mon, 2 Mar 2015 14:16:36 +0100 Subject: [PATCH] Added command line flags for websocket support. Added dummy websocket controller. --- cmd/mtwebmapper/forwardupdates.go | 26 ++++++++++++++++++++++++++ cmd/mtwebmapper/main.go | 11 ++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 cmd/mtwebmapper/forwardupdates.go diff --git a/cmd/mtwebmapper/forwardupdates.go b/cmd/mtwebmapper/forwardupdates.go new file mode 100644 index 0000000..4477214 --- /dev/null +++ b/cmd/mtwebmapper/forwardupdates.go @@ -0,0 +1,26 @@ +// Copyright 2014 by Sascha L. Teichmann +// Use of this source code is governed by the MIT license +// that can be found in the LICENSE file. + +package main + +import "net/http" + +type websocketForwarder struct { +} + +func newWebsocketForwarder() *websocketForwarder { + return &websocketForwarder{} +} + +func (wsf *websocketForwarder) run() { + // TODO: Implement me! +} + +func (wsf *websocketForwarder) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + // TODO: Implement me! +} + +func (wsf *websocketForwarder) BaseTilesUpdated(changes map[xz]bool) { + // TODO: Implement me! +} diff --git a/cmd/mtwebmapper/main.go b/cmd/mtwebmapper/main.go index 364f908..eef25af 100644 --- a/cmd/mtwebmapper/main.go +++ b/cmd/mtwebmapper/main.go @@ -28,6 +28,7 @@ func main() { workers int transparent bool updateHosts string + websockets bool ) flag.IntVar(&webPort, "web-port", 8808, "port of the web server") flag.IntVar(&webPort, "p", 8808, "port of the web server (shorthand)") @@ -50,6 +51,8 @@ func main() { flag.StringVar(&colorsFile, "c", "colors.txt", "colors used to render map tiles (shorthand).") flag.BoolVar(&transparent, "transparent", false, "Render transparent blocks.") flag.BoolVar(&transparent, "t", false, "Render transparent blocks (shorthand).") + flag.BoolVar(&websockets, "websockets", false, "Forward tile changes to clients via websockets.") + flag.BoolVar(&websockets, "ws", false, "Forward tile changes to clients via websockets (shorthand).") flag.Parse() @@ -58,9 +61,15 @@ func main() { subBaseLine := newSubBaseLine(mapDir) router.Path("/map/{z:[0-9]+}/{x:[0-9]+}/{y:[0-9]+}.png").Handler(subBaseLine) - // TODO: Implement me! var btu baseTilesUpdates + if websockets { + wsf := newWebsocketForwarder() + go wsf.run() + router.Path("/ws").Methods("GET").Handler(wsf) + btu = wsf + } + if redisHost != "" { var colors *common.Colors var err error