Skip to content

Instantly share code, notes, and snippets.

@vti

vti/Shell.pm Secret

Created July 24, 2010 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vti/2bf62237efb34b84e8d2 to your computer and use it in GitHub Desktop.
Save vti/2bf62237efb34b84e8d2 to your computer and use it in GitHub Desktop.
sub view {
my $self = shift;
my $id = $self->stash('id');
unless ($self->tx->is_websocket) {
my $url = $self->req->url->base->clone;
$url->scheme($self->req->is_secure ? 'wss' : 'ws');
$url->query->params([]);
$url->path($self->req->url->path);
$self->stash(websocket_url => $url->to_abs);
return;
}
#my $client = $self->client;
$self->client->async->websocket(
"ws://localhost:1234/$id" => sub {
my $client = shift;
if ($client->tx->has_error) {
$self->app->log->error("Can't connect to backend");
$client->finish;
$self->finish;
return;
}
$client->receive_message(
sub {
my ($client, $message) = @_;
warn "message=$message";
$self->send_message($message);
}
);
$client->finished(
sub {
my $client = shift;
warn qq/Backend connection is closed/;
}
);
}
)->process;
$self->receive_message(
sub {
my ($self, $message) = @_;
warn qq/Message from browser=$message/;
#$client->send_message($message);
}
);
$self->finished(
sub {
my $self = shift;
#$client->finish;
warn 'User closed websocket connection';
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment