<commit_before>(ns hellhound.components.websocket
  "Websocket component is responsible for setting up a sente server
  for client to connect to. In order to use this component all you
  have to do is, either use `websocket-server` function with
  `hellhound.system.defsystem` macro or use the `make-websocket` with a
  traditional system map."
  (:require [hellhound.connection                   :refer [event-router]]
            [hellhound.system                        :refer [get-system]]
            [com.stuartsierra.component              :as component]
            [taoensso.sente.packers.transit          :as packer]
            [taoensso.sente                          :as sente]
            [taoensso.sente.server-adapters.immutant :refer [get-sch-adapter]]))

(defrecord WebSocketServer [web-server-adapter handler options adapter]
  component/Lifecycle
  (start [component]
    (let [{:keys [ch-recv send-fn ajax-post-fn ajax-get-or-ws-handshake-fn connected-uids]}
          (sente/make-channel-socket-server! adapter  options) ;;web-server-adapter
          component (assoc component
                           :ring-ajax-post                ajax-post-fn
                           :ring-ajax-get-or-ws-handshake ajax-get-or-ws-handshake-fn
                           :ch-chsk                       ch-recv
                           :chsk-send!                    send-fn
                           :adapter                       adapter
                           :connected-uids                connected-uids)]

      (assoc component
             :router (sente/start-chsk-router!
                      ch-recv (if (:wrap-component? options)
                                (handler component)
                                handler)))))
  (stop [component]
    (let [router (:router component)]
      (if-not (nil? router)
        (do
          (router)
          (assoc component :router nil))
        component))))



(defn new-channel-socket-server
  ([web-server-adapter]
   (new-channel-socket-server nil web-server-adapter {}))
  ([event-msg-handler web-server-adapter]<commit_msg>Websocket component migrated to Units<commit_after>(ns hellhound.components.websocket
  "Websocket component is responsible for setting up a sente server
  for client to connect to. In order to use this component all you
  have to do is, either use `websocket-server` function with
  `hellhound.system.defsystem` macro or use the `make-websocket` with a
  traditional system map."
  (:require
   [hellhound.connection                    :refer [event-router]]
   [hellhound.system                        :refer [get-system]]
   [hellhound.units.core                    :as unit]
   [taoensso.sente.packers.transit          :as packer]
   [taoensso.sente                          :as sente]
   [taoensso.sente.server-adapters.immutant :refer [get-sch-adapter]]))

(defrecord WebSocketServer [web-server-adapter handler options adapter]
  unit/Structure
  (start [component]
    (let [{:keys [ch-recv send-fn ajax-post-fn ajax-get-or-ws-handshake-fn connected-uids]}
          (sente/make-channel-socket-server! adapter  options) ;;web-server-adapter
          component (assoc component
                           :ring-ajax-post                ajax-post-fn
                           :ring-ajax-get-or-ws-handshake ajax-get-or-ws-handshake-fn
                           :ch-chsk                       ch-recv
                           :chsk-send!                    send-fn
                           :adapter                       adapter
                           :connected-uids                connected-uids)]

      (assoc component
             :router (sente/start-chsk-router!
                      ch-recv (if (:wrap-component? options)
                                (handler component)
                                handler)))))
  (stop [component]
    (let [router (:router component)]
      (if-not (nil? router)
        (do
          (router)
          (assoc component :router nil))
        component))))



(defn new-channel-socket-server
  ([web-server-adapter]
   (new-channel-socket-server nil web-server-adapter {}))
  ([event-msg-handler web-server-adapter]
{'fraction_non_alphanumeric': 0.09730503219651801, 'fraction_numerical': 0.0, 'mean_word_length': 1.5856966707768188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3821498', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1117, 'n_words': 271}