<commit_before># -*- mode:ruby; coding:utf-8 -*-
require "rubygems"
require "bundler/setup"
require 'em-websocket'
require 'sinatra'
require 'thin'
require 'uri'
require 'open-uri'
require 'yaml'
require 'logger'

$log = Logger.new(STDOUT)

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

config_path = File.expand_path('../config/websocket.yml',
                               File.dirname(__FILE__))
puts "load from: #{config_path}"
WsConfig = YAML.load_file config_path
$log.info WsConfig.inspect

def rails_root
  "http#{WsConfig['use_rails_ssl'] ? 's' : ''}://#{WsConfig['roots']}"
end

EventMachine.run do
  $clients = Hash.new {|hash, key|
    hash[key] = []
  }

  EventMachine::WebSocket.start(:host => 'localhost',
                                :port => WsConfig['websocketPort']) do |ws|
    ws.onopen do
      $log.info "on open: #{ws.request['Query'].inspect}"
      room =  ws.request['Query']['room']
      $clients[room] << ws
    end

    ws.onclose do
      $log.info "on close: #{ws.request['Query'].inspect}"
      room =  ws.request['Query']['room']
      $clients[room].delete ws
    end
  end

  class App < Sinatra::Base
    get '/message/:event/:id' do
      event = params[:event]
      id    = params[:id]
      room  = params[:room]<commit_msg>Fixed: websocket server died refs #459<commit_after># -*- mode:ruby; coding:utf-8 -*-
require "rubygems"
require "bundler/setup"
require 'em-websocket'
require 'sinatra'
require 'thin'
require 'uri'
require 'open-uri'
require 'yaml'
require 'logger'

$log = Logger.new(STDOUT)

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

config_path = File.expand_path('../config/websocket.yml',
                               File.dirname(__FILE__))
puts "load from: #{config_path}"
WsConfig = YAML.load_file config_path
$log.info WsConfig.inspect

def rails_root
  "http#{WsConfig['use_rails_ssl'] ? 's' : ''}://#{WsConfig['roots']}"
end

EventMachine.run do
  $clients = Hash.new {|hash, key|
    hash[key] = []
  }

  EventMachine::WebSocket.start(:host => '0.0.0.0',
                                :port => WsConfig['websocketPort']) do |ws|
    ws.onopen do
      $log.info "on open: #{ws.request['Query'].inspect}"
      room =  ws.request['Query']['room']
      $clients[room] << ws
    end

    ws.onclose do
      $log.info "on close: #{ws.request['Query'].inspect}"
      room =  ws.request['Query']['room']
      $clients[room].delete ws
    end
  end

  class App < Sinatra::Base
    get '/message/:event/:id' do
      event = params[:event]
      id    = params[:id]
      room  = params[:room]
{'fraction_non_alphanumeric': 0.16827852998065765, 'fraction_numerical': 0.003481624758220503, 'mean_word_length': 3.0343213728549143, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '7445148', 'n_tokens_mistral': 933, 'n_tokens_neox': 890, 'n_words': 186}