给定下面的代码,我如何从 Fu::Bar::dosomething 中通过为“/wsinit”打开的 websocket 向客户端发送消息?
package Fu;
use Mojo::Base 'Mojolicious';
sub startup
{
my $r = shift->routes;
$r->get('/')->to(controller => 'bar', action => 'init');
$r->websocket('/wsinit')->to(controller => 'bar', action => 'wsinit');
$r->get('/dosomething')->to(controller => 'bar', action => 'dosomething');
}
1;
# -- ^L
# --
package Fu::Bar;
use Mojo::Base 'Mojolicious::Controller';
sub init
{
my $self = shift;
$self->render(text => 'init');
}
sub wsinit
{
my $self = shift;
$self->app->log->debug( 'Websocket opened.' );
$self->send({json => {fu => 'bar'}});
}
sub dosomething
{
my $self = shift;
}
1;
请忽略以下多余的措辞,其目的是满足 stackoverflow 的详细信息/代码要求,这些要求目前阻止我发布我的问题。