aboutsummaryrefslogtreecommitdiff
path: root/lib/Vlc/App.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Vlc/App.rakumod')
-rw-r--r--lib/Vlc/App.rakumod33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Vlc/App.rakumod b/lib/Vlc/App.rakumod
new file mode 100644
index 0000000..e4401e6
--- /dev/null
+++ b/lib/Vlc/App.rakumod
@@ -0,0 +1,33 @@
+use v6.d;
+use Cro::HTTP::Server;
+use Cro::HTTP::Router;
+use Vlc::Client;
+
+class Vlc::App {
+ has Vlc::Client $.vlc is required;
+ has Int $.port = 8080;
+ has Cro::Service $!service handles <stop>;
+
+ method start() {
+ my $application = route {
+ resources-from %?RESOURCES;
+
+ get -> { resource 'vlc.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();
+ }
+}