<commit_before>(ns tango.web-socket
  (:require [taoensso.sente :as sente]
            [clojure.core.async :as async]
            [com.stuartsierra.component :as component]
            [taoensso.timbre :as log]))

;; Provides useful Timbre aliases in this ns
(log/refer-timbre)

(defn event-msg-handler* [messages-receive-chan {:as ev-msg :keys [id ?data event ring-req]}]
  (async/>!! messages-receive-chan {:topic id :payload ?data :sender (:uid (:session ring-req))}))

(defrecord WSRingHandlers [ajax-post-fn ajax-get-or-ws-handshake-fn])

(defrecord WSConnection [ch-recv connected-uids send-fn ring-handlers channels]
  component/Lifecycle
  (start [component]
    (if (and ch-recv connected-uids send-fn ring-handlers)
      component
      (let [{:keys [ch-recv send-fn connected-uids
                    ajax-post-fn ajax-get-or-ws-handshake-fn]}
            (sente/make-channel-socket!)]
        (log/info "Start web socket")
        (assoc component<commit_msg>Added ring request to trace log<commit_after>(ns tango.web-socket
  (:require [taoensso.sente :as sente]
            [clojure.core.async :as async]
            [com.stuartsierra.component :as component]
            [taoensso.timbre :as log]))

;; Provides useful Timbre aliases in this ns
(log/refer-timbre)

(defn event-msg-handler* [messages-receive-chan {:as ev-msg :keys [id ?data event ring-req]}]
  (do
    (log/trace "Ring request: " ring-req)
    (async/>!! messages-receive-chan {:topic id :payload ?data :sender (:uid (:session ring-req))})))

(defrecord WSRingHandlers [ajax-post-fn ajax-get-or-ws-handshake-fn])

(defrecord WSConnection [ch-recv connected-uids send-fn ring-handlers channels]
  component/Lifecycle
  (start [component]
    (if (and ch-recv connected-uids send-fn ring-handlers)
      component
      (let [{:keys [ch-recv send-fn connected-uids
                    ajax-post-fn ajax-get-or-ws-handshake-fn]}
            (sente/make-channel-socket!)]
        (log/info "Start web socket")
        (assoc component
{'fraction_non_alphanumeric': 0.13561847988077497, 'fraction_numerical': 0.0, 'mean_word_length': 3.0119521912350598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3592834', 'n_tokens_mistral': 687, 'n_tokens_neox': 663, 'n_words': 165}