<commit_before>#require "./redis2ws/*"
require "kemal"
require "redis"

module Redis2ws
  SOCKETS = [] of HTTP::WebSocket
  
  #run redis subscriber in its own fiber
  spawn do
    redis = Redis.new
    redis.subscribe("mychannel") do |on|
      on.message do |channel, message|
        puts message
        SOCKETS.each { |socket| socket.send message }
      end
    end
  end
  
  # The Kemal app, pretty straightforward.
  
  # For root and /app.js we just hardcode some paths. You should probably use a nicer way for this.
  get "/" do |ctx|
    send_file ctx, "src/web/index.html"
  end
  
  get "/app.js" do |ctx|
    send_file ctx, "src/web/app.js"
  end
  
  ws "/eventstream/" do |socket|
    # Add the client to SOCKETS list
    SOCKETS << socket

    # Broadcast each message to all clients
    socket.on_message do |message|
      # we don't really care about what clients send to us, but leaving this in as an<commit_msg>Change endpoints in the app to use the /public directory<commit_after>#require "./redis2ws/*"
require "kemal"
require "redis"

module Redis2ws
  SOCKETS = [] of HTTP::WebSocket # which type are the objects in this empty list :O
  
  #run redis subscriber in its own fiber
  spawn do
    redis = Redis.new
    redis.subscribe("mychannel") do |on|
      on.message do |channel, message|
        puts message
        SOCKETS.each { |socket| socket.send message }
      end
    end
  end
  
  # The Kemal app, pretty straightforward.
  
  # While static files get served from the /public directory, this doesn't work for calls to `/`, so
  # we have to hardcode that one.
  get "/" do |ctx|
    send_file ctx, "public/index.html"
  end
  
  ws "/eventstream/" do |socket|
    # Add the client to SOCKETS list
    SOCKETS << socket

    # Broadcast each message to all clients
    socket.on_message do |message|
      # we don't really care about what clients send to us, but leaving this in as an
{'fraction_non_alphanumeric': 0.08670820353063344, 'fraction_numerical': 0.0020768431983385254, 'mean_word_length': 2.705769230769231, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6294742', 'n_tokens_mistral': 618, 'n_tokens_neox': 604, 'n_words': 240}