Sha256: 8a6895fead82582656ea78d75d60b939dbd0fb69d7179c27cfb139f678e7a728

Contents?: true

Size: 1.39 KB

Versions: 14

Compression:

Stored size: 1.39 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.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)
          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

14 entries across 14 versions & 1 rubygems

Version Path
atome-0.5.7.3.6 vendor/assets/server/atome_server.rb
atome-0.5.7.3.5 vendor/assets/server/atome_server.rb
atome-0.5.7.3.3 vendor/assets/server/atome_server.rb
atome-0.5.7.3.2 vendor/assets/server/atome_server.rb
atome-0.5.7.3.1 vendor/assets/server/atome_server.rb
atome-0.5.7.3.0 vendor/assets/server/atome_server.rb
atome-0.5.7.1.8 vendor/assets/server/atome_server.rb
atome-0.5.7.1.7 vendor/assets/server/atome_server.rb
atome-0.5.7.1.0 vendor/assets/server/atome_server.rb
atome-0.5.7.0.7 vendor/assets/server/atome_server.rb
atome-0.5.7.0.5 vendor/assets/server/atome_server.rb
atome-0.5.7.0.4 vendor/assets/server/atome_server.rb
atome-0.5.7.0.3 vendor/assets/server/atome_server.rb
atome-0.5.7.0.2 vendor/assets/server/atome_server.rb