             @connectionError()
             #editor.auth.think()
 
-        @ws.onmessage = (e) ->
+        @ws.onmessage = (e) =>
             packet = JSON.parse(e.data)
             msg = packet.msg
             kargs = packet.kargs

class Connection

    constructor: ->
        host = window.document.location.host.replace(/:.*/, '')
        @ws = new WebSocket 'ws://' + location.hostname + ":" + 1977

        afterInterval 1000, =>
            @ws.safeSend("ping", {})
            if @lastPong < Date.now() - 30 * 1000
                print "no pongs"
                @ws.close()

        @ws.safeSend = (msg, kargs) =>
            print "sending", msg, kargs, @ws.readyState, WebSocket.OPEN

            switch msg
                when 'pong'
                    @lastPong = Date.now()
                    print "got pong"
                when 'open-push'
                    editor.open_cmd.open_push(kargs)
                when 'loggedin'
