ref: f142458c4b3c35a4034358cb1293fad3e3a17568
dir: /livereload/livereload.go/
sed: Output line too long // Copyright © 2014 Steve Francia <[email protected]>. // // Licensed under the Simple Public License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://opensource.org/licenses/Simple-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package livereload import ( "net/http" "github.com/gorilla/websocket" ) var upgrader = &websocket.Upgrader{ReadBufferSize: 1024, WriteBufferSize: 1024} func Handler(w http.ResponseWriter, r *http.Request) { ws, err := upgrader.Upgrade(w, r, nil) if err != nil { return } c := &connection{send: make(chan []byte, 256), ws: ws} wsHub.register <- c defer func() { wsHub.unregister <- c }() go c.writer() c.reader() } func Initialize() { go wsHub.run() } func ForceRefresh() { // Tell livereload a js file changed to force a hard refresh wsHub.broadcast <- []byte(`{"command":"reload","path":"/x.js","originalPath":"","liveCSS":true}`) } func ServeJS(w http.ResponseWriter, r *http.Request) { w.Write(livereloadJS) }