8 "golang.org/x/net/websocket"
14 eventSource eventSource
19 func (rtr *router) setup() {
20 rtr.mux = http.NewServeMux()
21 rtr.mux.Handle("/websocket", rtr.makeServer(&handlerV0{
22 QueueSize: rtr.Config.ClientEventQueue,
24 rtr.mux.Handle("/arvados/v1/events.ws", rtr.makeServer(&handlerV1{
25 QueueSize: rtr.Config.ClientEventQueue,
29 func (rtr *router) makeServer(handler handler) *websocket.Server {
30 return &websocket.Server{
31 Handshake: func(c *websocket.Config, r *http.Request) error {
34 Handler: websocket.Handler(func(ws *websocket.Conn) {
35 log.Printf("socket request: %+v", ws.Request())
36 sink := rtr.eventSource.NewSink(nil)
37 handler.Handle(ws, sink.Channel())
40 log.Printf("socket disconnect: %+v", ws.Request().RemoteAddr)
45 func (rtr *router) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
46 rtr.setupOnce.Do(rtr.setup)
47 rtr.mux.ServeHTTP(resp, req)