forked from vti/crafty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vti
committed
May 1, 2017
1 parent
4e4d445
commit 6fefa92
Showing
25 changed files
with
769 additions
and
686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ perl5/ | |
db.db | ||
data/builds/ | ||
data/config.yml | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
-l=120 | ||
-pt=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package Crafty::Action::Event; | ||
use Moo; | ||
extends 'Crafty::Action::Base'; | ||
|
||
use Crafty::PubSub; | ||
|
||
sub run { | ||
my $self = shift; | ||
|
||
my $body = $self->req->content; | ||
|
||
$body = JSON::decode_json($body); | ||
|
||
Crafty::PubSub->instance->publish(@$body); | ||
|
||
return [ 200, [], ['ok'] ]; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package Crafty::Action::Events; | ||
use Moo; | ||
extends 'Crafty::Action::Base'; | ||
|
||
use Promises qw(deferred); | ||
use JSON (); | ||
use Plack::App::EventSource; | ||
use Crafty::PubSub; | ||
use Crafty::Log; | ||
|
||
sub run { | ||
my $self = shift; | ||
my (%params) = @_; | ||
|
||
return sub { | ||
my $respond = shift; | ||
|
||
my $cb = Plack::App::EventSource->new( | ||
headers => [ 'Access-Control-Allow-Credentials', 'true' ], | ||
handler_cb => sub { | ||
my ($conn, $env) = @_; | ||
|
||
Crafty::PubSub->instance->subscribe( | ||
'*' => sub { | ||
my ($ev, $data) = @_; | ||
|
||
eval { | ||
$conn->push(JSON::encode_json({ type => $ev, data => $data })); | ||
1; | ||
} or do { | ||
$conn->close; | ||
}; | ||
|
||
return deferred->resolve; | ||
} | ||
); | ||
} | ||
)->call($self->env); | ||
|
||
$cb->($respond); | ||
}; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,4 @@ sub tail { | |
}; | ||
} | ||
|
||
sub DESTROY { "ACTION TAIL DESTROY" } | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.