       url  = "ws://#{host}:#{port}/socket.io/websocket"
       @ws = new WebSocket(url)
       @ws.onmessage = @onMessage.bind(@)
+      @ws.onerror = @onError.bind(@)
       @ws.onclose = @onClose.bind(@)
 
+  onError: (data) ->
+    @emit 'wserror', data
 
   whichServer: (roomid, callback) ->
     options =


  onMessage: (msg) ->
    data = msg.data
    return @treatHeartbeat(data) if @isHeartbeat(data)
    @log "> #{data}"
    return @treatNoSession(data) if @isNoSession(data)

          callback.call(@, host, port)
        else
          @log "Failed to determine which server to use: #{dataStr}"
    .on 'error', (e) =>
      @log "whichServer error: #{e}"


  setTmpSong: (data) ->
