   (fn [{:keys [chan-id :user/id] :as socket-user}
       {:keys [game-id]}]
     (let [player ((:get-player-from-game datomic) game-id id)
+          game ((:get-game-by-id datomic) game-id)
           game-state ((:get-game-state-by-id datomic) game-id)
           arena (get-in game-state [:frame :frame/arena])]
 

             [game-id :players chan-id]
             (assoc socket-user :color (:player/color player)))

      ;; Sends the initial frame to the frontend
      (broadcast-arena game-id arena))))

(defn- leave-game
  [_]


;; Broadcast functions

(defn- broadcast-to-viewers
  [game-id message]
  (let [channel-ids (get-game-room-channel-ids game-id)]
    (doseq [channel-id channel-ids]
      (send-message channel-id
                    message))))

(defn broadcast-arena
  [game-id arena]
  (broadcast-to-viewers game-id
                        {:meta {:msg-type :frame-update}
                         :payload arena}))

(defn- broadcast-game-info
  "Pulls out relevant info from game-state and sends it in join-game"
  [game-id game]
  (broadcast-to-viewers game-id
                        {:meta {:msg-type :game-info}
                         :payload {:start-time (:game/start-time game)
                                   :max-players (:game/max-players game)
                                   :name (:game/name game)
                                   :status (:game/status game)}}))

(defn broadcast-stats
  [game-id stats]
  (broadcast-to-viewers game-id                        
                        {:meta {:msg-type :stats-update}
                         :payload (vec stats)}))

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Handlers
