App-EventStreamr

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

         "requires" : {
            "Test::Spelling" : "0.12"
         }
      },
      "runtime" : {
         "requires" : {
            "Carp" : "0",
            "Config::JSON" : "0",
            "Cwd" : "0",
            "Dancer" : "0",
            "Data::Dumper" : "0",
            "File::Basename" : "0",
            "File::Path" : "0",
            "File::ReadBackwards" : "0",
            "File::ShareDir::Tarball" : "0",
            "File::Slurp" : "0",
            "File::Spec" : "0",
            "File::Tail" : "0",
            "FindBin" : "0",
            "Getopt::Long" : "0",
            "HTTP::Tiny" : "0",

META.yml  view on Meta::CPAN

license: open_source
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: 1.4
name: App-EventStreamr
requires:
  Carp: 0
  Config::JSON: 0
  Cwd: 0
  Dancer: 0
  Data::Dumper: 0
  File::Basename: 0
  File::Path: 0
  File::ReadBackwards: 0
  File::ShareDir::Tarball: 0
  File::Slurp: 0
  File::Spec: 0
  File::Tail: 0
  FindBin: 0
  Getopt::Long: 0
  HTTP::Tiny: 0

Makefile.PL  view on Meta::CPAN

    "bin/eventstreamr"
  ],
  "LICENSE" => "open_source",
  "MIN_PERL_VERSION" => "5.010000",
  "NAME" => "App::EventStreamr",
  "PREREQ_PM" => {
    "Carp" => 0,
    "Config::JSON" => 0,
    "Cwd" => 0,
    "Dancer" => 0,
    "Data::Dumper" => 0,
    "File::Basename" => 0,
    "File::Path" => 0,
    "File::ReadBackwards" => 0,
    "File::ShareDir::Tarball" => 0,
    "File::Slurp" => 0,
    "File::Spec" => 0,
    "File::Tail" => 0,
    "FindBin" => 0,
    "Getopt::Long" => 0,
    "HTTP::Tiny" => 0,

Makefile.PL  view on Meta::CPAN

    "TESTS" => "t/*.t t/App/EventStreamr/*.t t/App/EventStreamr/DVswitch/*.t t/App/EventStreamr/DVswitch/Ingest/*.t t/App/EventStreamr/Internal/*.t t/App/EventStreamr/Roles/*.t"
  }
);


my %FallbackPrereqs = (
  "Carp" => 0,
  "Config::JSON" => 0,
  "Cwd" => 0,
  "Dancer" => 0,
  "Data::Dumper" => 0,
  "ExtUtils::MakeMaker" => 0,
  "File::Basename" => 0,
  "File::Path" => 0,
  "File::ReadBackwards" => 0,
  "File::ShareDir::Install" => "0.06",
  "File::ShareDir::Tarball" => 0,
  "File::Slurp" => 0,
  "File::Spec" => 0,
  "File::Tail" => 0,
  "File::Temp" => 0,

bin/station-mgr.pl  view on Meta::CPAN

use Proc::Daemon; # libproc-daemon-perl
use JSON; # libjson-perl
use Config::JSON; # libconfig-json-perl
use HTTP::Tiny; # libhttp-tiny-perl
use Log::Log4perl; # liblog-log4perl-perl
use POSIX;
use File::Path qw(make_path);
use File::Basename;
use experimental 'switch';
use Getopt::Long;
use Data::Dumper;

# PODNAME: station-mgr

# ABSTRACT: station-mgr - Core Station Manager script

our $VERSION = '0.5'; # VERSION


my $DEBUG  = 0;
my $DAEMON = 1;

bin/station-mgr.pl  view on Meta::CPAN

        'station-mgr' => 1,
        'Content-Type' => 'application/json', 
  );
  my %post_data = ( 
        content => $json, 
        headers => \%headers,
  );

  $response =  $http->post("$localconfig->{controller}/api/station", \%post_data);
  
  $logger->debug({filter => \&Data::Dumper::Dumper,
                  value  => $response}) if ($logger->is_debug());
}


if ($response->{status} == 200 ) {
  my $content = from_json($response->{content});
  $self->{controller}{running} = 1;
  $logger->debug({filter => \&Data::Dumper::Dumper,
                  value  => $content}) if ($logger->is_debug());

  if (defined $content && $content ne 'true') {
    $self->{config} = $content->{settings};
    write_config();
  } else {
    write_config();
  }

  # Run all connected devices - need to get devices to return an array

bin/station-mgr.pl  view on Meta::CPAN

    $self->{config}{devices} = $self->{devices}{array};
  }

  $self->{config}{manager}{pid} = $$;
  post_config();
} elsif ($response->{status} == 204){
  $self->{controller}{running} = 1;
  $self->{config}{manager}{pid} = $$;
  $logger->warn("Connected but not registered");
  $logger->info("Falling back to local config");
  $logger->debug({filter => \&Data::Dumper::Dumper,
                  value  => $response}) if ($logger->is_debug());

  # Run all connected devices - need to get devices to return an array
  if ($self->{config}{devices} eq 'all') {
    $self->{config}{devices} = $self->{devices}{array};
  }
  post_config();
} else {
  chomp $response->{content};
  $self->{controller}{running} = 0;
  $self->{config}{manager}{pid} = $$;
  $logger->warn("Failed to connect: $response->{content}");
  $logger->info("Falling back to local config");
  $logger->debug({filter => \&Data::Dumper::Dumper,
                  value  => $response}) if ($logger->is_debug());

  # Run all connected devices - need to get devices to return an array
  if ($self->{config}{devices} eq 'all') {
    $self->{config}{devices} = $self->{devices}{array};
  }
  post_config();
}

# Debug logging of data
$logger->debug({filter => \&Data::Dumper::Dumper,
                value  => $self}) if ($logger->is_debug());

# Log when started
if ($self->{config}{run}) {
  $logger->info("Manager started, starting devices");
} else {
  $logger->info("Manager started, configuration set to not start devices.");
}

# Post start clearing of data

bin/station-mgr.pl  view on Meta::CPAN

  # Post to manager api
  my $json = to_json($self);
  my %post_data = ( 
        content => $json, 
        'content-type' => 'application/json', 
        'content-length' => length($json),
  );

  my $post = $http->post("http://127.0.0.1:3000/internal/settings", \%post_data);
  $logger->info("Config Posted to API");
  $logger->debug({filter => \&Data::Dumper::Dumper,
                value  => $post}) if ($logger->is_debug());

  # Status information
  my $status;
  $status->{status} = $self->{status};
  $status->{macaddress} = $self->{config}{macaddress};
  $status->{nickname} = $self->{config}{nickname};
  # Uncomment for heartbeat
  #$status->{heartbeat} = $self->{heartbeat};

  # Post Headers
  my %headers = (
        'station-mgr' => 1,
        'Content-Type' => 'application/json',
  );

  $logger->debug({filter => \&Data::Dumper::Dumper,
                value  => $status}) if ($logger->is_debug());

  # Status Post Data
  $json = to_json($status);
  %post_data = ( 
        content => $json, 
        headers => \%headers, 
  );

  # Post Status to Mixer
  $post = $http->post("http://$self->{config}{mixer}{host}:3000/status/$self->{config}{macaddress}", \%post_data);
  $logger->info("Status Posted to Mixer API -> http://$self->{config}{mixer}{host}:3000/status/$self->{config}{macaddress}");
  $logger->debug({filter => \&Data::Dumper::Dumper,
                value  => $post}) if ($logger->is_debug());

  # Post Status + devices to Controller
  if ($self->{controller}{running}) {
    # Build post object
    my $data;
    $data->[0]{key} = "status";
    $data->[0]{value} = $status->{status};
    $data->[1]{key} = "devices";
    $data->[1]{value} = $self->{devices}{all};

bin/station-mgr.pl  view on Meta::CPAN

    # Post data
    $json = to_json($data);
    # some bug and it's late this could cause hideous issues if 
    # a device id has a / in it, but this should be unlikely
    $json =~ s{/|\.}{}g;

    %post_data = ( 
          content => $json, 
          headers => \%headers, 
    );
    $logger->debug({filter => \&Data::Dumper::Dumper,
                  value  => $json}) if ($logger->is_debug());
    $post = $http->post("$localconfig->{controller}/api/stations/$self->{config}{macaddress}/partial", \%post_data);
    $logger->info("Status Posted to Controller API - $localconfig->{controller}/api/stations/$self->{config}{macaddress}/partial");
    $logger->debug({filter => \&Data::Dumper::Dumper,
                  value  => $post}) if ($logger->is_debug());
  }
  
  return;
}

sub get_config {
  my $get = $http->get("http://127.0.0.1:3000/internal/settings");
  my $content = from_json($get->{content});
  $self->{config} = $content->{config};
  $logger->debug({filter => \&Data::Dumper::Dumper,
                value  => $get}) if ($logger->is_debug());
  $logger->debug({filter => \&Data::Dumper::Dumper,
                value  => $self}) if ($logger->is_debug());
  $logger->info("Config recieved from API");
  write_config();
  return;
}

sub write_config {
  $stationconfig->{config} = $self->{config};
  $stationconfig->write;
  $logger->info("Config written to disk");

bin/station-mgr.pl  view on Meta::CPAN

           exec_command => $self->{device_commands}{$device->{id}}{command},
        );
      }       
      # run process
      my $proc = $daemon->Init( \%proc_opts );

      # give the process some time to settle
      sleep 1;
      # Set the running state + pid
      $state = $utils->get_pid_command($device->{id},$self->{device_commands}{$device->{id}}{command},$device->{type}); 
      $logger->debug({filter => \&Data::Dumper::Dumper,
                      value  => $state}) if ($logger->is_debug());
      
      # Increase runcount
      $self->{device_control}{$device->{id}}{runcount}++;
      my $age = $time - $self->{device_control}{$device->{id}}{timestamp};
      if ($age > 1 && ! $state->{running}) {
        # Log!
        $logger->warn("$device->{id} failed to start (count=$self->{device_control}{$device->{id}}{runcount}, died=$age secs ago)");

        # Refresh devices

cpanfile  view on Meta::CPAN

requires "Carp" => "0";
requires "Config::JSON" => "0";
requires "Cwd" => "0";
requires "Dancer" => "0";
requires "Data::Dumper" => "0";
requires "File::Basename" => "0";
requires "File::Path" => "0";
requires "File::ReadBackwards" => "0";
requires "File::ShareDir::Tarball" => "0";
requires "File::Slurp" => "0";
requires "File::Spec" => "0";
requires "File::Tail" => "0";
requires "FindBin" => "0";
requires "Getopt::Long" => "0";
requires "HTTP::Tiny" => "0";

lib/App/EventStreamr/Devices.pm  view on Meta::CPAN

package App::EventStreamr::Devices;
use Moo; # libmoo-perl
use Cwd 'realpath';
use File::Slurp 'read_file'; #libfile-slurp-perl
use Hash::Merge::Simple; # libhash-merge-simple-perl
use Data::Dumper;

# ABSTRACT: Devices Methods

our $VERSION = '0.5'; # VERSION: Generated by DZP::OurPkg:Version


# TODO: Needs a cleanup!

sub all {
  my $self = shift;

lib/App/EventStreamr/Roles/ConfigAPI.pm  view on Meta::CPAN

            'Content-Type' => 'application/json',
          } 
    );
  
    $response = $self->http->post($self->controller."/api/station", \%post_data);
  }

  # We get a 200 if exist and are already registered. Previous 
  # if block takes care of requesting config after registering.
  if ($response->{status} == 200 ) {
    $self->debug({filter => \&Data::Dumper::Dumper,
                    value  => $response}) if ($self->is_debug());

    if (defined $response->{content} && $response->{content} ne 'true') {
      my $content = from_json($response->{content});
      return $content->{settings};
    }
    return 0;
  } else {
    return 0;
  }

lib/App/EventStreamr/Roles/ConfigAPI.pm  view on Meta::CPAN

        'station-mgr' => 1,
        'Content-Type' => 'application/json',
      }
    );

    $post = $self->http->post(
      $self->controller."/api/station/".$self->macaddress."/partial", 
      \%post_data,
    );
  
    $self->debug({filter => \&Data::Dumper::Dumper,
                    value  => $post}) if ($self->is_debug());
  }
}

method get_config() {
  $self->info("Retrieving config from manager API");
  my $get = $self->http->get($self->api_url);
  my $content = from_json($get->{content});
  
  $self->debug({filter => \&Data::Dumper::Dumper,
                  value  => $get}) if ($self->is_debug());


  # Eww code duplication of _load_config. Same appliest.
  foreach my $key (keys %{$content->{config}}) {
    $self->{$key} = $content->{config}{$key};
  }
  $self->write_config();
}

lib/App/EventStreamr/Status.pm  view on Meta::CPAN

      content => $json,
      'content-type' => 'application/json',
      'content-length' => length($json),
    );
    my $post = $self->config->http->post(
      "http://".$self->config->{mixer}{host}.":3000/status/".$self->config->macaddress,
      \%post_data,
    );

    $self->debug("Status posted to http://".$self->config->{mixer}{host}.":3000/status/".$self->config->macaddress);
    $self->debug({filter => \&Data::Dumper::Dumper,
                  value  => $post}) if ($self->is_debug());

    if ( $self->config->controller ) {
      # The Frontend doesn't like empty objects..
      # TODO: Fix the frontend
      foreach my $key (keys %{$self->{status}}) {
        if (! defined $self->{status}{$key}{id}) {
          delete $self->{status}{$key};
        }
      }

lib/App/EventStreamr/Status.pm  view on Meta::CPAN

          'station-mgr' => 1,
          'Content-Type' => 'application/json',
        }
      );

      $post = $self->config->http->post(
        $self->config->controller."/api/station/".$self->config->macaddress."/partial", 
        \%post_data,
      );

      $self->debug({filter => \&Data::Dumper::Dumper,
                    value  => $post}) if ($self->is_debug());

      $self->info("Status posted to ".$self->config->controller."/api/station/".$self->config->macaddress."/partial");
    }
  }
}

with('App::EventStreamr::Roles::Logger');

1;

lib/App/EventStreamr/Utils.pm  view on Meta::CPAN

package App::EventStreamr::Utils;
use Moo;
use IO::Socket::INET; # System Class
use Proc::ProcessTable; # libproc-processtable-perl
use experimental 'switch';
use Data::Dumper;

# ABSTRACT: Utils

our $VERSION = '0.5'; # VERSION: Generated by DZP::OurPkg:Version


sub test {
  my $self = shift;
  $self->{portstate} = port("localhost","1234");
  $self->{get_pid_command} = get_pid_command("video0","ffmpeg -f video4linux2 -s vga -r 25 -i /dev/video0 -target pal-dv - | dvsource-file /dev/stdin -h localhost -p 1234","v4l");



( run in 0.279 second using v1.01-cache-2.11-cpan-4d50c553e7e )