Sha256: 0d4b3ec9b8b6de1f07bd3f8594e860090765b853ef0e34fd7ca8f730bf170efa

Contents?: true

Size: 773 Bytes

Versions: 2

Compression:

Stored size: 773 Bytes

Contents

# frozen_string_literal: true
require "rack/request"

module Pytty
  module Daemon
    module Components
      class WebSocketHandler
        def initialize(env)
          @env = env
        end

        def handle
          req = Rack::Request.new(@env)
          ws = Pytty::Daemon::Api::WebSockets.new(@env)
          ws.handle

          klass = case req.path_info
          when "/stream"
            Stream
          else
            raise "Unknown: #{req.path_info}"
          end
          params = ws.read
          body = begin
            JSON.parse(params)
          rescue Exception => ex
            p ex
          end

          obj = klass.new cmd: body.dig("cmd"), env: body.dig("env")
          obj.run stream: ws
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pytty-0.3.0 lib/pytty/daemon/components/web_socket_handler.rb
pytty-0.2.0 lib/pytty/daemon/components/web_socket_handler.rb