Class: Airplay::Server

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/airplay/server.rb,
lib/airplay/server/app.rb

Defined Under Namespace

Classes: App

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/airplay/server.rb', line 15

def initialize
  @port = Airplay.configuration.port || find_free_port
  @logger = Airplay::Logger.new("airplay::server")
  @server = Rack::Server.new(
    server: :reel,
    Host: private_ip,
    Port: @port,
    Logger: @logger,
    AccessLog: [],
    quiet: true,
    app: App.app
  )

  start!
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



13
14
15
# File 'lib/airplay/server.rb', line 13

def port
  @port
end

Instance Method Details

#serve(file) ⇒ Object

Public: Adds a file to serve

file - The file path to be served

Returns the url that the file will have



37
38
39
40
41
42
# File 'lib/airplay/server.rb', line 37

def serve(file)
  sleep 0.1 until running?
  asset_id = App.settings[:assets][file]

  "http://#{private_ip}:#{@port}/assets/#{asset_id}"
end

#start!Object

Public: Starts the server in a new thread

Returns nothing



48
49
50
# File 'lib/airplay/server.rb', line 48

def start!
  Thread.start { @server.start }
end