aboutsummaryrefslogtreecommitdiff
path: root/lib/App/MediaControl.rakumod
blob: f60f3c71b48f8656d868aa8cf727a1697f670174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use v6.d;
use Cro::HTTP::Server;
use Cro::HTTP::Router;
use Vlc::Client;
use Lirc::Client;
 
class App::MediaControl {
    has Vlc::Client $.vlc is required;
    has Lirc::Client $.lirc is required;
    has Int $.port = 8080;
    has Cro::Service $!service handles <stop>;
 
    method start() {
        my $application = route {
            resources-from %?RESOURCES;
 
            get -> { resource 'index.html' }
 
            post -> 'play' { await self.vlc.command('pl_play'}
            post -> 'pause' { await self.vlc.command('pl_pause'}
            post -> 'stop' { await self.vlc.command('pl_stop'}
 
            get -> 'status' {
                my $status = await self.vlc.status();
                content 'application/json'$status;
            }
        };
 
        $!service = Cro::HTTP::Server.new(
            :port(self.port), :$application,
        );
 
        return $!service.start();
    }
}