Sha256: 489d55b39d743e63cb05a792db26c031723ea5b8fd8e55ea5bc1360a03e2ba45

Contents?: true

Size: 1.4 KB

Versions: 27

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

# atome server

require 'em/pure_ruby' if RUBY_PLATFORM == 'x64-mingw32'
require 'fileutils'
require '../src/utilities/aui'
require 'digest/sha2'
require 'faye/websocket'
require 'geocoder'
require 'json'
require 'mail'
require 'net/ping'
require 'roda'
require 'rufus-scheduler'
require 'securerandom'
require 'sequel'

require './eDen'
require './database'
require './extensions'

Faye::WebSocket.load_adapter('puma')

class App < Roda
  index_content = File.read("../src/index_server_wasm.html")
  opts[:root] = '../src'
  plugin :static, %w[/css /js /medias /wasm], root: '../src'
  route do |r|
    r.root do
      if Faye::WebSocket.websocket?(r.env)
        ws = Faye::WebSocket.new(r.env)
        ws.on :open do |_event|
          ws.send({ return: 'server ready' }.to_json)
        end
        ws.on(:message) do |event|
          json_string = event.data.gsub(/(\w+):/) { "\"#{$1}\":" }.gsub('=>', ':')
          full_data = JSON.parse(json_string)
          data = full_data['data']
          action_requested = full_data['action']
          message_id = full_data['message_id']
          return_message = EDen.safe_send(action_requested, data, message_id)
          ws.send(return_message.to_json)
        end
        ws.on(:close) do |event|
          puts "server closed with status #{event.code}"
        end
        ws.rack_response
      end
      index_content
    end
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
atome-0.5.6.8.7 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.8.6 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.8.5 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.8.3 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.7.8 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.7.7 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.7.6 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.7.5 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.7.4 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.7.3 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.6.9 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.6.7 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.6.5 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.6.1 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.6.0 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.5.7 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.5.6 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.5.4 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.5.1 vendor/assets/server/atome_server_wasm.rb
atome-0.5.6.4.8 vendor/assets/server/atome_server_wasm.rb