Device-WebIO-Dancer
    
    
  
  
  
view release on metacpan or search on metacpan
lib/Device/WebIO/Dancer.pm view on Meta::CPAN
get '/devices/:name/video/:channel/stream/:type1/:type2' => sub {
    my $name    = params->{name};
    my $channel = params->{channel};
    my $type1   = params->{type1};
    my $type2   = params->{type2};
    my $mime_type = $type1 . '/' . $type2;
    my $in_fh = $webio->vid_stream( $name, $channel, $mime_type );
    return send_file( '/etc/hosts',
        streaming    => 1,
        system_path  => 1,
        content_type => $mime_type,
        callbacks    => {
            around_content => sub {
                my ($writer, $chunk) = @_;
                my $buf;
                while( read( $in_fh, $buf, VID_READ_LENGTH ) ) {
                    $writer->write( $buf );
                }
t/020_video.t view on Meta::CPAN
$res = $test->request( GET '/devices/foo/video/0/kbps' );
cmp_ok( $res->code, '==', 200, "Got new video bitrate response" );
cmp_ok( $res->content, 'eq', '1000' );
$res = $test->request( GET '/devices/foo/video/0/allowed-content-types' );
cmp_ok( $res->code, '==', 200, "Got video allowed content type response" );
cmp_ok( $res->content, 'eq', 'video/h264' );
SKIP: {
    skip q{Plack::Test doesn't seem to handle streaming correctly}, 2;
    $res = $test->request( GET '/devices/foo/video/0/stream/video/h264' );
    cmp_ok( $res->code, '==', 200, "Got video stream" );
    cmp_ok( length($res->content), '==', -s $STREAM_FILE );
}
# TODO error for trying to read a stream with an unsupported content type
( run in 0.264 second using v1.01-cache-2.11-cpan-5dc5da66d9d )