source: main/trunk/greenstone2/perllib/cpan/Mojo/IOLoop/Stream/WebSocketClient.pm@ 32205

Last change on this file since 32205 was 32205, checked in by ak19, 6 years ago

First set of commits to do with implementing the new 'paged_html' output option of PDFPlugin that uses using xpdftools' new pdftohtml. So far tested only on Linux (64 bit), but things work there so I'm optimistically committing the changes since they work. 2. Committing the pre-built Linux binaries of XPDFtools for both 32 and 64 bit built by the XPDF group. 2. To use the correct bitness variant of xpdftools, setup.bash now exports the BITNESS env var, consulted by gsConvert.pl. 3. All the perl code changes to do with using xpdf tools' pdftohtml to generate paged_html and feed it in the desired form into GS(3): gsConvert.pl, PDFPlugin.pm and its parent ConvertBinaryPFile.pm have been modified to make it all work. xpdftools' pdftohtml generates a folder containing an html file and a screenshot for each page in a PDF (as well as an index.html linking to each page's html). However, we want a single html file that contains each individual 'page' html's content in a div, and need to do some further HTML style, attribute and structure modifications to massage the xpdftool output to what we want for GS. In order to parse and manipulate the HTML 'DOM' to do this, we're using the Mojo::DOM package that Dr Bainbridge found and which he's compiled up. Mojo::DOM is therefore also committed in this revision. Some further changes and some display fixes are required, but need to check with the others about that.

File size: 1.8 KB
Line 
1package Mojo::IOLoop::Stream::WebSocketClient;
2use Mojo::Base 'Mojo::IOLoop::Stream::HTTPClient';
3
4use Scalar::Util 'weaken';
5
6sub process {
7 my ($self, $tx) = @_;
8 $self->{tx} = $tx;
9 weaken $self;
10 $tx->on(resume => sub { $self->_write_content });
11 $self->_write_content;
12}
13
14sub _finish {
15 my $self = shift;
16 return ++$self->{closing} && $self->close unless $self->{tx};
17 delete($self->{tx})->closed;
18 ++$self->{closing} && $self->close_gracefully;
19}
20
211;
22
23=encoding utf8
24
25=head1 NAME
26
27Mojo::IOLoop::Stream::WebSocketClient - Non-blocking I/O WebSocket client stream
28
29=head1 SYNOPSIS
30
31 use Mojo::IOLoop::Stream::WebSocketClient;
32 use Mojo::Transaction::WebSocket;
33
34 # Create transaction
35 my $ws = Mojo::Transaction::WebSocket->new;
36 $ws->on(message => sub {
37 my ($ws, $msg) = @_;
38 say "Message: $msg";
39 });
40
41 # Create stream and process transaction with it
42 my $stream = Mojo::IOLoop::Stream::WebSocketClient->new($handle);
43 $stream->process($ws);
44
45 # Start reactor if necessary
46 $stream->reactor->start unless $stream->reactor->is_running;
47
48=head1 DESCRIPTION
49
50L<Mojo::IOLoop::Stream::WebSocketClient> is a container for I/O streams used by
51L<Mojo::IOLoop> to support the WebSocket protocol client-side.
52
53=head1 EVENTS
54
55L<Mojo::IOLoop::Stream::WebSocketClient> inherits all events from
56L<Mojo::IOLoop::Stream::HTTPClient>.
57
58=head1 ATTRIBUTES
59
60L<Mojo::IOLoop::Stream::WebSocketClient> inherits all attributes from
61L<Mojo::IOLoop::Stream::HTTPClient>.
62
63=head1 METHODS
64
65L<Mojo::IOLoop::Stream::WebSocketClient> inherits all methods from
66L<Mojo::IOLoop::Stream::HTTPClient> and implements the following new ones.
67
68=head2 process
69
70 $stream->process(Mojo::Transaction::WebSocket->new);
71
72Process a L<Mojo::Transaction::WebSocket> object.
73
74=head1 SEE ALSO
75
76L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>.
77
78=cut
79
Note: See TracBrowser for help on using the repository browser.