Class: Vizcore::Server::RackApp

Inherits:
Object
  • Object
show all
Defined in:
lib/vizcore/server/rack_app.rb

Overview

Rack app serving frontend assets, health endpoint, and WebSocket upgrade.

Constant Summary collapse

AUDIO_FILE_PATH =
"/audio-file"
CONTROL_PATH =
"/control"
CONTROL_PRESET_PATH =
"/control-preset"
PLUGIN_ASSET_PREFIX =
"/plugins/"
PROJECTOR_PATH =
"/projector"
RUNTIME_PATH =
"/runtime"

Instance Method Summary collapse

Constructor Details

#initialize(frontend_root:, websocket_path: "/ws", audio_source: nil, audio_file: nil, scene_names: nil, tap_tempo_key: nil, key_mappings: nil, globals: nil, control_preset: nil, control_preset_path: nil, plugin_assets: nil, projector_mode: false) ⇒ RackApp

Returns a new instance of RackApp.

Parameters:

  • frontend_root (Pathname)
  • websocket_path (String) (defaults to: "/ws")
  • audio_source (Symbol, String, nil) (defaults to: nil)
  • audio_file (String, Pathname, nil) (defaults to: nil)
  • scene_names (Array<String, Symbol>, nil) (defaults to: nil)
  • tap_tempo_key (String, Symbol, nil) (defaults to: nil)
  • key_mappings (Array<Hash>, nil) (defaults to: nil)
  • globals (Hash, nil) (defaults to: nil)
  • control_preset (Hash, nil) (defaults to: nil)
  • control_preset_path (String, Pathname, nil) (defaults to: nil)
  • plugin_assets (Array<String, Pathname>, nil) (defaults to: nil)
  • projector_mode (Boolean) (defaults to: false)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vizcore/server/rack_app.rb', line 32

def initialize(
  frontend_root:,
  websocket_path: "/ws",
  audio_source: nil,
  audio_file: nil,
  scene_names: nil,
  tap_tempo_key: nil,
  key_mappings: nil,
  globals: nil,
  control_preset: nil,
  control_preset_path: nil,
  plugin_assets: nil,
  projector_mode: false
)
  @frontend_root = frontend_root.expand_path
  @websocket_path = websocket_path
  @audio_source = audio_source&.to_sym
  @audio_file = audio_file ? Pathname.new(audio_file).expand_path : nil
  @scene_names = normalize_scene_names(scene_names)
  @tap_tempo_key = normalize_tap_tempo_key(tap_tempo_key)
  @key_mappings = normalize_key_mappings(key_mappings)
  @globals = normalize_globals(globals)
  @control_preset = normalize_control_preset(control_preset)
  @control_preset_path = control_preset_path ? Pathname.new(control_preset_path).expand_path : nil
  @plugin_assets = normalize_plugin_assets(plugin_assets)
  @projector_mode = !!projector_mode
end

Instance Method Details

#call(env) ⇒ Array(Integer, Hash, Array<String>)

Parameters:

  • env (Hash)

Returns:

  • (Array(Integer, Hash, Array<String>))


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vizcore/server/rack_app.rb', line 62

def call(env)
  request = Rack::Request.new(env)

  return WebSocketHandler.call(env) if request.path_info == @websocket_path
  return health_response if request.path_info == "/health"
  return runtime_response if request.path_info == RUNTIME_PATH
  return control_preset_response(request) if request.path_info == CONTROL_PRESET_PATH
  return audio_file_response(request) if request.path_info == AUDIO_FILE_PATH
  return plugin_asset_response(request.path_info) if request.path_info.start_with?(PLUGIN_ASSET_PREFIX)
  return serve_index(display_mode: root_display_mode) if request.path_info == "/"
  return serve_index(display_mode: "control") if request.path_info == CONTROL_PATH
  return serve_index(display_mode: "projector") if request.path_info == PROJECTOR_PATH

  serve_static(request.path_info)
end