         (swap! app-state assoc :music-files
           (merge (:music-files @app-state)
                  {track-id
-                  (new js/Blob #js [(get (:music-files @app-state) track-id) data-chunk])}))))
+                  (new js/Blob #js [(get (:music-files @app-state) track-id) data-chunk]
+                               #js {:type "audio/mpeg"})}))))
     (.on stream "end"
       (fn []
         (println "Download complete!")
-        (swap! app-state assoc :download-progress nil)))))
+        (swap! app-state assoc :download-progress nil)
+
+        (if (= (:current-track-id @app-state) track-id)
+          (play-track track-id))))))
+
+(.on socket "track-change"
+  (fn [track-id]
+    (swap! app-state assoc :current-track-id track-id)
+    (.emit socket "file-download-request" track-id)))

        (fn []
          (println "Upload successful!"))))))
; end stuff that should be cleaned up with react....

(.on socket "connect" #(.emit socket "join-room" room-id))
(.on socket "sign-in-success"


(defonce room-id (.getAttribute (. js/document (getElementById "roomid")) "data"))
(defonce socket (js/io))
(defonce current-sound-id "current-song")
(defonce app-state (atom {:signed-in? false
                          :messages []
                          :message-received? false
