   ; 2. Emit game start
   nil)
 
-;;------------------------------------------------------------
+;;------------------------------------------------------------------------------
+;; Socket Events
+;;------------------------------------------------------------------------------
+
+(defn- on-chat-message [msg pid socket]
+  (let [d (assoc (get @players pid) :type "msg" :msg msg)]
+    (js/console.log "Player" pid "said:" msg)
+    (.. socket -broadcast (to "lobby") (emit "new-message" (pr-str d)))))
+
+;;------------------------------------------------------------------------------
 ;; Socket Setup
-;;------------------------------------------------------------
+;;------------------------------------------------------------------------------
 
 (defn init-socket
   "Initialize the web socket."


    ; start server
    (.listen server port)
    (println "listening on port" port "\n")

    ; configure sockets
    (.sockets.on io "connection" #(init-socket io %))))

            (.leave socket "lobby")))

    ; Chat in the lobby.
    (.on socket "chat-message" #(on-chat-message % pid socket))

    ; Join/leave the game.
    (.on socket "join-game" #(.join socket "game"))
